/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

  1. package nl.bitbrains.nebu.common.topology;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. /**
  7. * @author Jesse Donkervliet, Tim Hegeman, and Stefan Hugtenburg
  8. *
  9. */
  10. public abstract class PhysicalResourceWithDisks extends PhysicalResource {
  11. private final Map<String, PhysicalStore> disks;
  12. /**
  13. * @param id
  14. * to use.
  15. * @param disks
  16. * to set as disks.
  17. */
  18. public PhysicalResourceWithDisks(final String id, final Map<String, PhysicalStore> disks) {
  19. super(id);
  20. this.disks = disks;
  21. }
  22. /**
  23. * @param id
  24. * to set.
  25. * @param disks
  26. * to add.
  27. */
  28. public PhysicalResourceWithDisks(final String id, final List<PhysicalStore> disks) {
  29. super(id);
  30. this.disks = new HashMap<String, PhysicalStore>();
  31. for (final PhysicalStore disk : disks) {
  32. final PhysicalStore newDisk = new PhysicalStore(disk);
  33. newDisk.setParent(this);
  34. this.addDisk(newDisk);
  35. }
  36. }
  37. /**
  38. * @return Disks contained in the PhysicalRack.
  39. */
  40. public final List<PhysicalStore> getDisks() {
  41. return new ArrayList<PhysicalStore>(this.disks.values());
  42. }
  43. /**
  44. * @param disk
  45. * the Disk to add to the PhysicalRack.
  46. */
  47. protected final void addDisk(final PhysicalStore disk) {
  48. if (disk != null) {
  49. this.disks.put(disk.getUniqueIdentifier(), disk);
  50. }
  51. }
  52. /**
  53. * @param disk
  54. * the disk to remove from the PhysicalRack.
  55. */
  56. protected final void removeDisk(final PhysicalStore disk) {
  57. if (disk != null) {
  58. this.disks.remove(disk.getUniqueIdentifier());
  59. }
  60. }
  61. }