/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

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