com.powsybl.dataframe.MappingUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pypowsybl Show documentation
Show all versions of pypowsybl Show documentation
A C interface to powsybl, for pypowsybl implementation
The 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/.
* SPDX-License-Identifier: MPL-2.0
*/
package com.powsybl.dataframe;
import java.util.function.Function;
import java.util.function.ToDoubleFunction;
import java.util.function.ToIntFunction;
/**
* Utility methods to help mapping objects to values.
*
* @author Geoffroy Jamgotchian {@literal }
* @author Sylvain Leclerc {@literal }
*/
public final class MappingUtils {
private MappingUtils() {
}
public static final int INT_UNDEFINED_VALUE = -99999;
/**
* Maps T to another object U and returns the specified undefined value if U is {@code null}
*/
public static ToDoubleFunction ifExistsDouble(Function objectGetter, ToDoubleFunction valueGetter, double undefinedValue) {
return item -> {
U object = objectGetter.apply(item);
return object != null ? valueGetter.applyAsDouble(object) : undefinedValue;
};
}
/**
* Maps T to another object U and returns {@link Double#NaN} if U is {@code null}
*/
public static ToDoubleFunction ifExistsDouble(Function objectGetter, ToDoubleFunction valueGetter) {
return ifExistsDouble(objectGetter, valueGetter, Double.NaN);
}
/**
* Maps T to another object U and returns the specified undefined value if U is {@code null}
*/
public static ToIntFunction ifExistsInt(Function objectGetter, ToIntFunction valueGetter, int undefinedValue) {
return item -> {
U object = objectGetter.apply(item);
return object != null ? valueGetter.applyAsInt(object) : undefinedValue;
};
}
/**
* Maps T to another object U and returns {@link MappingUtils#INT_UNDEFINED_VALUE} if U is {@code null}
*/
public static ToIntFunction ifExistsInt(Function objectGetter, ToIntFunction valueGetter) {
return ifExistsInt(objectGetter, valueGetter, INT_UNDEFINED_VALUE);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy