CpsObject.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. }
  30. public CpsObject(CpsObject obj) {
  31. this.objName = obj.getObjName();
  32. connectedTo = new ArrayList<CpsObject>();
  33. position = new Position();
  34. id = IdCounter.nextId();
  35. }
  36. /* Obj type */
  37. public String getObjName() {
  38. return objName;
  39. }
  40. public void setObjName(String objName) {
  41. this.objName = objName;
  42. }
  43. /* User defined Name */
  44. public String getName() {
  45. return name;
  46. }
  47. public void setName(String name) {
  48. this.name = name;
  49. }
  50. /* Unique ID number */
  51. public int getID() {
  52. return id;
  53. }
  54. /* Image path */
  55. public String getImage() {
  56. return image;
  57. }
  58. public void setImage(String image) {
  59. this.image = image;
  60. }
  61. /* Neighbors array */
  62. public ArrayList<CpsObject> getConnectedTo() {
  63. return connectedTo;
  64. }
  65. public void AddConnection(CpsObject toConnect) {
  66. connectedTo.add(toConnect);
  67. }
  68. /* Position (x and Y) */
  69. public void setPos(int x, int y){
  70. position.x = x;
  71. position.y = y;
  72. }
  73. public Position getPos(){
  74. return position;
  75. }
  76. /*Getter and Setters for the energy input and output*/
  77. public float getEnergyIn() {
  78. return energyIn;
  79. }
  80. public void setEnergyIn(float energyIn) {
  81. this.energyIn = energyIn;
  82. }
  83. public float getEnergyOut() {
  84. return energyOut;
  85. }
  86. public void setEnergyOut(float energyOut) {
  87. this.energyOut = energyOut;
  88. }
  89. @Override
  90. public String getCompareName() {
  91. return objName;
  92. }
  93. }