com.farao_community.farao.data.crac_impl.NetworkActionAdderImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of farao-crac-impl Show documentation
Show all versions of farao-crac-impl Show documentation
Object model for CRAC implementation
/*
* Copyright (c) 2021, 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.farao_community.farao.data.crac_impl;
import com.farao_community.farao.commons.FaraoException;
import com.farao_community.farao.commons.logs.FaraoLoggerProvider;
import com.farao_community.farao.data.crac_api.network_action.*;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
/**
* @author Baptiste Seguinot {@literal }
* @author Peter Mitri {@literal }
*/
public class NetworkActionAdderImpl extends AbstractRemedialActionAdder implements NetworkActionAdder {
private Set elementaryActions;
NetworkActionAdderImpl(CracImpl owner) {
super(owner);
this.elementaryActions = new HashSet<>();
}
@Override
protected String getTypeDescription() {
return "NetworkAction";
}
@Override
public TopologicalActionAdder newTopologicalAction() {
return new TopologicalActionAdderImpl(this);
}
@Override
public PstSetpointAdder newPstSetPoint() {
return new PstSetpointAdderImpl(this);
}
@Override
public InjectionSetpointAdder newInjectionSetPoint() {
return new InjectionSetpointAdderImpl(this);
}
@Override
public SwitchPairAdder newSwitchPair() {
return new SwitchPairAdderImpl(this);
}
@Override
public NetworkAction add() {
checkId();
if (!Objects.isNull(getCrac().getRemedialAction(id))) {
throw new FaraoException(String.format("A remedial action with id %s already exists", id));
}
if (usageRules.isEmpty()) {
FaraoLoggerProvider.BUSINESS_WARNS.warn("NetworkAction {} does not contain any usage rule, by default it will never be available", id);
}
if (elementaryActions.isEmpty()) {
throw new FaraoException(String.format("NetworkAction %s has to have at least one ElementaryAction.", id));
}
NetworkAction networkAction = new NetworkActionImpl(id, name, operator, usageRules, elementaryActions, speed);
getCrac().addNetworkAction(networkAction);
return networkAction;
}
void addElementaryAction(ElementaryAction elementaryAction) {
this.elementaryActions.add(elementaryAction);
}
}