SmartDevice.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core;
  2. import java.util.LinkedList;
  3. import java.util.List;
  4. /**
  5. * Model of an SmartDevice, which keeps track of its main attributes, like name,
  6. * position, links and connections
  7. *
  8. * @author Andreas T. Meyer-Berg
  9. */
  10. public class SmartDevice {
  11. /**
  12. * Label
  13. */
  14. protected short label = 0;
  15. /**
  16. * Name of the Device
  17. */
  18. private String name;
  19. /**
  20. * Physical connections to other SmartDevices
  21. */
  22. private List<Link> links;
  23. /**
  24. * Ports of this device
  25. */
  26. private List<Port> ports;
  27. /**
  28. * Creates a new SmartDevice without links
  29. *
  30. * @param name
  31. * name of the device
  32. */
  33. public SmartDevice(String name) {
  34. this.name = name;
  35. links = new LinkedList<Link>();
  36. ports = new LinkedList<Port>();
  37. }
  38. /**
  39. * Creates a new SmartDevice without links
  40. */
  41. public SmartDevice() {
  42. this.name = "Unnamed";
  43. links = new LinkedList<Link>();
  44. ports = new LinkedList<Port>();
  45. }
  46. /**
  47. * Position on the x-Axis
  48. */
  49. private int x;
  50. /**
  51. * Position on the y-Axis
  52. */
  53. private int y;
  54. /**
  55. * Position on the z-Axis
  56. */
  57. private int z;
  58. /**
  59. * Returns the {@link SmartDevice#name}
  60. *
  61. * @return {@link SmartDevice#name}
  62. */
  63. public String getName() {
  64. return name;
  65. }
  66. /**
  67. * Sets the {@link SmartDevice#name}
  68. *
  69. * @param name
  70. * the {@link SmartDevice#name} to set
  71. */
  72. public void setName(String name) {
  73. this.name = name;
  74. }
  75. /**
  76. * Returns links of this device
  77. *
  78. * @return the links of this device
  79. */
  80. public List<Link> getLinks() {
  81. return links;
  82. }
  83. /**
  84. * Adds a new link to this device
  85. *
  86. * @param link
  87. * the link to add
  88. */
  89. public void addLink(Link link) {
  90. if(!links.contains(link) && link != null)
  91. links.add(link);
  92. }
  93. /**
  94. * Removes the link from this SmartDevice
  95. *
  96. * @param link
  97. * Link which should be removed
  98. */
  99. public void removeLink(Link link) {
  100. if (link == null)
  101. return;
  102. links.remove(link);
  103. }
  104. /**
  105. * Returns the x-position
  106. *
  107. * @return the x-position
  108. */
  109. public int getX() {
  110. return x;
  111. }
  112. /**
  113. * Sets the x-position
  114. *
  115. * @param x
  116. * the x-position to set
  117. */
  118. public void setX(int x) {
  119. this.x = x;
  120. }
  121. /**
  122. * Returns the y-position
  123. *
  124. * @return the y-position
  125. */
  126. public int getY() {
  127. return y;
  128. }
  129. /**
  130. * Sets the y-position
  131. *
  132. * @param y
  133. * the y-position to set
  134. */
  135. public void setY(int y) {
  136. this.y = y;
  137. }
  138. /**
  139. * Returns the z-position
  140. *
  141. * @return the z-position
  142. */
  143. public int getZ() {
  144. return z;
  145. }
  146. /**
  147. * Sets the z-position
  148. *
  149. * @param z
  150. * the z-position to set
  151. */
  152. public void setZ(int z) {
  153. this.z = z;
  154. }
  155. /**
  156. * Simulates the next Timestep
  157. *
  158. * @param startTime
  159. * Time the simulation interval starts in
  160. * System.currentTimeMillis() time
  161. * @param duration
  162. * Duration of the simulation interval in milliseconds
  163. */
  164. public void simulateTimeStep(long startTime, long duration) {
  165. }
  166. /**
  167. * @return the ports
  168. */
  169. public List<Port> getPorts() {
  170. return ports;
  171. }
  172. /**
  173. * @param port the port to add
  174. */
  175. public void addPort(Port port) {
  176. if(!ports.contains(port)&&port!=null)
  177. this.ports.add(port);
  178. }
  179. /**
  180. * @param port the ports to remove
  181. */
  182. public void removePort(Port port) {
  183. this.ports.remove(port);
  184. }
  185. /**
  186. * @return label
  187. */
  188. public short getLabel() {
  189. return label;
  190. }
  191. /**
  192. * Sets the label
  193. * @param label label to set
  194. */
  195. public void setLabel(Short label) {
  196. this.label = label;
  197. }
  198. }