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

io.virtdata.libbasics.shared.from_long.to_long.Clamp Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.libbasics.shared.from_long.to_long;

import io.virtdata.annotations.Example;
import io.virtdata.annotations.ThreadSafeMapper;

import java.util.function.LongUnaryOperator;

/**
 * Clamp the output values to be at least the minimum value and
 * at most the maximum value.
 */
@ThreadSafeMapper
public class Clamp implements LongUnaryOperator {

    private final long min;
    private final long max;

    @Example({"Clamp(4L,400L)","clamp the output values in the range [4L,400L], inclusive"})
    public Clamp(long min, long max) {
        this.min = min;
        this.max = max;
    }

    @Override
    public long applyAsLong(long operand) {
        return Long.min(max,Long.max(min,operand));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy