PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

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