All Downloads are FREE. Search and download functionalities are using the official Maven repository.

oshi.hardware.common.AbstractLogicalVolumeGroup Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2021-2022 The OSHI Project Contributors
 * SPDX-License-Identifier: MIT
 */
package oshi.hardware.common;

import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import oshi.hardware.LogicalVolumeGroup;

public class AbstractLogicalVolumeGroup implements LogicalVolumeGroup {

    private final String name;
    private final Map> lvMap;
    private final Set pvSet;

    /**
     * @param name  Name of the volume group
     * @param lvMap Logical volumes derived from this volume group and the physical volumes its mapped to.
     * @param pvSet Set of physical volumes this volume group consists of.
     */
    protected AbstractLogicalVolumeGroup(String name, Map> lvMap, Set pvSet) {
        this.name = name;
        for (Entry> entry : lvMap.entrySet()) {
            lvMap.put(entry.getKey(), Collections.unmodifiableSet(entry.getValue()));
        }
        this.lvMap = Collections.unmodifiableMap(lvMap);
        this.pvSet = Collections.unmodifiableSet(pvSet);
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public Map> getLogicalVolumes() {
        return lvMap;
    }

    @Override
    public Set getPhysicalVolumes() {
        return pvSet;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("Logical Volume Group: ");
        sb.append(name).append("\n |-- PVs: ");
        sb.append(pvSet.toString());
        for (Entry> entry : lvMap.entrySet()) {
            sb.append("\n |-- LV: ").append(entry.getKey());
            Set mappedPVs = entry.getValue();
            if (!mappedPVs.isEmpty()) {
                sb.append(" --> ").append(mappedPVs);
            }
        }
        return sb.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy