/src/main/java/nl/bitbrains/nebu/common/topology/PhysicalRoot.java

https://github.com/deltaforge/nebu-common-java · Java · 87 lines · 46 code · 10 blank · 31 comment · 6 complexity · 58a92b470d487aed6e95855b7134a928 MD5 · raw file

  1. package nl.bitbrains.nebu.common.topology;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. /**
  7. * This class represents the root of a physical server topology. It can contain
  8. * any number PhysicalDataCenters. The root has a unique identifier and is thus
  9. * Identifiable.
  10. *
  11. * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
  12. */
  13. public class PhysicalRoot extends PhysicalResource {
  14. private final Map<String, PhysicalDataCenter> dataCenters;
  15. /**
  16. * Copy constructor.
  17. *
  18. * @param other
  19. * root to adopt.
  20. */
  21. public PhysicalRoot(final PhysicalRoot other) {
  22. super(other.getUniqueIdentifier());
  23. this.dataCenters = new HashMap<String, PhysicalDataCenter>();
  24. for (final PhysicalDataCenter datacenter : other.getDataCenters()) {
  25. final PhysicalDataCenter d = new PhysicalDataCenter(datacenter);
  26. d.setParent(this);
  27. this.addDataCenter(d);
  28. }
  29. }
  30. /**
  31. *
  32. * @param uniqueIdentifier
  33. * the unique identifier for the new PhysicalRoot.
  34. * @param dcs
  35. * the datacenters under this root.
  36. */
  37. protected PhysicalRoot(final String uniqueIdentifier, final Map<String, PhysicalDataCenter> dcs) {
  38. super(uniqueIdentifier);
  39. this.dataCenters = dcs;
  40. }
  41. /**
  42. * @return the data centers part of this PhyscicalRoot.
  43. */
  44. public List<PhysicalDataCenter> getDataCenters() {
  45. return new ArrayList<PhysicalDataCenter>(this.dataCenters.values());
  46. }
  47. /**
  48. * @param dataCenter
  49. * the data center to add to the PhysicalRoot.
  50. */
  51. protected final void addDataCenter(final PhysicalDataCenter dataCenter) {
  52. if (dataCenter != null) {
  53. this.dataCenters.put(dataCenter.getUniqueIdentifier(), dataCenter);
  54. }
  55. }
  56. /**
  57. * @param dataCenter
  58. * the data center to remove from the PhysicalRoot.
  59. */
  60. protected void removeDataCenter(final PhysicalDataCenter dataCenter) {
  61. if (dataCenter != null) {
  62. this.dataCenters.remove(dataCenter.getUniqueIdentifier());
  63. }
  64. }
  65. @Override
  66. public int hashCode() {
  67. return this.getUniqueIdentifier().hashCode();
  68. }
  69. @Override
  70. public boolean equals(final Object obj) {
  71. if (obj instanceof PhysicalRoot) {
  72. final PhysicalRoot that = (PhysicalRoot) obj;
  73. return this.getUniqueIdentifier().equals(that.getUniqueIdentifier());
  74. }
  75. return false;
  76. }
  77. }