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

com.powsybl.openrao.data.cracimpl.AbstractCnec Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2020, 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.openrao.data.cracapi.NetworkElement;
import com.powsybl.openrao.data.cracapi.State;
import com.powsybl.openrao.data.cracapi.cnec.Cnec;

import java.util.Set;

/**
 * @author Joris Mancini {@literal }
 */
public abstract class AbstractCnec> extends AbstractIdentifiable implements Cnec {

    protected final Set networkElements;
    protected final State state;
    protected boolean optimized;
    protected boolean monitored;
    protected final String operator;
    protected final String border;
    protected double reliabilityMargin = 0;

    protected AbstractCnec(String id,
                           String name,
                           Set networkElements,
                           String operator,
                           String border,
                           State state,
                           boolean optimized,
                           boolean monitored,
                           double reliabilityMargin) {
        super(id, name);
        this.networkElements = networkElements;
        this.operator = operator;
        this.border = border;
        this.state = state;
        this.optimized = optimized;
        this.monitored = monitored;
        this.reliabilityMargin = reliabilityMargin;
    }

    @Override
    public final State getState() {
        return state;
    }

    @Override
    public final Set getNetworkElements() {
        return networkElements;
    }

    @Override
    public boolean isOptimized() {
        return optimized;
    }

    @Override
    @Deprecated (since = "3.0.0")
    public void setOptimized(boolean optimized) {
        this.optimized = optimized;
    }

    @Override
    public boolean isMonitored() {
        return monitored;
    }

    @Override
    @Deprecated (since = "3.0.0")
    public void setMonitored(boolean monitored) {
        this.monitored = monitored;
    }

    @Override
    public String getOperator() {
        return this.operator;
    }

    @Override
    public String getBorder() {
        return border;
    }

    @Override
    public double getReliabilityMargin() {
        return reliabilityMargin;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AbstractCnec cnec = (AbstractCnec) o;
        return super.equals(cnec)
            && networkElements.equals(cnec.getNetworkElements())
            && state.equals(cnec.getState())
            && optimized == cnec.isOptimized()
            && monitored == cnec.isMonitored()
            && reliabilityMargin == cnec.getReliabilityMargin();
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + networkElements.hashCode();
        result = 31 * result + state.hashCode();
        result = 31 * result + Double.hashCode(reliabilityMargin);
        return result;
    }
}