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

com.landawn.abacus.util.NoCachingNoUpdating Maven / Gradle / Ivy

Go to download

A general programming library in Java/Android. It's easy to learn and simple to use with concise and powerful APIs.

There is a newer version: 5.3.16
Show newest version
/*
 * Copyright (C) 2019 HaiYang Li
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

package com.landawn.abacus.util;

import java.util.AbstractMap;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.landawn.abacus.annotation.Beta;
import com.landawn.abacus.annotation.SequentialOnly;
import com.landawn.abacus.annotation.Stateful;
import com.landawn.abacus.annotation.SuppressFBWarnings;
import com.landawn.abacus.util.function.IntFunction;

/**
 * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}.
 *
 * @since 1.3
 *
 * @author Haiyang Li
 */
@Beta
@SequentialOnly
@Stateful
public interface NoCachingNoUpdating {

    /**
     * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}.
     * 
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. * * @param */ @Beta @SequentialOnly @Stateful @SuppressFBWarnings("CN_IDIOM_NO_SUPER_CALL") public static class DisposableArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final T[] a; /** * Instantiates a new disposable array. * * @param a */ protected DisposableArray(final T[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableArray create(final Class componentType, final int len) { return new DisposableArray<>(N.newArray(componentType, len)); } /** * * @param * @param a * @return */ public static DisposableArray wrap(final T[] a) { return new DisposableArray<>(a); } /** * * @param index * @return */ public T get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @param * @param target * @return */ public A[] toArray(A[] target) { if (target.length < length()) { target = N.newArray(target.getClass().getComponentType(), length()); } N.copy(this.a, 0, target, 0, length()); return target; } /** * * @return */ @Override public T[] clone() { return N.clone(a); } /** * * @return */ public List toList() { return N.toList(clone()); } /** * * @return */ public Set toSet() { return N.toSet(a); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); result.addAll(toList()); return result; } /** * * @param action */ public void forEach(final Throwables.Consumer action) throws E { for (T e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @param delimiter * @param prefix * @param suffix * @return */ public String join(String delimiter, String prefix, String suffix) { return StringUtil.join(a, delimiter, prefix, suffix); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected T[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableObjArray extends DisposableArray { /** * Instantiates a new disposable obj array. * * @param a */ protected DisposableObjArray(Object[] a) { super(a); } public static DisposableObjArray create(final int len) { return new DisposableObjArray(new Object[len]); } /** * * @param * @param componentType * @param len * @return * @throws UnsupportedOperationException * @deprecated throw UnsupportedOperation */ @Deprecated public static DisposableArray create(final Class componentType, final int len) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } /** * * @param a * @return */ public static DisposableObjArray wrap(final Object[] a) { return new DisposableObjArray(a); } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableBooleanArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final boolean[] a; /** * Instantiates a new disposable boolean array. * * @param a */ protected DisposableBooleanArray(final boolean[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableBooleanArray create(final int len) { return new DisposableBooleanArray(new boolean[len]); } /** * * @param a * @return */ public static DisposableBooleanArray wrap(final boolean[] a) { return new DisposableBooleanArray(a); } /** * * @param index * @return */ public boolean get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public boolean[] clone() { return N.clone(a); } /** * * @return */ public Boolean[] box() { return Array.box(a); } /** * * @return */ public BooleanList toList() { return BooleanList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (boolean e : a) { result.add(e); } return result; } /** * * @param action */ public void forEach(final Throwables.BooleanConsumer action) throws E { for (boolean e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected boolean[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableCharArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final char[] a; /** * Instantiates a new disposable char array. * * @param a */ protected DisposableCharArray(final char[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableCharArray create(final int len) { return new DisposableCharArray(new char[len]); } /** * * @param a * @return */ public static DisposableCharArray wrap(final char[] a) { return new DisposableCharArray(a); } /** * * @param index * @return */ public char get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public char[] clone() { return N.clone(a); } /** * * @return */ public Character[] box() { return Array.box(a); } /** * * @return */ public CharList toList() { return CharList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (char e : a) { result.add(e); } return result; } /** * * @return */ public int sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public char min() { return N.min(a); } /** * * @return */ public char max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.CharConsumer action) throws E { for (char e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected char[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableByteArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final byte[] a; /** * Instantiates a new disposable byte array. * * @param a */ protected DisposableByteArray(final byte[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableByteArray create(final int len) { return new DisposableByteArray(new byte[len]); } /** * * @param a * @return */ public static DisposableByteArray wrap(final byte[] a) { return new DisposableByteArray(a); } /** * * @param index * @return */ public byte get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public byte[] clone() { return N.clone(a); } /** * * @return */ public Byte[] box() { return Array.box(a); } /** * * @return */ public ByteList toList() { return ByteList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (byte e : a) { result.add(e); } return result; } /** * * @return */ public int sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public byte min() { return N.min(a); } /** * * @return */ public byte max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.ByteConsumer action) throws E { for (byte e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected byte[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableShortArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final short[] a; /** * Instantiates a new disposable short array. * * @param a */ protected DisposableShortArray(final short[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableShortArray create(final int len) { return new DisposableShortArray(new short[len]); } /** * * @param a * @return */ public static DisposableShortArray wrap(final short[] a) { return new DisposableShortArray(a); } /** * * @param index * @return */ public short get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public short[] clone() { return N.clone(a); } /** * * @return */ public Short[] box() { return Array.box(a); } /** * * @return */ public ShortList toList() { return ShortList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (short e : a) { result.add(e); } return result; } /** * * @return */ public int sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public short min() { return N.min(a); } /** * * @return */ public short max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.ShortConsumer action) throws E { for (short e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected short[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableIntArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final int[] a; /** * Instantiates a new disposable int array. * * @param a */ protected DisposableIntArray(final int[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableIntArray create(final int len) { return new DisposableIntArray(new int[len]); } /** * * @param a * @return */ public static DisposableIntArray wrap(final int[] a) { return new DisposableIntArray(a); } /** * * @param index * @return */ public int get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public int[] clone() { return N.clone(a); } /** * * @return */ public Integer[] box() { return Array.box(a); } /** * * @return */ public IntList toList() { return IntList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (int e : a) { result.add(e); } return result; } /** * * @return */ public int sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public int min() { return N.min(a); } /** * * @return */ public int max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.IntConsumer action) throws E { for (int e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected int[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableLongArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final long[] a; /** * Instantiates a new disposable long array. * * @param a */ protected DisposableLongArray(final long[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableLongArray create(final int len) { return new DisposableLongArray(new long[len]); } /** * * @param a * @return */ public static DisposableLongArray wrap(final long[] a) { return new DisposableLongArray(a); } /** * * @param index * @return */ public long get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public long[] clone() { return N.clone(a); } /** * * @return */ public Long[] box() { return Array.box(a); } /** * * @return */ public LongList toList() { return LongList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (long e : a) { result.add(e); } return result; } /** * * @return */ public long sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public long min() { return N.min(a); } /** * * @return */ public long max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.LongConsumer action) throws E { for (long e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected long[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableFloatArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final float[] a; /** * Instantiates a new disposable float array. * * @param a */ protected DisposableFloatArray(final float[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableFloatArray create(final int len) { return new DisposableFloatArray(new float[len]); } /** * * @param a * @return */ public static DisposableFloatArray wrap(final float[] a) { return new DisposableFloatArray(a); } /** * * @param index * @return */ public float get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public float[] clone() { return N.clone(a); } /** * * @return */ public Float[] box() { return Array.box(a); } /** * * @return */ public FloatList toList() { return FloatList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (float e : a) { result.add(e); } return result; } /** * * @return */ public float sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public float min() { return N.min(a); } /** * * @return */ public float max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.FloatConsumer action) throws E { for (float e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected float[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the array itself. */ @Beta @SequentialOnly @Stateful public static class DisposableDoubleArray implements NoCachingNoUpdating, Cloneable { /** The a. */ private final double[] a; /** * Instantiates a new disposable double array. * * @param a */ protected DisposableDoubleArray(final double[] a) { N.checkArgNotNull(a, "a"); this.a = a; } public static DisposableDoubleArray create(final int len) { return new DisposableDoubleArray(new double[len]); } /** * * @param a * @return */ public static DisposableDoubleArray wrap(final double[] a) { return new DisposableDoubleArray(a); } /** * * @param index * @return */ public double get(final int index) { return a[index]; } /** * * @return */ public int length() { return a.length; } /** * * @return */ @Override public double[] clone() { return N.clone(a); } /** * * @return */ public Double[] box() { return Array.box(a); } /** * * @return */ public DoubleList toList() { return DoubleList.of(clone()); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(length()); for (double e : a) { result.add(e); } return result; } /** * * @return */ public double sum() { return N.sum(a); } /** * * @return */ public double average() { return N.average(a); } /** * * @return */ public double min() { return N.min(a); } /** * * @return */ public double max() { return N.max(a); } /** * * @param action */ public void forEach(final Throwables.DoubleConsumer action) throws E { for (double e : a) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function func) throws E { return func.apply(a); } /** * * @param action */ public void accept(final Throwables.Consumer action) throws E { action.accept(a); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(a, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(a); } /** * * @return */ protected double[] values() { return a; } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the {@code Queue} itself. * * @param */ @Beta @SequentialOnly @Stateful public static class DisposableDeque implements NoCachingNoUpdating { /** The deque. */ private final Deque deque; /** * Instantiates a new disposable deque. * * @param deque */ protected DisposableDeque(final Deque deque) { N.checkArgNotNull(deque, "deque"); this.deque = deque; } public static DisposableDeque create(final int len) { return new DisposableDeque<>(new ArrayDeque(len)); } /** * * @param * @param deque * @return */ public static DisposableDeque wrap(final Deque deque) { return new DisposableDeque<>(deque); } /** * * @return */ public int size() { return deque.size(); } /** * Gets the first. * * @return */ public T getFirst() { return deque.getFirst(); } /** * Gets the last. * * @return */ public T getLast() { return deque.getLast(); } /** * * @param * @param a * @return */ public A[] toArray(A[] a) { return deque.toArray(a); } /** * * @return */ public List toList() { return new ArrayList<>(deque); } /** * * @return */ public Set toSet() { return new HashSet<>(deque); } /** * * @param * @param supplier * @return */ public > C toCollection(final IntFunction supplier) { final C result = supplier.apply(size()); result.addAll(deque); return result; } /** * * @param action */ public void forEach(final Throwables.Consumer action) throws E { for (T e : deque) { action.accept(e); } } /** * * @param * @param func * @return */ public R apply(final Throwables.Function, R, E> func) throws E { return func.apply(deque); } /** * * @param action */ public void accept(final Throwables.Consumer, E> action) throws E { action.accept(deque); } /** * * @param delimiter * @return */ public String join(String delimiter) { return StringUtil.join(deque, delimiter); } /** * * @return */ @Override public String toString() { return N.toString(deque); } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the {@code Entry} itself. * * @param the key type * @param the value type */ @Beta @SequentialOnly @Stateful public static abstract class DisposableEntry implements Map.Entry, NoCachingNoUpdating { /** * * @param the key type * @param the value type * @param entry * @return */ public static DisposableEntry wrap(final Map.Entry entry) { N.checkArgNotNull(entry, "entry"); return new DisposableEntry<>() { private final Map.Entry e = entry; @Override public K getKey() { return e.getKey(); } @Override public V getValue() { return e.getValue(); } }; } /** * Sets the value. * * @param value * @return * @throws UnsupportedOperationException the unsupported operation exception * @deprecated UnsupportedOperationException */ @Deprecated @Override public V setValue(V value) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } public Map.Entry copy() { return new AbstractMap.SimpleEntry<>(getKey(), getValue()); } public R apply(final Throwables.Function, R, E> func) throws E { return func.apply(this); } public R apply(final Throwables.BiFunction func) throws E { return func.apply(this.getKey(), this.getValue()); } public void accept(final Throwables.Consumer, E> action) throws E { action.accept(this); } public void accept(final Throwables.BiConsumer action) throws E { action.accept(this.getKey(), this.getValue()); } /** * * @return */ @Override public String toString() { return getKey() + "=" + getValue(); } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the {@code Pair} itself. * * @param * @param */ @Beta @SequentialOnly @Stateful public static abstract class DisposablePair implements NoCachingNoUpdating { /** * * @param * @param * @param p * @return */ public static DisposablePair wrap(final Pair p) { N.checkArgNotNull(p, "pair"); return new DisposablePair<>() { private final Pair pair = p; @Override public L left() { return pair.left; } @Override public R right() { return pair.right; } }; } public abstract L left(); public abstract R right(); public Pair copy() { return Pair.of(left(), right()); } public U apply(final Throwables.BiFunction func) throws E { return func.apply(left(), right()); } public void accept(final Throwables.BiConsumer action) throws E { action.accept(left(), right()); } @Override public String toString() { return "[" + N.toString(left()) + ", " + N.toString(right()) + "]"; // return N.toString(left()) + "=" + N.toString(right()); } } /** * One-off Object. No caching/saving in memory, No updating. To cache/save/update the Object, call {@code clone()/copy()}. *
* Depends on context, it should be okay to cache/save the elements from the array, but never save or cache the {@code Tripe} itself. * * @param * @param * @param */ @Beta @SequentialOnly @Stateful public static abstract class DisposableTriple implements NoCachingNoUpdating { /** * * @param * @param * @param * @param p * @return */ public static DisposableTriple wrap(final Triple p) { N.checkArgNotNull(p, "triple"); return new DisposableTriple<>() { private final Triple triple = p; @Override public L left() { return triple.left; } @Override public M middle() { return triple.middle; } @Override public R right() { return triple.right; } }; } public abstract L left(); public abstract M middle(); public abstract R right(); public Triple copy() { return Triple.of(left(), middle(), right()); } public U apply(final Throwables.TriFunction func) throws E { return func.apply(left(), middle(), right()); } public void accept(final Throwables.TriConsumer action) throws E { action.accept(left(), middle(), right()); } @Override public String toString() { return "[" + N.toString(left()) + ", " + N.toString(middle()) + ", " + N.toString(right()) + "]"; } } }