com.tangosol.util.function.Remote Maven / Gradle / Ivy
Show all versions of coherence Show documentation
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates.
*
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
package com.tangosol.util.function;
import com.tangosol.util.ValueExtractor;
import com.tangosol.util.comparator.InverseComparator;
import com.tangosol.util.comparator.SafeComparator;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.SortedMap;
import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
/**
* Helper interfaces and methods that enable capture of standard JDK
* functional interfaces as serializable lambdas.
*
* @author as 2014.07.16
* @since 12.2.1
*/
public class Remote
{
// ---- Consumers -------------------------------------------------------
/**
* Represents an operation that accepts a single input argument and returns
* no result. Unlike most other functional interfaces, {@code Consumer} is
* expected to operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(Object)}.
*
* @param the type of the input to the operation
*/
@FunctionalInterface
public static interface Consumer
extends java.util.function.Consumer, Serializable
{
/**
* Returns a composed {@code Consumer} that performs, in sequence, this
* operation followed by the {@code after} operation. If performing
* either operation throws an exception, it is relayed to the caller of
* the composed operation. If performing this operation throws an
* exception, the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
*
* @return a composed {@code Consumer} that performs in sequence this
* operation followed by the {@code after} operation
*
* @throws NullPointerException if {@code after} is null
*/
default Consumer andThen(Consumer super T> after)
{
Objects.requireNonNull(after);
return (T t) ->
{
accept(t);
after.accept(t);
};
}
}
/**
* Capture serializable Consumer.
*
* @param consumer lambda to capture
* @param the type of the input to the operation
*
* @return serializable Consumer
*/
public static Consumer consumer(Consumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts two input arguments and returns no
* result. This is the two-arity specialization of {@link Consumer}. Unlike
* most other functional interfaces, {@code BiConsumer} is expected to
* operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(Object, Object)}.
*
* @param the type of the first argument to the operation
* @param the type of the second argument to the operation
*
* @see Consumer
*/
@FunctionalInterface
public static interface BiConsumer
extends java.util.function.BiConsumer, Serializable
{
/**
* Returns a composed {@code BiConsumer} that performs, in sequence,
* this operation followed by the {@code after} operation. If performing
* either operation throws an exception, it is relayed to the caller of
* the composed operation. If performing this operation throws an
* exception, the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
*
* @return a composed {@code BiConsumer} that performs in sequence this
* operation followed by the {@code after} operation
*
* @throws NullPointerException if {@code after} is null
*/
default BiConsumer andThen(BiConsumer super T, ? super U> after)
{
Objects.requireNonNull(after);
return (l, r) ->
{
accept(l, r);
after.accept(l, r);
};
}
}
/**
* Capture serializable BiConsumer.
*
* @param biConsumer lambda to capture
* @param the type of the input to the operation
* @param the type of the second argument to the operation
*
* @return serializable BiConsumer
*/
public static BiConsumer biConsumer(BiConsumer biConsumer)
{
return biConsumer;
}
/**
* Represents an operation that accepts a single {@code double}-valued
* argument and returns no result. This is the primitive type
* specialization of {@link Consumer} for {@code double}. Unlike most other
* functional interfaces, {@code DoubleConsumer} is expected to operate via
* side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(double)}.
*
* @see Consumer
*/
@FunctionalInterface
public static interface DoubleConsumer
extends java.util.function.DoubleConsumer, Serializable
{
/**
* Returns a composed {@code DoubleConsumer} that performs, in sequence,
* this operation followed by the {@code after} operation. If performing
* either operation throws an exception, it is relayed to the caller of
* the composed operation. If performing this operation throws an
* exception, the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
*
* @return a composed {@code DoubleConsumer} that performs in sequence
* this operation followed by the {@code after} operation
*
* @throws NullPointerException if {@code after} is null
*/
default DoubleConsumer andThen(DoubleConsumer after)
{
Objects.requireNonNull(after);
return (double t) ->
{
accept(t);
after.accept(t);
};
}
}
/**
* Capture serializable DoubleConsumer.
*
* @param consumer lambda to capture
*
* @return serializable DoubleConsumer
*/
public static DoubleConsumer doubleConsumer(DoubleConsumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts a single {@code int}-valued argument
* and returns no result. This is the primitive type specialization of
* {@link Consumer} for {@code int}. Unlike most other functional
* interfaces, {@code IntConsumer} is expected to operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(int)}.
*
* @see Consumer
*/
@FunctionalInterface
public static interface IntConsumer
extends java.util.function.IntConsumer, Serializable
{
/**
* Returns a composed {@code IntConsumer} that performs, in sequence,
* this operation followed by the {@code after} operation. If performing
* either operation throws an exception, it is relayed to the caller of
* the composed operation. If performing this operation throws an
* exception, the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
*
* @return a composed {@code IntConsumer} that performs in sequence this
* operation followed by the {@code after} operation
*
* @throws NullPointerException if {@code after} is null
*/
default IntConsumer andThen(IntConsumer after)
{
Objects.requireNonNull(after);
return (int t) ->
{
accept(t);
after.accept(t);
};
}
}
/**
* Capture serializable IntConsumer.
*
* @param consumer lambda to capture
*
* @return serializable IntConsumer
*/
public static IntConsumer intConsumer(IntConsumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts a single {@code long}-valued
* argument and returns no result. This is the primitive type
* specialization of {@link Consumer} for {@code long}. Unlike most other
* functional interfaces, {@code LongConsumer} is expected to operate via
* side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(long)}.
*
* @see Consumer
*/
@FunctionalInterface
public static interface LongConsumer
extends java.util.function.LongConsumer, Serializable
{
/**
* Returns a composed {@code LongConsumer} that performs, in sequence,
* this operation followed by the {@code after} operation. If performing
* either operation throws an exception, it is relayed to the caller of
* the composed operation. If performing this operation throws an
* exception, the {@code after} operation will not be performed.
*
* @param after the operation to perform after this operation
*
* @return a composed {@code LongConsumer} that performs in sequence
* this operation followed by the {@code after} operation
*
* @throws NullPointerException if {@code after} is null
*/
default LongConsumer andThen(LongConsumer after)
{
Objects.requireNonNull(after);
return (long t) ->
{
accept(t);
after.accept(t);
};
}
}
/**
* Capture serializable LongConsumer.
*
* @param consumer lambda to capture
*
* @return serializable LongConsumer
*/
public static LongConsumer longConsumer(LongConsumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts an object-valued and a {@code
* double}-valued argument, and returns no result. This is the {@code
* (reference, double)} specialization of {@link BiConsumer}. Unlike most
* other functional interfaces, {@code ObjDoubleConsumer} is expected to
* operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(Object, double)}.
*
* @param the type of the object argument to the operation
*
* @see BiConsumer
*/
@FunctionalInterface
public static interface ObjDoubleConsumer
extends java.util.function.ObjDoubleConsumer, Serializable
{
}
/**
* Capture serializable ObjDoubleConsumer.
*
* @param consumer lambda to capture
* @param the type of the object argument to the operation
*
* @return serializable ObjDoubleConsumer
*/
public static ObjDoubleConsumer objDoubleConsumer(ObjDoubleConsumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts an object-valued and a {@code
* int}-valued argument, and returns no result. This is the {@code
* (reference, int)} specialization of {@link java.util.function.BiConsumer}.
* Unlike most other functional interfaces, {@code ObjIntConsumer} is
* expected to operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(Object, int)}.
*
* @param the type of the object argument to the operation
*
* @see BiConsumer
*/
@FunctionalInterface
public static interface ObjIntConsumer
extends java.util.function.ObjIntConsumer, Serializable
{
}
/**
* Capture serializable ObjIntConsumer.
*
* @param consumer lambda to capture
* @param the type of the object argument to the operation
*
* @return serializable ObjIntConsumer
*/
public static ObjIntConsumer objIntConsumer(ObjIntConsumer consumer)
{
return consumer;
}
/**
* Represents an operation that accepts an object-valued and a {@code
* long}-valued argument, and returns no result. This is the {@code
* (reference, long)} specialization of {@link BiConsumer}. Unlike most
* other functional interfaces, {@code ObjLongConsumer} is expected to
* operate via side-effects.
*
*
This is a functional interface
* whose functional method is {@link #accept(Object, long)}.
*
* @param the type of the object argument to the operation
*
* @see BiConsumer
*/
@FunctionalInterface
public static interface ObjLongConsumer
extends java.util.function.ObjLongConsumer, Serializable
{
}
/**
* Capture serializable ObjLongConsumer.
*
* @param consumer lambda to capture
* @param the type of the object argument to the operation
*
* @return serializable ObjLongConsumer
*/
public static ObjLongConsumer objLongConsumer(ObjLongConsumer consumer)
{
return consumer;
}
// ---- Functions -------------------------------------------------------
/**
* Represents a function that accepts one argument and produces a result.
*
*
This is a functional interface
* whose functional method is {@link #apply(Object)}.
*
* @param the type of the input to the function
* @param the type of the result of the function
*/
@FunctionalInterface
public static interface Function
extends java.util.function.Function, Serializable
{
/**
* Returns a composed function that first applies the {@code before}
* function to its input, and then applies this function to the result.
* If evaluation of either function throws an exception, it is relayed
* to the caller of the composed function.
*
* @param the type of input to the {@code before} function, and
* to the composed function
* @param before the function to apply before this function is applied
*
* @return a composed function that first applies the {@code before}
* function and then applies this function
*
* @throws NullPointerException if before is null
* @see #andThen(Function)
*/
default Function compose(Function super V, ? extends T> before)
{
Objects.requireNonNull(before);
return (V v) -> apply(before.apply(v));
}
/**
* Returns a composed function that first applies this function to its
* input, and then applies the {@code after} function to the result. If
* evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param the type of output of the {@code after} function, and of
* the composed function
* @param after the function to apply after this function is applied
*
* @return a composed function that first applies this function and then
* applies the {@code after} function
*
* @throws NullPointerException if after is null
* @see #compose(Function)
*/
default Function andThen(Function super R, ? extends V> after)
{
Objects.requireNonNull(after);
return (T t) -> after.apply(apply(t));
}
/**
* Returns a function that always returns its input argument.
*
* @param the type of the input and output objects to the function
*
* @return a function that always returns its input argument
*/
static Function identity()
{
return t -> t;
}
}
/**
* Capture serializable Function.
*
* @param function lambda to capture
* @param the type of the input to the function
* @param the type of the result of the function
*
* @return serializable Function
*/
public static Function function(Function function)
{
return function;
}
/**
* Represents a function that accepts two arguments and produces a result.
* This is the two-arity specialization of {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #apply(Object, Object)}.
*
* @param the type of the first argument to the function
* @param the type of the second argument to the function
* @param the type of the result of the function
*
* @see Function
*/
@FunctionalInterface
public static interface BiFunction
extends java.util.function.BiFunction, Serializable
{
/**
* Returns a composed function that first applies this function to its
* input, and then applies the {@code after} function to the result. If
* evaluation of either function throws an exception, it is relayed to
* the caller of the composed function.
*
* @param the type of output of the {@code after} function, and of
* the composed function
* @param after the function to apply after this function is applied
*
* @return a composed function that first applies this function and then
* applies the {@code after} function
*
* @throws NullPointerException if after is null
*/
default BiFunction andThen(Function super R, ? extends V> after)
{
Objects.requireNonNull(after);
return (T t, U u) -> after.apply(apply(t, u));
}
}
/**
* Capture serializable BiFunction.
*
* @param biFunction lambda to capture
* @param the type of the first argument to the function
* @param the type of the second argument to the function
* @param the type of the result of the function
*
* @return serializable BiFunction
*/
public static BiFunction biFunction(BiFunction biFunction)
{
return biFunction;
}
/**
* Represents a function that accepts a double-valued argument and produces
* a result. This is the {@code double}-consuming primitive specialization
* for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #apply(double)}.
*
* @param the type of the result of the function
*
* @see Function
*/
@FunctionalInterface
public static interface DoubleFunction
extends java.util.function.DoubleFunction, Serializable
{
}
/**
* Capture serializable DoubleFunction.
*
* @param function lambda to capture
* @param the type of the result of the function
*
* @return serializable DoubleFunction
*/
public static DoubleFunction doubleFunction(DoubleFunction function)
{
return function;
}
/**
* Represents a function that accepts a double-valued argument and produces
* an int-valued result. This is the {@code double}-to-{@code int}
* primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsInt(double)}.
*
* @see Function
*/
@FunctionalInterface
public static interface DoubleToIntFunction
extends java.util.function.DoubleToIntFunction, Serializable
{
}
/**
* Capture serializable DoubleToIntFunction.
*
* @param function lambda to capture
*
* @return serializable DoubleToIntFunction
*/
public static DoubleToIntFunction doubleToIntFunction(DoubleToIntFunction function)
{
return function;
}
/**
* Represents a function that accepts a double-valued argument and produces
* a long-valued result. This is the {@code double}-to-{@code long}
* primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsLong(double)}.
*
* @see Function
*/
@FunctionalInterface
public static interface DoubleToLongFunction
extends java.util.function.DoubleToLongFunction, Serializable
{
}
/**
* Capture serializable DoubleToLongFunction.
*
* @param function lambda to capture
*
* @return serializable DoubleToLongFunction
*/
public static DoubleToLongFunction doubleToLongFunction(DoubleToLongFunction function)
{
return function;
}
/**
* Represents a function that accepts an int-valued argument and produces a
* result. This is the {@code int}-consuming primitive specialization for
* {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #apply(int)}.
*
* @param the type of the result of the function
*
* @see Function
*/
@FunctionalInterface
public static interface IntFunction
extends java.util.function.IntFunction, Serializable
{
}
/**
* Capture serializable IntFunction.
*
* @param function lambda to capture
* @param the type of the result of the function
*
* @return serializable IntFunction
*/
public static IntFunction intFunction(IntFunction function)
{
return function;
}
/**
* Represents a function that accepts an int-valued argument and produces a
* double-valued result. This is the {@code int}-to-{@code double}
* primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsDouble(int)}.
*
* @see Function
*/
@FunctionalInterface
public static interface IntToDoubleFunction
extends java.util.function.IntToDoubleFunction, Serializable
{
}
/**
* Capture serializable IntToDoubleFunction.
*
* @param function lambda to capture
*
* @return serializable IntToDoubleFunction
*/
public static IntToDoubleFunction intToDoubleFunction(IntToDoubleFunction function)
{
return function;
}
/**
* Represents a function that accepts an int-valued argument and produces a
* long-valued result. This is the {@code int}-to-{@code long} primitive
* specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsLong(int)}.
*
* @see Function
*/
@FunctionalInterface
public static interface IntToLongFunction
extends java.util.function.IntToLongFunction, Serializable
{
}
/**
* Capture serializable IntToLongFunction.
*
* @param function lambda to capture
*
* @return serializable IntToLongFunction
*/
public static IntToLongFunction intToLongFunction(IntToLongFunction function)
{
return function;
}
/**
* Represents a function that accepts a long-valued argument and produces a
* result. This is the {@code long}-consuming primitive specialization for
* {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #apply(long)}.
*
* @param the type of the result of the function
*
* @see Function
*/
@FunctionalInterface
public static interface LongFunction
extends java.util.function.LongFunction, Serializable
{
}
/**
* Capture serializable LongFunction.
*
* @param function lambda to capture
* @param the type of the result of the function
*
* @return serializable LongFunction
*/
public static LongFunction longFunction(LongFunction function)
{
return function;
}
/**
* Represents a function that accepts a long-valued argument and produces a
* double-valued result. This is the {@code long}-to-{@code double}
* primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsDouble(long)}.
*
* @see Function
*/
@FunctionalInterface
public static interface LongToDoubleFunction
extends java.util.function.LongToDoubleFunction, Serializable
{
}
/**
* Capture serializable LongToDoubleFunction.
*
* @param function lambda to capture
*
* @return serializable LongToDoubleFunction
*/
public static LongToDoubleFunction longToDoubleFunction(LongToDoubleFunction function)
{
return function;
}
/**
* Represents a function that accepts a long-valued argument and produces an
* int-valued result. This is the {@code long}-to-{@code int} primitive
* specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsInt(long)}.
*
* @see Function
*/
@FunctionalInterface
public static interface LongToIntFunction
extends java.util.function.LongToIntFunction, Serializable
{
}
/**
* Capture serializable LongToIntFunction.
*
* @param function lambda to capture
*
* @return serializable LongToIntFunction
*/
public static LongToIntFunction longToIntFunction(LongToIntFunction function)
{
return function;
}
/**
* Represents a function that produces a Comparable-valued result.
*
*
This is a functional interface
* whose functional method is {@link #apply(Object)}.
*
* @param the type of the input to the function
*
* @see Function
*/
@FunctionalInterface
public static interface ToComparableFunction>
extends java.util.function.Function, Serializable
{
}
/**
* Represents a function that produces a BigDecimal-valued result.
*
*
This is a functional interface
* whose functional method is {@link #apply(Object)}.
*
* @param the type of the input to the function
*
* @see Function
*/
@FunctionalInterface
public static interface ToBigDecimalFunction
extends java.util.function.Function, Serializable
{
}
/**
* Represents a function that produces a double-valued result. This is the
* {@code double}-producing primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsDouble(Object)}.
*
* @param the type of the input to the function
*
* @see Function
*/
@FunctionalInterface
public static interface ToDoubleFunction
extends java.util.function.ToDoubleFunction, Serializable
{
}
/**
* Capture serializable ToDoubleFunction.
*
* @param function lambda to capture
* @param the type of the input to the function
*
* @return serializable ToDoubleFunction
*/
public static ToDoubleFunction toDoubleFunction(ToDoubleFunction function)
{
return function;
}
/**
* Represents a function that produces an int-valued result. This is the
* {@code int}-producing primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsInt(Object)}.
*
* @param the type of the input to the function
*
* @see Function
*/
@FunctionalInterface
public static interface ToIntFunction
extends java.util.function.ToIntFunction, Serializable
{
}
/**
* Capture serializable ToIntFunction.
*
* @param function lambda to capture
* @param the type of the input to the function
*
* @return serializable ToIntFunction
*/
public static ToIntFunction toIntFunction(ToIntFunction function)
{
return function;
}
/**
* Represents a function that produces a long-valued result. This is the
* {@code long}-producing primitive specialization for {@link Function}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsLong(Object)}.
*
* @param the type of the input to the function
*
* @see Function
*/
@FunctionalInterface
public static interface ToLongFunction
extends java.util.function.ToLongFunction, Serializable
{
}
/**
* Capture serializable ToLongFunction.
*
* @param function lambda to capture
* @param the type of the input to the function
*
* @return serializable ToLongFunction
*/
public static ToLongFunction toLongFunction(ToLongFunction function)
{
return function;
}
/**
* Represents a function that accepts two arguments and produces a
* double-valued result. This is the {@code double}-producing primitive
* specialization for {@link BiFunction}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsDouble(Object, Object)}.
*
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @see BiFunction
*/
@FunctionalInterface
public static interface ToDoubleBiFunction
extends java.util.function.ToDoubleBiFunction, Serializable
{
}
/**
* Capture serializable ToDoubleBiFunction.
*
* @param biFunction lambda to capture
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @return serializable ToDoubleBiFunction
*/
public static ToDoubleBiFunction toDoubleBiFunction(ToDoubleBiFunction biFunction)
{
return biFunction;
}
/**
* Represents a function that accepts two arguments and produces an
* int-valued result. This is the {@code int}-producing primitive
* specialization for {@link BiFunction}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsInt(Object, Object)}.
*
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @see BiFunction
*/
@FunctionalInterface
public static interface ToIntBiFunction
extends java.util.function.ToIntBiFunction, Serializable
{
}
/**
* Capture serializable ToIntBiFunction.
*
* @param biFunction lambda to capture
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @return serializable ToIntBiFunction
*/
public static ToIntBiFunction toIntBiFunction(ToIntBiFunction biFunction)
{
return biFunction;
}
/**
* Represents a function that accepts two arguments and produces a
* long-valued result. This is the {@code long}-producing primitive
* specialization for {@link BiFunction}.
*
*
This is a functional interface
* whose functional method is {@link #applyAsLong(Object, Object)}.
*
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @see BiFunction
*/
@FunctionalInterface
public static interface ToLongBiFunction
extends java.util.function.ToLongBiFunction, Serializable
{
}
/**
* Capture serializable ToLongBiFunction.
*
* @param biFunction lambda to capture
* @param the type of the first argument to the function
* @param the type of the second argument to the function
*
* @return serializable ToLongBiFunction
*/
public static ToLongBiFunction toLongBiFunction(ToLongBiFunction biFunction)
{
return biFunction;
}
// ---- Predicates ------------------------------------------------------
/**
* Represents a predicate (boolean-valued function) of one argument.
*
*
This is a functional interface
* whose functional method is {@link #test(Object)}.
*
* @param the type of the input to the predicate
*/
@FunctionalInterface
public static interface Predicate
extends java.util.function.Predicate, Serializable
{
/**
* Returns a composed predicate that represents a short-circuiting
* logical AND of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code false}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ANDed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical AND of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default Predicate and(Predicate super T> other)
{
Objects.requireNonNull(other);
return (t) -> test(t) && other.test(t);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default Predicate negate()
{
return (t) -> !test(t);
}
/**
* Returns a composed predicate that represents a short-circuiting
* logical OR of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code true}, then the
* {@code other} predicate is not evaluated.
*
*
Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ORed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical OR of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default Predicate or(Predicate super T> other)
{
Objects.requireNonNull(other);
return (t) -> test(t) || other.test(t);
}
/**
* Returns a predicate that tests if two arguments are equal according
* to {@link Objects#equals(Object, Object)}.
*
* @param the type of arguments to the predicate
* @param targetRef the object reference with which to compare for
* equality, which may be {@code null}
*
* @return a predicate that tests if two arguments are equal according
* to {@link Objects#equals(Object, Object)}
*/
static Predicate isEqual(Object targetRef)
{
return (null == targetRef)
? Objects::isNull
: targetRef::equals;
}
}
/**
* Capture serializable Predicate.
*
* @param predicate lambda to capture
* @param the type of the input to the predicate
*
* @return serializable Predicate
*/
public static Predicate predicate(Predicate predicate)
{
return predicate;
}
/**
* Represents a predicate (boolean-valued function) of two arguments. This
* is the two-arity specialization of {@link Predicate}.
*
*
This is a functional interface
* whose functional method is {@link #test(Object, Object)}.
*
* @param the type of the first argument to the predicate
* @param the type of the second argument the predicate
*
* @see Predicate
*/
@FunctionalInterface
public static interface BiPredicate
extends java.util.function.BiPredicate, Serializable
{
/**
* Returns a composed predicate that represents a short-circuiting
* logical AND of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code false}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ANDed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical AND of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default BiPredicate and(BiPredicate super T, ? super U> other)
{
Objects.requireNonNull(other);
return (T t, U u) -> test(t, u) && other.test(t, u);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default BiPredicate negate()
{
return (T t, U u) -> !test(t, u);
}
/**
* Returns a composed predicate that represents a short-circuiting
* logical OR of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code true}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ORed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical OR of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default BiPredicate or(BiPredicate super T, ? super U> other)
{
Objects.requireNonNull(other);
return (T t, U u) -> test(t, u) || other.test(t, u);
}
}
/**
* Capture serializable BiPredicate.
*
* @param biPredicate lambda to capture
* @param the type of the first argument to the predicate
* @param the type of the second argument the predicate
*
* @return serializable BiPredicate
*/
public static BiPredicate biPredicate(BiPredicate biPredicate)
{
return biPredicate;
}
/**
* Represents a predicate (boolean-valued function) of one {@code
* double}-valued argument. This is the {@code double}-consuming primitive
* type specialization of {@link Predicate}.
*
*
This is a functional interface
* whose functional method is {@link #test(double)}.
*
* @see Predicate
*/
@FunctionalInterface
public static interface DoublePredicate
extends java.util.function.DoublePredicate, Serializable
{
/**
* Returns a composed predicate that represents a short-circuiting
* logical AND of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code false}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ANDed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical AND of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default DoublePredicate and(DoublePredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) && other.test(value);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default DoublePredicate negate()
{
return (value) -> !test(value);
}
/**
* Returns a composed predicate that represents a short-circuiting
* logical OR of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code true}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ORed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical OR of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default DoublePredicate or(DoublePredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) || other.test(value);
}
}
/**
* Capture serializable DoublePredicate.
*
* @param predicate lambda to capture
*
* @return serializable DoublePredicate
*/
public static DoublePredicate doublePredicate(DoublePredicate predicate)
{
return predicate;
}
/**
* Represents a predicate (boolean-valued function) of one {@code
* int}-valued argument. This is the {@code int}-consuming primitive type
* specialization of {@link Predicate}.
*
*
This is a functional interface
* whose functional method is {@link #test(int)}.
*
* @see Predicate
*/
@FunctionalInterface
public static interface IntPredicate
extends java.util.function.IntPredicate, Serializable
{
/**
* Returns a composed predicate that represents a short-circuiting
* logical AND of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code false}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ANDed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical AND of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default IntPredicate and(IntPredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) && other.test(value);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default IntPredicate negate()
{
return (value) -> !test(value);
}
/**
* Returns a composed predicate that represents a short-circuiting
* logical OR of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code true}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ORed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical OR of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default IntPredicate or(IntPredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) || other.test(value);
}
}
/**
* Capture serializable IntPredicate.
*
* @param predicate lambda to capture
*
* @return serializable IntPredicate
*/
public static IntPredicate intPredicate(IntPredicate predicate)
{
return predicate;
}
/**
* Represents a predicate (boolean-valued function) of one {@code
* long}-valued argument. This is the {@code long}-consuming primitive type
* specialization of {@link Predicate}.
*
*
This is a functional interface
* whose functional method is {@link #test(long)}.
*
* @see Predicate
*/
@FunctionalInterface
public static interface LongPredicate
extends java.util.function.LongPredicate, Serializable
{
/**
* Returns a composed predicate that represents a short-circuiting
* logical AND of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code false}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ANDed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical AND of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default LongPredicate and(LongPredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) && other.test(value);
}
/**
* Returns a predicate that represents the logical negation of this
* predicate.
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default LongPredicate negate()
{
return (value) -> !test(value);
}
/**
* Returns a composed predicate that represents a short-circuiting
* logical OR of this predicate and another. When evaluating the
* composed predicate, if this predicate is {@code true}, then the
* {@code other} predicate is not evaluated.
*
* Any exceptions thrown during evaluation of either predicate are
* relayed to the caller; if evaluation of this predicate throws an
* exception, the {@code other} predicate will not be evaluated.
*
* @param other a predicate that will be logically-ORed with this
* predicate
*
* @return a composed predicate that represents the short-circuiting
* logical OR of this predicate and the {@code other} predicate
*
* @throws NullPointerException if other is null
*/
default LongPredicate or(LongPredicate other)
{
Objects.requireNonNull(other);
return (value) -> test(value) || other.test(value);
}
}
/**
* Capture serializable LongPredicate.
*
* @param predicate lambda to capture
*
* @return serializable LongPredicate
*/
public static LongPredicate longPredicate(LongPredicate predicate)
{
return predicate;
}
// ---- Suppliers -------------------------------------------------------
/**
* Represents a supplier of results.
*
* There is no requirement that a new or distinct result be returned each
* time the supplier is invoked.
*
* This is a functional interface
* whose functional method is {@link #get()}.
*
* @param the type of results supplied by this supplier
*/
@FunctionalInterface
public static interface Supplier
extends java.util.function.Supplier, Serializable
{
}
/**
* Capture serializable Supplier.
*
* @param supplier lambda to capture
* @param the type of results supplied by this supplier
*
* @return serializable Supplier
*/
public static Supplier supplier(Supplier supplier)
{
return supplier;
}
/**
* Represents a supplier of {@code boolean}-valued results. This is the
* {@code boolean}-producing primitive specialization of {@link Supplier}.
*
*
There is no requirement that a new or distinct result be returned each
* time the supplier is invoked.
*
*
This is a functional interface
* whose functional method is {@link #getAsBoolean()}.
*
* @see Supplier
*/
@FunctionalInterface
public static interface BooleanSupplier
extends java.util.function.BooleanSupplier, Serializable
{
}
/**
* Capture serializable BooleanSupplier.
*
* @param supplier lambda to capture
*
* @return serializable BooleanSupplier
*/
public static BooleanSupplier booleanSupplier(BooleanSupplier supplier)
{
return supplier;
}
/**
* Represents a supplier of {@code double}-valued results. This is the
* {@code double}-producing primitive specialization of {@link Supplier}.
*
*
There is no requirement that a distinct result be returned each time
* the supplier is invoked.
*
*
This is a functional interface
* whose functional method is {@link #getAsDouble()}.
*
* @see Supplier
*/
@FunctionalInterface
public static interface DoubleSupplier
extends java.util.function.DoubleSupplier, Serializable
{
}
/**
* Capture serializable DoubleSupplier.
*
* @param supplier lambda to capture
*
* @return serializable DoubleSupplier
*/
public static DoubleSupplier doubleSupplier(DoubleSupplier supplier)
{
return supplier;
}
/**
* Represents a supplier of {@code int}-valued results. This is the {@code
* int}-producing primitive specialization of {@link Supplier}.
*
*
There is no requirement that a distinct result be returned each time
* the supplier is invoked.
*
*
This is a functional interface
* whose functional method is {@link #getAsInt()}.
*
* @see Supplier
*/
@FunctionalInterface
public static interface IntSupplier
extends java.util.function.IntSupplier, Serializable
{
}
/**
* Capture serializable IntSupplier.
*
* @param supplier lambda to capture
*
* @return serializable IntSupplier
*/
public static IntSupplier intSupplier(IntSupplier supplier)
{
return supplier;
}
/**
* Represents a supplier of {@code long}-valued results. This is the {@code
* long}-producing primitive specialization of {@link Supplier}.
*
*
There is no requirement that a distinct result be returned each time
* the supplier is invoked.
*
*
This is a functional interface
* whose functional method is {@link #getAsLong()}.
*
* @see Supplier
*/
@FunctionalInterface
public static interface LongSupplier
extends java.util.function.LongSupplier, Serializable
{
}
/**
* Capture serializable LongSupplier.
*
* @param supplier lambda to capture
*
* @return serializable LongSupplier
*/
public static LongSupplier longSupplier(LongSupplier supplier)
{
return supplier;
}
// ---- Binary Operators ------------------------------------------------
/**
* Represents an operation upon two operands of the same type, producing a
* result of the same type as the operands. This is a specialization of
* {@link BiFunction} for the case where the operands and the result are all
* of the same type.
*
*
This is a functional interface
* whose functional method is {@link #apply(Object, Object)}.
*
* @param the type of the operands and result of the operator
*
* @see BiFunction
* @see UnaryOperator
*/
@FunctionalInterface
public static interface BinaryOperator
extends BiFunction,
java.util.function.BinaryOperator,
Serializable
{
/**
* Returns a {@link BinaryOperator} which returns the lesser of two
* elements according to the specified {@code Comparable} value.
*
* @param the type of the input arguments of the comparator
* @param comparable a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the greater of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static > BinaryOperator minBy(ValueExtractor super T, ? extends E> comparable)
{
return minBy(comparator(comparable));
}
/**
* Returns a {@link BinaryOperator} which returns the lesser of two
* elements according to the specified {@code Comparator}.
*
* @param the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the lesser of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static BinaryOperator minBy(Comparator super T> comparator)
{
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
}
/**
* Returns a {@link BinaryOperator} which returns the lesser of two
* elements according to the specified {@code Comparator}.
*
* @param the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the lesser of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static BinaryOperator minBy(java.util.Comparator super T> comparator)
{
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) <= 0 ? a : b;
}
/**
* Returns a {@link BinaryOperator} which returns the greater of two
* elements according to the specified {@code Comparable} value.
*
* @param the type of the input arguments of the comparator
* @param comparable a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the greater of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static > BinaryOperator maxBy(ValueExtractor super T, ? extends E> comparable)
{
return maxBy(comparator(comparable));
}
/**
* Returns a {@link BinaryOperator} which returns the greater of two
* elements according to the specified {@code Comparator}.
*
* @param the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the greater of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static BinaryOperator maxBy(Comparator super T> comparator)
{
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
}
/**
* Returns a {@link BinaryOperator} which returns the greater of two
* elements according to the specified {@code Comparator}.
*
* @param the type of the input arguments of the comparator
* @param comparator a {@code Comparator} for comparing the two values
*
* @return a {@code BinaryOperator} which returns the greater of its
* operands, according to the supplied {@code Comparator}
*
* @throws NullPointerException if the argument is null
*/
public static BinaryOperator maxBy(java.util.Comparator super T> comparator)
{
Objects.requireNonNull(comparator);
return (a, b) -> comparator.compare(a, b) >= 0 ? a : b;
}
/**
* {@code BinaryOperator