/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

  1. package nl.bitbrains.nebu.common.topology;
  2. import nl.bitbrains.nebu.common.util.ErrorChecker;
  3. /**
  4. * Builder class for the {@link PhysicalHost}.
  5. *
  6. * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
  7. *
  8. */
  9. public class PhysicalHostBuilder extends PhysicalResourceWithDisksBuilder<PhysicalHost> {
  10. private PhysicalRack parent;
  11. private double memUsage;
  12. private double cpuUsage;
  13. /**
  14. * Simple constructor.
  15. */
  16. public PhysicalHostBuilder() {
  17. this.reset();
  18. }
  19. /**
  20. * Resets the builder.
  21. */
  22. @Override
  23. public final void reset() {
  24. super.reset();
  25. this.parent = null;
  26. this.memUsage = 0;
  27. this.cpuUsage = 0;
  28. }
  29. /**
  30. * @param parent
  31. * to build with
  32. * @return this for fluency.
  33. */
  34. public PhysicalHostBuilder withParent(final PhysicalRack parent) {
  35. this.parent = parent;
  36. return this;
  37. }
  38. /**
  39. * @param usage
  40. * to set.
  41. * @return this for fluency.
  42. */
  43. public PhysicalHostBuilder withCpuUsage(final double usage) {
  44. this.cpuUsage = usage;
  45. return this;
  46. }
  47. /**
  48. * @param usage
  49. * to set.
  50. * @return this for fluency.
  51. */
  52. public PhysicalHostBuilder withMemUsage(final double usage) {
  53. this.memUsage = usage;
  54. return this;
  55. }
  56. /**
  57. * @return the build {@link PhysicalHost} object.
  58. */
  59. public PhysicalHost build() {
  60. ErrorChecker.throwIfNotSet(this.getUUID(), PhysicalResource.UUID_NAME);
  61. final PhysicalHost host = new PhysicalHost(this.getUUID(), this.parent, this.getDisks(),
  62. this.cpuUsage, this.memUsage);
  63. this.reset();
  64. return host;
  65. }
  66. }