CpsObject.java 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package classes;
  2. import java.util.ArrayList;
  3. import Interfaces.ComparableObject;
  4. import ui.model.IdCounter;
  5. public 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<CpsObject> connectedTo;
  16. /* Position with a X and Y value */
  17. Position position;
  18. /*Energy input and output of each object in the grid*/
  19. float energyIn;
  20. float energyOut;
  21. /**
  22. * Constructor for an CpsObejct with an unique ID
  23. */
  24. public CpsObject(String objName) {
  25. this.objName = objName;
  26. connectedTo = new ArrayList<CpsObject>();
  27. position = new Position();
  28. id = IdCounter.nextId();
  29. image = "/Images/Dummy_House.png";
  30. }
  31. public CpsObject(CpsObject obj) {
  32. this.objName = obj.getObjName();
  33. connectedTo = new ArrayList<CpsObject>();
  34. position = new Position();
  35. id = IdCounter.nextId();
  36. this.name = obj.getName();
  37. this.energyIn = obj.getEnergyIn();
  38. this.energyOut = obj.getEnergyOut();
  39. this.image = obj.getImage();
  40. }
  41. /* Obj type */
  42. public String getObjName() {
  43. return objName;
  44. }
  45. public void setObjName(String objName) {
  46. this.objName = objName;
  47. }
  48. /* User defined Name */
  49. public String getName() {
  50. return name;
  51. }
  52. public void setName(String name) {
  53. this.name = name;
  54. }
  55. /* Unique ID number */
  56. public int getID() {
  57. return id;
  58. }
  59. /* Image path */
  60. public String getImage() {
  61. return image;
  62. }
  63. public void setImage(String image) {
  64. this.image = image;
  65. }
  66. /* Neighbors array */
  67. public ArrayList<CpsObject> getConnectedTo() {
  68. return connectedTo;
  69. }
  70. public void AddConnection(CpsObject toConnect) {
  71. connectedTo.add(toConnect);
  72. }
  73. /* Position (x and Y) */
  74. public void setPos(int x, int y){
  75. position.x = x;
  76. position.y = y;
  77. }
  78. public Position getPos(){
  79. return position;
  80. }
  81. /*Getter and Setters for the energy input and output*/
  82. public float getEnergyIn() {
  83. return energyIn;
  84. }
  85. public void setEnergyIn(float energyIn) {
  86. this.energyIn = energyIn;
  87. }
  88. public float getEnergyOut() {
  89. return energyOut;
  90. }
  91. public void setEnergyOut(float energyOut) {
  92. this.energyOut = energyOut;
  93. }
  94. @Override
  95. public String getCompareName() {
  96. return objName;
  97. }
  98. }