com.powsybl.cgmes.extensions.CgmesMetadataModelsImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-cgmes-extensions Show documentation
Show all versions of powsybl-cgmes-extensions Show documentation
A set of CGMES common extensions
The newest version!
/**
* Copyright (c) 2024, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.cgmes.extensions;
import com.powsybl.cgmes.model.CgmesMetadataModel;
import com.powsybl.cgmes.model.CgmesSubset;
import com.powsybl.commons.extensions.AbstractExtension;
import com.powsybl.iidm.network.Network;
import java.util.*;
/**
* @author Luma Zamarreño {@literal }
*/
class CgmesMetadataModelsImpl extends AbstractExtension implements CgmesMetadataModels {
private final List models = new ArrayList<>();
private final EnumMap subsetModel = new EnumMap<>(CgmesSubset.class);
CgmesMetadataModelsImpl(Set models) {
this.models.addAll(models);
models.forEach(m -> subsetModel.put(m.getSubset(), m));
}
@Override
public Optional getModelForSubset(CgmesSubset subset) {
return Optional.ofNullable(subsetModel.get(subset));
}
@Override
public Optional getModelForSubsetModelingAuthoritySet(CgmesSubset subset, String modelingAuthoritySet) {
return models.stream()
.filter(m -> m.getSubset().equals(subset) && m.getModelingAuthoritySet().equals(modelingAuthoritySet))
.findFirst();
}
@Override
public Collection getModels() {
return Collections.unmodifiableCollection(models);
}
@Override
public List getSortedModels() {
return models.stream().sorted(
Comparator.comparing(CgmesMetadataModel::getModelingAuthoritySet)
.thenComparing(CgmesMetadataModel::getSubset)
.thenComparing(CgmesMetadataModel::getVersion)
.thenComparing(CgmesMetadataModel::getId)
).toList();
}
}