CpsObject.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package classes;
  2. import java.util.ArrayList;
  3. import Interfaces.ComparableObject;
  4. import ui.model.idCounter;
  5. public abstract class CpsObject implements ComparableObject {
  6. /* Type of the Object */
  7. String objName;
  8. /* Name given by the user */
  9. String name;
  10. /* ID of the Obj. */
  11. int ID;
  12. /* Path of the image for the Obj. */
  13. String image;
  14. /* Array of neighbors */
  15. ArrayList<CpsEdge> connections;
  16. /* Position with a X and Y value */
  17. Position position;
  18. /* Energy input and output of each object in the grid */
  19. String stored;
  20. float energyIn;
  21. float energyOut;
  22. /**
  23. * Constructor for an CpsObejct with an unique ID
  24. */
  25. public CpsObject(String objName) {
  26. setObjName(objName);
  27. setName(objName);
  28. setImage("/Images/Dummy_House.png");
  29. }
  30. public CpsObject(CpsObject obj) {
  31. setObjName(obj.getObjName());
  32. setName(obj.getObjName());
  33. setConnections(new ArrayList<CpsEdge>());
  34. setPosition(new Position());
  35. setID(idCounter.nextId());
  36. setEnergyIn(obj.getEnergyIn());
  37. setEnergyOut(obj.getEnergyOut());
  38. setImage(obj.getImage());
  39. }
  40. /* Obj type */
  41. public String getObjName() {
  42. return objName;
  43. }
  44. public void setObjName(String objName) {
  45. this.objName = objName;
  46. }
  47. /* User defined Name */
  48. public String getName() {
  49. return name;
  50. }
  51. public void setName(String name) {
  52. this.name = name;
  53. }
  54. /* Unique ID number */
  55. public int getID() {
  56. return ID;
  57. }
  58. /**
  59. * @param iD
  60. * the iD to set
  61. */
  62. public void setID(int ID) {
  63. this.ID = ID;
  64. }
  65. /* Image path */
  66. public String getImage() {
  67. return image;
  68. }
  69. public void setImage(String image) {
  70. this.image = image;
  71. }
  72. /**
  73. * @return the connections
  74. */
  75. public ArrayList<CpsEdge> getConnections() {
  76. return connections;
  77. }
  78. /**
  79. * @param arrayList
  80. * the connections to set
  81. */
  82. public void setConnections(ArrayList<CpsEdge> arrayList) {
  83. this.connections = arrayList;
  84. }
  85. /* Neighbors array */
  86. public ArrayList<CpsEdge> getConnectedTo() {
  87. return connections;
  88. }
  89. public void AddConnection(CpsEdge toConnect) {
  90. connections.add(toConnect);
  91. }
  92. public void setPosition(Position pos) {
  93. this.position = pos;
  94. }
  95. /* Position (x and Y) */
  96. public void setPosition(int x, int y) {
  97. setPosition(new Position(x, y));
  98. }
  99. public Position getPosition() {
  100. return position;
  101. }
  102. /**
  103. * @return the stored
  104. */
  105. public String getStored() {
  106. return stored;
  107. }
  108. /**
  109. * @param stored the stored to set
  110. */
  111. public void setStored(String stored) {
  112. this.stored = stored;
  113. }
  114. /* Getter and Setters for the energy input and output */
  115. public float getEnergyIn() {
  116. return energyIn;
  117. }
  118. public void setEnergyIn(float energyIn) {
  119. this.energyIn = energyIn;
  120. }
  121. public float getEnergyOut() {
  122. return energyOut;
  123. }
  124. public void setEnergyOut(float energyOut) {
  125. this.energyOut = energyOut;
  126. }
  127. @Override
  128. public String getCompareName() {
  129. return objName;
  130. }
  131. }