PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/deltaforge/nebu-common-java
Java | 70 lines | 34 code | 9 blank | 27 comment | 5 complexity | f103947bd7ac7d4d9b8a0a4a257da490 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 * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
10 * 
11 */
12public abstract class PhysicalResourceWithDisks extends PhysicalResource {
13
14    private final Map<String, PhysicalStore> disks;
15
16    /**
17     * @param id
18     *            to use.
19     * @param disks
20     *            to set as disks.
21     */
22    public PhysicalResourceWithDisks(final String id, final Map<String, PhysicalStore> disks) {
23        super(id);
24        this.disks = disks;
25    }
26
27    /**
28     * @param id
29     *            to set.
30     * @param disks
31     *            to add.
32     */
33    public PhysicalResourceWithDisks(final String id, final List<PhysicalStore> disks) {
34        super(id);
35        this.disks = new HashMap<String, PhysicalStore>();
36        for (final PhysicalStore disk : disks) {
37            final PhysicalStore newDisk = new PhysicalStore(disk);
38            newDisk.setParent(this);
39            this.addDisk(newDisk);
40        }
41    }
42
43    /**
44     * @return Disks contained in the PhysicalRack.
45     */
46    public final List<PhysicalStore> getDisks() {
47        return new ArrayList<PhysicalStore>(this.disks.values());
48    }
49
50    /**
51     * @param disk
52     *            the Disk to add to the PhysicalRack.
53     */
54    protected final void addDisk(final PhysicalStore disk) {
55        if (disk != null) {
56            this.disks.put(disk.getUniqueIdentifier(), disk);
57        }
58    }
59
60    /**
61     * @param disk
62     *            the disk to remove from the PhysicalRack.
63     */
64    protected final void removeDisk(final PhysicalStore disk) {
65        if (disk != null) {
66            this.disks.remove(disk.getUniqueIdentifier());
67        }
68    }
69
70}