com.powsybl.glsk.cse.BlockWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of powsybl-glsk-document-cse Show documentation
Show all versions of powsybl-glsk-document-cse Show documentation
Model of GLSK according to CSE format with its importer.
The newest version!
/*
* Copyright (c) 2023, 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/.
*/
package com.powsybl.glsk.cse;
import xsd.etso_core_cmpts.QuantityType;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author Vincent BOCHET {@literal }
*/
public final class BlockWrapper {
private final Object block;
public BlockWrapper(Object block) {
this.block = block;
}
public Object getBlock() {
return block;
}
public Optional getOrder() {
try {
BigInteger order = (BigInteger) block.getClass().getDeclaredField("order").get(block);
return Optional.ofNullable(order);
} catch (NoSuchFieldException | IllegalAccessException e) {
return Optional.empty();
}
}
public Optional getMaximumShift() {
try {
QuantityType maximumShift = (QuantityType) block.getClass().getDeclaredField("maximumShift").get(block);
return Optional.ofNullable(maximumShift).map(QuantityType::getV);
} catch (NoSuchFieldException | IllegalAccessException e) {
return Optional.empty();
}
}
public Optional getFactor() {
try {
QuantityType factor = (QuantityType) block.getClass().getDeclaredField("factor").get(block);
return Optional.ofNullable(factor).map(QuantityType::getV);
} catch (NoSuchFieldException | IllegalAccessException e) {
return Optional.empty();
}
}
public Optional> getNodeList() {
try {
List