PageRenderTime 23ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

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

https://github.com/deltaforge/nebu-common-java
Java | 71 lines | 36 code | 8 blank | 27 comment | 0 complexity | f03432316f4400ea28a878c5b2c91f1c MD5 | raw file
 1package nl.bitbrains.nebu.common.topology;
 2
 3import nl.bitbrains.nebu.common.util.ErrorChecker;
 4
 5/**
 6 * Builder class for the {@link PhysicalStore}.
 7 * 
 8 * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
 9 * 
10 */
11public class PhysicalStoreBuilder extends PhysicalResourceBuilder<PhysicalStore> {
12    private PhysicalResource parent;
13    private long capacity;
14    private long used;
15
16    /**
17     * Simple constructor.
18     */
19    public PhysicalStoreBuilder() {
20        this.reset();
21    }
22
23    @Override
24    public final void reset() {
25        super.reset();
26        this.parent = null;
27        this.capacity = 0;
28        this.used = 0;
29    }
30
31    /**
32     * @param parent
33     *            to build with
34     * @return this for fluency.
35     */
36    public PhysicalStoreBuilder withParent(final PhysicalRack parent) {
37        this.parent = parent;
38        return this;
39    }
40
41    /**
42     * @param capacity
43     *            to set.
44     * @return this for fluency.
45     */
46    public PhysicalStoreBuilder withCapacity(final long capacity) {
47        this.capacity = capacity;
48        return this;
49    }
50
51    /**
52     * @param used
53     *            to set.
54     * @return this for fluency.
55     */
56    public PhysicalStoreBuilder withUsed(final long used) {
57        this.used = used;
58        return this;
59    }
60
61    /**
62     * @return the build {@link PhysicalStore} object.
63     */
64    public PhysicalStore build() {
65        ErrorChecker.throwIfNotSet(this.getUUID(), PhysicalResource.UUID_NAME);
66        final PhysicalStore res = new PhysicalStore(this.getUUID(), this.parent, this.capacity,
67                this.used);
68        this.reset();
69        return res;
70    }
71}