Example usage for org.apache.commons.lang3.tuple Triple of

List of usage examples for org.apache.commons.lang3.tuple Triple of

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Triple of.

Prototype

public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right) 

Source Link

Document

Obtains an immutable triple of from three objects inferring the generic types.

This factory allows the triple to be created using inference to obtain the generic types.

Usage

From source file:at.gridtec.lambda4j.function.tri.obj.BiObjDoubleToDoubleFunction.java

/**
 * Returns a memoized (caching) version of this {@link BiObjDoubleToDoubleFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/*from  www  . j a  v  a  2  s . c  o m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code BiObjDoubleToDoubleFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default BiObjDoubleToDoubleFunction<T, U> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, U, Double>, Double> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (BiObjDoubleToDoubleFunction<T, U> & Memoized) (t, u, value) -> {
            final double returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, u, value),
                        key -> applyAsDouble(key.getLeft(), key.getMiddle(), key.getRight()));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiIntToIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiIntToIntFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/*from w  ww.j av a  2 s  . co  m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiIntToIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiIntToIntFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Integer, Integer>, Integer> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiIntToIntFunction<T, X> & Memoized) (t, value1, value2) -> {
            final int returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiByteToByteFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiByteToByteFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/*from   w  w  w  .j  av a  2 s .c o  m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiByteToByteFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiByteToByteFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Byte, Byte>, Byte> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiByteToByteFunction<T, X> & Memoized) (t, value1, value2) -> {
            final byte returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsByteThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiLongToLongFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiLongToLongFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/* w w  w  . j av a  2s .c  om*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiLongToLongFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiLongToLongFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Long, Long>, Long> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiLongToLongFunction<T, X> & Memoized) (t, value1, value2) -> {
            final long returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsLongThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiCharToCharFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiCharToCharFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/*from   w w w .  jav a 2  s.  co m*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiCharToCharFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiCharToCharFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Character, Character>, Character> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiCharToCharFunction<T, X> & Memoized) (t, value1, value2) -> {
            final char returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsCharThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiBooleanToIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiBooleanToIntFunction}. Whenever it is called,
 * the mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>//from ww w. j a va2 s.co  m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiBooleanToIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiBooleanToIntFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Boolean, Boolean>, Integer> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiBooleanToIntFunction<T, X> & Memoized) (t, value1, value2) -> {
            final int returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiByteToIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiByteToIntFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>// w  w w.  java 2s.  c o  m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiByteToIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiByteToIntFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Byte, Byte>, Integer> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiByteToIntFunction<T, X> & Memoized) (t, value1, value2) -> {
            final int returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiLongToIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiLongToIntFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>// w  w w.  ja va  2  s.  c o m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiLongToIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiLongToIntFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Long, Long>, Integer> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiLongToIntFunction<T, X> & Memoized) (t, value1, value2) -> {
            final int returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiCharToIntFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiCharToIntFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>//  w ww .j  ava  2  s .  co m
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiCharToIntFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiCharToIntFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Character, Character>, Integer> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiCharToIntFunction<T, X> & Memoized) (t, value1, value2) -> {
            final int returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}

From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableObjBiIntToByteFunction.java

/**
 * Returns a memoized (caching) version of this {@link ThrowableObjBiIntToByteFunction}. Whenever it is called, the
 * mapping between the input parameters and the return value is preserved in a cache, making subsequent calls
 * returning the memoized value instead of computing the return value again.
 * <p>/*from  ww  w.  j av  a  2s . c  om*/
 * Unless the function and therefore the used cache will be garbage-collected, it will keep all memoized values
 * forever.
 *
 * @return A memoized (caching) version of this {@code ThrowableObjBiIntToByteFunction}.
 * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the
 * resulting memoized function, as the cache used internally does not permit {@code null} keys or values.
 * @implNote The returned memoized function can be safely used concurrently from multiple threads which makes it
 * thread-safe.
 */
@Nonnull
default ThrowableObjBiIntToByteFunction<T, X> memoized() {
    if (isMemoized()) {
        return this;
    } else {
        final Map<Triple<T, Integer, Integer>, Byte> cache = new ConcurrentHashMap<>();
        final Object lock = new Object();
        return (ThrowableObjBiIntToByteFunction<T, X> & Memoized) (t, value1, value2) -> {
            final byte returnValue;
            synchronized (lock) {
                returnValue = cache.computeIfAbsent(Triple.of(t, value1, value2), ThrowableFunction
                        .of(key -> applyAsByteThrows(key.getLeft(), key.getMiddle(), key.getRight())));
            }
            return returnValue;
        };
    }
}