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

com.powsybl.openrao.data.cracimpl.OnInstantImpl 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.Instant;
import com.powsybl.openrao.data.cracapi.State;
import com.powsybl.openrao.data.cracapi.usagerule.OnInstant;
import com.powsybl.openrao.data.cracapi.usagerule.UsageMethod;

/**
 * The UsageMethod of the OnInstantImpl UsageRule is effective in all the States which
 * are at a given Instant.
 *
 * @author Viktor Terrier {@literal }
 * @author Baptiste Seguinot {@literal }
 */
public final class OnInstantImpl extends AbstractUsageRule implements OnInstant {

    private Instant instant;

    OnInstantImpl(UsageMethod usageMethod, Instant instant) {
        super(usageMethod);
        this.instant = instant;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        OnInstantImpl rule = (OnInstantImpl) o;
        return super.equals(o) && rule.getInstant().equals(instant);
    }

    @Override
    public int hashCode() {
        return usageMethod.hashCode() * 19 + instant.hashCode() * 47;
    }

    @Override
    public UsageMethod getUsageMethod(State state) {
        return state.getInstant().equals(instant) ? usageMethod : UsageMethod.UNDEFINED;
    }

    @Override
    public Instant getInstant() {
        return instant;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy