View Javadoc
1   /*
2    * Copyright 2021-2022 The OSHI Project Contributors
3    * SPDX-License-Identifier: MIT
4    */
5   package oshi.hardware.common;
6   
7   import java.util.Collections;
8   import java.util.Map;
9   import java.util.Map.Entry;
10  import java.util.Set;
11  
12  import oshi.hardware.LogicalVolumeGroup;
13  
14  public class AbstractLogicalVolumeGroup implements LogicalVolumeGroup {
15  
16      private final String name;
17      private final Map<String, Set<String>> lvMap;
18      private final Set<String> pvSet;
19  
20      /**
21       * @param name  Name of the volume group
22       * @param lvMap Logical volumes derived from this volume group and the physical volumes its mapped to.
23       * @param pvSet Set of physical volumes this volume group consists of.
24       */
25      protected AbstractLogicalVolumeGroup(String name, Map<String, Set<String>> lvMap, Set<String> pvSet) {
26          this.name = name;
27          for (Entry<String, Set<String>> entry : lvMap.entrySet()) {
28              lvMap.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue()));
29          }
30          this.lvMap = Collections.unmodifiableMap(lvMap);
31          this.pvSet = Collections.unmodifiableSet(pvSet);
32      }
33  
34      @Override
35      public String getName() {
36          return name;
37      }
38  
39      @Override
40      public Map<String, Set<String>> getLogicalVolumes() {
41          return lvMap;
42      }
43  
44      @Override
45      public Set<String> getPhysicalVolumes() {
46          return pvSet;
47      }
48  
49      @Override
50      public String toString() {
51          StringBuilder sb = new StringBuilder("Logical Volume Group: ");
52          sb.append(name).append("\n |-- PVs: ");
53          sb.append(pvSet.toString());
54          for (Entry<String, Set<String>> entry : lvMap.entrySet()) {
55              sb.append("\n |-- LV: ").append(entry.getKey());
56              Set<String> mappedPVs = entry.getValue();
57              if (!mappedPVs.isEmpty()) {
58                  sb.append(" --> ").append(mappedPVs);
59              }
60          }
61          return sb.toString();
62      }
63  }