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

io.virtdata.functionadapters.ToLongFunction Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.functionadapters;

import io.virtdata.annotations.ThreadSafeMapper;

import java.util.function.*;

/**
 * Adapts any {@link FunctionalInterface} type to a LongFunction,
 * for use with higher-order functions, when they require a
 * LongFunction as an argument.
 */
@ThreadSafeMapper
public class ToLongFunction implements LongFunction {

    private LongFunction function;

    public ToLongFunction(LongUnaryOperator op) {
        this.function = op::applyAsLong;
    }
    public ToLongFunction(Function op) {
        this.function = op::apply;
    }
    public ToLongFunction(LongToIntFunction op) {
        this.function = op::applyAsInt;
    }
    public ToLongFunction(LongToDoubleFunction op) {
        this.function = op::applyAsDouble;
    }
    public ToLongFunction(LongFunction func) {
        this.function = func;
    }


    @Override
    public Object apply(long value) {
        return function.apply(value);
    }
}