NetworkTreeSettings.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package de.tu_darmstadt.tk.SmartHomeNetworkSim.core.configuration;
  2. import java.util.HashMap;
  3. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Connection;
  4. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Link;
  5. import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.SmartDevice;
  6. /**
  7. * Settings of the Network Tree and contains the settings for each node
  8. *
  9. * @author Andreas T. Meyer-Berg
  10. */
  11. public class NetworkTreeSettings {
  12. /**
  13. * HashMap to access nodes
  14. */
  15. private HashMap<Object, NetworkTreeNodeStatus> map;
  16. /**
  17. * Initialize the NetworkTreeSettings
  18. */
  19. public NetworkTreeSettings() {
  20. map = new HashMap<Object, NetworkTreeNodeStatus>();
  21. }
  22. /**
  23. * Returns the Status for the given Object
  24. * @param o Object, whose status should be returned
  25. * @return Status of the object
  26. */
  27. public NetworkTreeNodeStatus getStatusOfObject(Object o){
  28. NetworkTreeNodeStatus ret = map.get(o);
  29. if(o instanceof Link || o instanceof Connection || o instanceof SmartDevice || o instanceof String){
  30. if(ret == null){
  31. /**
  32. * if no status stored -> create and return new one
  33. */
  34. ret = new NetworkTreeNodeStatus(o);
  35. map.put(o, ret);
  36. }
  37. return ret;
  38. }
  39. /**
  40. * Error for simple debug - should be
  41. */
  42. throw new Error("Invalid Object in Tree: "+o);
  43. }
  44. /**
  45. * Adds an status for the given Object
  46. * @param o Object to be added
  47. * @param status Status of the object
  48. */
  49. public void addStatusOfObject(Object o, NetworkTreeNodeStatus status){
  50. map.put(o, status);
  51. }
  52. /**
  53. * Removes the status of the object o
  54. * @param o Object, which status should be removed
  55. */
  56. public void removeStatusOfObject(Object o){
  57. map.remove(o);
  58. }
  59. }