PageRenderTime 27ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

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

https://github.com/deltaforge/nebu-common-java
Java | 75 lines | 36 code | 9 blank | 30 comment | 0 complexity | 8d3bb3bb9742b740d9a84ab91bdebf9d 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 PhysicalHost}.
 7 * 
 8 * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
 9 * 
10 */
11public class PhysicalHostBuilder extends PhysicalResourceWithDisksBuilder<PhysicalHost> {
12    private PhysicalRack parent;
13    private double memUsage;
14    private double cpuUsage;
15
16    /**
17     * Simple constructor.
18     */
19    public PhysicalHostBuilder() {
20        this.reset();
21    }
22
23    /**
24     * Resets the builder.
25     */
26    @Override
27    public final void reset() {
28        super.reset();
29        this.parent = null;
30        this.memUsage = 0;
31        this.cpuUsage = 0;
32    }
33
34    /**
35     * @param parent
36     *            to build with
37     * @return this for fluency.
38     */
39    public PhysicalHostBuilder withParent(final PhysicalRack parent) {
40        this.parent = parent;
41        return this;
42    }
43
44    /**
45     * @param usage
46     *            to set.
47     * @return this for fluency.
48     */
49    public PhysicalHostBuilder withCpuUsage(final double usage) {
50        this.cpuUsage = usage;
51        return this;
52    }
53
54    /**
55     * @param usage
56     *            to set.
57     * @return this for fluency.
58     */
59    public PhysicalHostBuilder withMemUsage(final double usage) {
60        this.memUsage = usage;
61        return this;
62    }
63
64    /**
65     * @return the build {@link PhysicalHost} object.
66     */
67    public PhysicalHost build() {
68        ErrorChecker.throwIfNotSet(this.getUUID(), PhysicalResource.UUID_NAME);
69        final PhysicalHost host = new PhysicalHost(this.getUUID(), this.parent, this.getDisks(),
70                this.cpuUsage, this.memUsage);
71        this.reset();
72        return host;
73    }
74
75}