package bjc.utils.data; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; /** * Holds a pair of values of two different types. * * Is an eager variant of {@link IPair} * * @author ben * * @param * The type of the thing held on the left (first) * @param * The type of the thing held on the right (second) */ public class Pair implements IPair { /** * The left value of the pair */ protected L l; /** * The right value of the pair */ protected R r; /** * Create a new pair that holds two nulls. */ public Pair() { } /** * Create a new pair holding the specified values. * * @param left * The value to hold on the left. * @param right * The value to hold on the right. */ public Pair(L left, R right) { l = left; r = right; } /* * (non-Javadoc) * * @see bjc.utils.data.IPair#apply(java.util.function.Function, * java.util.function.Function) */ @Override public IPair apply(Function lf, Function rf) { return new Pair<>(lf.apply(l), rf.apply(r)); } /* * (non-Javadoc) * * @see bjc.utils.data.IPair#doWith(java.util.function.BiConsumer) */ @Override public void doWith(BiConsumer bc) { bc.accept(l, r); } /* * (non-Javadoc) * * @see bjc.utils.data.IPair#merge(java.util.function.BiFunction) */ @Override public E merge(BiFunction bf) { return bf.apply(l, r); } }