Java Inventar


SUBMITTED BY: Guest

DATE: Nov. 19, 2013, 5:30 p.m.

FORMAT: Text only

SIZE: 1.6 kB

HITS: 1024

  1. public class Inventar {
  2. public String[] places;
  3. public int big;
  4. public String[] src;
  5. public Inventar()
  6. {
  7. }
  8. public void setPlaces(int i)
  9. {
  10. places = new String[i+1];
  11. src= new String[i+1];
  12. big=i;
  13. }
  14. public int newItem(String name)
  15. {
  16. for(int s=0 ; s<=big;s++)
  17. {
  18. if (places[s]==null)
  19. {
  20. places[s]=name;
  21. return (s);
  22. }
  23. }
  24. return (-1);
  25. }
  26. public void addSrc(int id,String path)
  27. {
  28. src[id]=path;
  29. }
  30. public void removeItem(int id)
  31. {
  32. places[id]=null;
  33. src[id]=null;
  34. }
  35. public String getItemId(int id)
  36. {
  37. return (places[id]);
  38. }
  39. public String getItemSrc(int id)
  40. {
  41. return (src[id]);
  42. }
  43. public int searchItemId(String name)
  44. {
  45. for(int s=0 ; s<=big;s++)
  46. {
  47. if (places[s].equals(name))
  48. {
  49. return (s);
  50. }
  51. }
  52. return -1;
  53. }
  54. public int searchItemSrc(String path)
  55. {
  56. for(int s=0 ; s<=big;s++)
  57. {
  58. if (src[s].equals(path))
  59. {
  60. return (s);
  61. }
  62. }
  63. return -1;
  64. }
  65. public String printItems()
  66. {
  67. String ret=places[0];
  68. for(int s=0 ; s<=big;s++)
  69. {
  70. ret = ret + ","+places[s];
  71. }
  72. return ret;
  73. }
  74. public void ItemMove(int id,int id2)
  75. {
  76. String name=places[id];
  77. String name2=places[id2];
  78. String path=src[id];
  79. String path2=src[id2];
  80. if (name2==null)
  81. {
  82. places[id2]=name;
  83. src[id2]=path;
  84. removeItem(id);
  85. }
  86. else
  87. {
  88. places[id2]=name;
  89. src[id2]=path;
  90. removeItem(id);
  91. newItem(name2);
  92. addSrc(id2,path2);
  93. }
  94. }
  95. }

comments powered by Disqus