com.powsybl.openrao.data.cracimpl.OnFlowConstraintInCountryImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of open-rao-crac-impl Show documentation
Show all versions of open-rao-crac-impl Show documentation
Object model for CRAC implementation
The newest version!
/*
* Copyright (c) 2022, 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.openrao.data.cracimpl;
import com.powsybl.contingency.Contingency;
import com.powsybl.openrao.data.cracapi.Instant;
import com.powsybl.openrao.data.cracapi.State;
import com.powsybl.openrao.data.cracapi.usagerule.OnFlowConstraintInCountry;
import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod;
import com.powsybl.iidm.network.Country;
import java.util.Optional;
/**
* @author Peter Mitri {@literal }
*/
public class OnFlowConstraintInCountryImpl extends AbstractUsageRule implements OnFlowConstraintInCountry {
private final Instant instant;
private final Optional contingency;
private final Country country;
OnFlowConstraintInCountryImpl(UsageMethod usageMethod, Instant instant, Optional contingency, Country country) {
super(usageMethod);
this.instant = instant;
this.contingency = contingency;
this.country = country;
}
@Override
public Country getCountry() {
return country;
}
@Override
public Instant getInstant() {
return instant;
}
@Override
public Optional getContingency() {
return contingency;
}
@Override
public UsageMethod getUsageMethod(State state) {
if (contingency.isPresent() && !contingency.get().equals(state.getContingency().orElse(null))) {
return UsageMethod.UNDEFINED;
}
return state.getInstant().equals(instant) ? usageMethod : UsageMethod.UNDEFINED;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
OnFlowConstraintInCountryImpl rule = (OnFlowConstraintInCountryImpl) o;
return super.equals(o) && rule.getInstant().equals(instant)
&& rule.getContingency().equals(contingency)
&& rule.getCountry().equals(country);
}
@Override
public int hashCode() {
return country.hashCode() * 19
+ instant.hashCode() * 47
+ contingency.hashCode() * 59;
}
}