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

com.farao_community.farao.data.crac_impl.TapRangeAdderImpl Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
/*
 * 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.data.crac_api.range_action.PstRangeActionAdder;
import com.farao_community.farao.data.crac_api.range.RangeType;
import com.farao_community.farao.data.crac_api.range.TapRange;
import com.farao_community.farao.data.crac_api.range.TapRangeAdder;

/**
 * @author Baptiste Seguinot {@literal }
 * @author Peter Mitri {@literal }
 */
public class TapRangeAdderImpl implements TapRangeAdder {

    private Integer minTap;
    private Integer maxTap;
    private RangeType rangeType;
    private static final String CLASS_NAME = "TapRange";

    private PstRangeActionAdderImpl ownerAdder;

    TapRangeAdderImpl(PstRangeActionAdderImpl ownerAdder) {
        this.ownerAdder = ownerAdder;
        this.minTap = Integer.MIN_VALUE;
        this.maxTap = Integer.MAX_VALUE;
    }

    @Override
    public TapRangeAdder withMinTap(int minTap) {
        this.minTap = minTap;
        return this;
    }

    @Override
    public TapRangeAdder withMaxTap(int maxTap) {
        this.maxTap = maxTap;
        return this;
    }

    @Override
    public TapRangeAdder withRangeType(RangeType rangeType) {
        this.rangeType = rangeType;
        return this;
    }

    @Override
    public PstRangeActionAdder add() {
        AdderUtils.assertAttributeNotNull(minTap, CLASS_NAME, "min value", "withMin()");
        AdderUtils.assertAttributeNotNull(maxTap, CLASS_NAME, "max value", "withMax()");
        AdderUtils.assertAttributeNotNull(rangeType, CLASS_NAME, "range type", "withRangeType()");

        if (maxTap < minTap) {
            throw new FaraoException("Max tap of TapRange must be equal or greater than min tap.");
        }

        TapRange pstRange = new TapRangeImpl(minTap, maxTap, rangeType);

        ownerAdder.addRange(pstRange);
        return ownerAdder;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy