List of usage examples for org.apache.commons.lang3.tuple Triple of
public static <L, M, R> Triple<L, M, R> of(final L left, final M middle, final R right)
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.
From source file:at.gridtec.lambda4j.predicate.tri.TriCharPredicate.java
/** * Returns a memoized (caching) version of this {@link TriCharPredicate}. 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. ja va 2 s . c o m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code TriCharPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default TriCharPredicate memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Character, Character, Character>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (TriCharPredicate & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.TriFloatPredicate.java
/** * Returns a memoized (caching) version of this {@link TriFloatPredicate}. 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 av a 2s . c o m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code TriFloatPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default TriFloatPredicate memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Float, Float, Float>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (TriFloatPredicate & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.TriShortPredicate.java
/** * Returns a memoized (caching) version of this {@link TriShortPredicate}. 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 a v a 2 s . c o m*/ * Unless the predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code TriShortPredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default TriShortPredicate memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Short, Short, Short>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (TriShortPredicate & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjIntToIntFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjIntToIntFunction}. 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 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 ThrowableBiObjIntToIntFunction}. * @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 ThrowableBiObjIntToIntFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Integer>, Integer> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjIntToIntFunction<T, U, X> & Memoized) (t, u, value) -> { final int returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.predicate.tri.TriDoublePredicate.java
/** * Returns a memoized (caching) version of this {@link TriDoublePredicate}. 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 predicate and therefore the used cache will be garbage-collected, it will keep all memoized values * forever. * * @return A memoized (caching) version of this {@code TriDoublePredicate}. * @implSpec This implementation does not allow the input parameters or return value to be {@code null} for the * resulting memoized predicate, as the cache used internally does not permit {@code null} keys or values. * @implNote The returned memoized predicate can be safely used concurrently from multiple threads which makes it * thread-safe. */ @Nonnull default TriDoublePredicate memoized() { if (isMemoized()) { return this; } else { final Map<Triple<Double, Double, Double>, Boolean> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (TriDoublePredicate & Memoized) (value1, value2, value3) -> { final boolean returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(value1, value2, value3), key -> test(key.getLeft(), key.getMiddle(), key.getRight())); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjByteToIntFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjByteToIntFunction}. 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 .ja v 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 ThrowableBiObjByteToIntFunction}. * @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 ThrowableBiObjByteToIntFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Byte>, Integer> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjByteToIntFunction<T, U, X> & Memoized) (t, u, value) -> { final int returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjLongToIntFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjLongToIntFunction}. 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 a va2 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 ThrowableBiObjLongToIntFunction}. * @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 ThrowableBiObjLongToIntFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Long>, Integer> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjLongToIntFunction<T, U, X> & Memoized) (t, u, value) -> { final int returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjCharToIntFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjCharToIntFunction}. 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>/*ww w. jav 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 ThrowableBiObjCharToIntFunction}. * @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 ThrowableBiObjCharToIntFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Character>, Integer> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjCharToIntFunction<T, U, X> & Memoized) (t, u, value) -> { final int returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsIntThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjByteToByteFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjByteToByteFunction}. 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 a v a2s.com*/ * 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 ThrowableBiObjByteToByteFunction}. * @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 ThrowableBiObjByteToByteFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Byte>, Byte> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjByteToByteFunction<T, U, X> & Memoized) (t, u, value) -> { final byte returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsByteThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }
From source file:at.gridtec.lambda4j.function.tri.obj.ThrowableBiObjLongToLongFunction.java
/** * Returns a memoized (caching) version of this {@link ThrowableBiObjLongToLongFunction}. 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 ava2 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 ThrowableBiObjLongToLongFunction}. * @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 ThrowableBiObjLongToLongFunction<T, U, X> memoized() { if (isMemoized()) { return this; } else { final Map<Triple<T, U, Long>, Long> cache = new ConcurrentHashMap<>(); final Object lock = new Object(); return (ThrowableBiObjLongToLongFunction<T, U, X> & Memoized) (t, u, value) -> { final long returnValue; synchronized (lock) { returnValue = cache.computeIfAbsent(Triple.of(t, u, value), ThrowableFunction .of(key -> applyAsLongThrows(key.getLeft(), key.getMiddle(), key.getRight()))); } return returnValue; }; } }