L
- Type of 'left' object to be heldR
- Type of 'right' object to be heldpublic class Pair<L,R>
extends java.lang.Object
Constructor and Description |
---|
Pair(L left,
R right)
Constructs a new pair, providing the left and right objects to be held.
|
Modifier and Type | Method and Description |
---|---|
static <L> void |
applyToLeft(java.lang.Iterable<? extends Pair<? extends L,?>> source,
java.util.function.Consumer<? super L> consumer)
Goes through source
Iterable and provides all left entries to a given consumer. |
static <R> void |
applyToRight(java.lang.Iterable<? extends Pair<?,? extends R>> source,
java.util.function.Consumer<? super R> consumer)
Goes through source
Iterable and provides all right entries to a given consumer. |
static <T> java.util.List<T> |
collectLeft(java.util.Collection<? extends Pair<? extends T,?>> source)
Collect all the non-null left references into a new List.
|
static <T> java.util.List<T> |
collectRight(java.util.Collection<? extends Pair<?,? extends T>> source)
Collect all the non-null right references into a new List.
|
static boolean |
containsLeft(java.lang.Iterable<? extends Pair<?,?>> search,
java.lang.Object value)
Simple search to see if a collection of pairs contains a given left value.
|
static boolean |
containsRight(java.lang.Iterable<? extends Pair<?,?>> search,
java.lang.Object value)
Simple search to see if a collection of pairs contains a given right value.
|
static <L,R> java.util.List<Pair<L,R>> |
convertMap(java.util.Map<? extends L,? extends R> map)
Convert a map into a list of Pair's where the left side of the pair contains the value and
the right side is the corresponding value.
|
boolean |
equals(java.lang.Object o) |
L |
getLeft()
Getter to get the left reference stored in the pair.
|
static <T> T |
getLeftFromRight(java.lang.Iterable<? extends Pair<? extends T,?>> search,
java.lang.Object right)
Get the left side of a pair by searching for a matching right side.
|
R |
getRight()
Getter to get the right reference stored in the pair.
|
static <T> T |
getRightFromLeft(java.lang.Iterable<? extends Pair<?,? extends T>> search,
java.lang.Object left)
Get the right side of a pair by searching for a matching left side.
|
int |
hashCode() |
static <T> java.lang.Iterable<T> |
iterateLeft(java.lang.Iterable<? extends Pair<? extends T,?>> i)
Convert a
Pair Iterator into an iterator that returns the left items. |
static <T> java.util.Iterator<T> |
iterateLeft(java.util.Iterator<? extends Pair<? extends T,?>> i)
Convert a
Pair Iterator into an iterator that returns the left items. |
static <T> java.lang.Iterable<T> |
iterateRight(java.lang.Iterable<? extends Pair<?,? extends T>> i)
Convert a
Pair Iterator into an iterator that returns the right items. |
static <T> java.util.Iterator<T> |
iterateRight(java.util.Iterator<? extends Pair<?,? extends T>> i)
Convert a
Pair Iterator into an iterator that returns the right items. |
static <L,R> Pair<java.util.List<L>,java.util.List<R>> |
split(java.util.Collection<? extends Pair<? extends L,? extends R>> source)
Split a collection of pair's into a pair of two collections.
|
java.lang.String |
toString() |
static <OL,NL,OR,NR> |
transform(java.util.Collection<? extends Pair<? extends OL,? extends OR>> source,
java.util.function.Function<? super OL,? extends NL> leftTransformer,
java.util.function.Function<? super OR,? extends NR> rightTransformer)
Function to assist in transforming a collection of pairs into a new resulting list.
|
static <OL,NL,R> java.util.List<Pair<NL,R>> |
transformLeft(java.util.Collection<? extends Pair<? extends OL,? extends R>> source,
java.util.function.Function<? super OL,? extends NL> transformer)
Function to assist in transforming the left side of pairs from one form to another.
|
static <L,OR,NR> java.util.List<Pair<L,NR>> |
transformRight(java.util.Collection<? extends Pair<? extends L,? extends OR>> source,
java.util.function.Function<? super OR,? extends NR> transformer)
Function to assist in transforming the right side of pairs from one form to another.
|
public static <OL,NL,R> java.util.List<Pair<NL,R>> transformLeft(java.util.Collection<? extends Pair<? extends OL,? extends R>> source, java.util.function.Function<? super OL,? extends NL> transformer)
If both the left and right sides must be transformed please see
transform(Collection, Function, Function)
.
OL
- Original left side type for input sourceNL
- Transformed left side type for resulting listR
- Type of object held as pair's right referencesource
- Source collection to be iterating overtransformer
- Function to apply to the left side entriespublic static <L,OR,NR> java.util.List<Pair<L,NR>> transformRight(java.util.Collection<? extends Pair<? extends L,? extends OR>> source, java.util.function.Function<? super OR,? extends NR> transformer)
If both the left and right sides must be transformed please see
transform(Collection, Function, Function)
.
OR
- Original right side type for input sourceNR
- Transformed right side type for resulting listL
- Type of object held as pair's left referencesource
- Source collection to be iterating overtransformer
- Function to apply to the right side entriespublic static <OL,NL,OR,NR> java.util.List<Pair<NL,NR>> transform(java.util.Collection<? extends Pair<? extends OL,? extends OR>> source, java.util.function.Function<? super OL,? extends NL> leftTransformer, java.util.function.Function<? super OR,? extends NR> rightTransformer)
OL
- Original left side type for input sourceOR
- Original right side type for input sourceNL
- Transformed left side type for resulting listNR
- Transformed right side type for resulting listsource
- Source collection to be iterating overleftTransformer
- Function to apply to the left side entriesrightTransformer
- Function to apply to the right side entriespublic static <L> void applyToLeft(java.lang.Iterable<? extends Pair<? extends L,?>> source, java.util.function.Consumer<? super L> consumer)
Iterable
and provides all left entries to a given consumer.L
- Type of object held as pair's left referencesource
- Source to iterate throughconsumer
- Consumer to provide left entries topublic static <R> void applyToRight(java.lang.Iterable<? extends Pair<?,? extends R>> source, java.util.function.Consumer<? super R> consumer)
Iterable
and provides all right entries to a given consumer.R
- Type of object held as pair's right referencesource
- Source to iterate throughconsumer
- Consumer to provide right entries topublic static <L,R> java.util.List<Pair<L,R>> convertMap(java.util.Map<? extends L,? extends R> map)
L
- Type of object held as pair's left referenceR
- Type of object held as pair's right referencemap
- Map to source entries frompublic static <L,R> Pair<java.util.List<L>,java.util.List<R>> split(java.util.Collection<? extends Pair<? extends L,? extends R>> source)
getLeft()
and getRight()
separately. Similar to those functions,
this will only collect non-null entries. If there is a null
left or right entry then
the indexes will no longer match each other between the two lists.L
- Type of object held as pair's left referenceR
- Type of object held as pair's right referencesource
- Source collection of pairspublic static <T> java.lang.Iterable<T> iterateLeft(java.lang.Iterable<? extends Pair<? extends T,?>> i)
Pair
Iterator
into an iterator that returns the left items. This
has the minor advantage over collectLeft(Collection)
in that the collection is not
iterated / copied. Allowing for potential concurrent structures to provide their special
iterator behavior through this, as well as avoiding a potential short term memory copy.T
- Type of object held as pair's left referencei
- Iterable to source pairs frompublic static <T> java.util.Iterator<T> iterateLeft(java.util.Iterator<? extends Pair<? extends T,?>> i)
Pair
Iterator
into an iterator that returns the left items. This
has the minor advantage over collectLeft(Collection)
in that the collection is not
iterated / copied. Allowing for potential concurrent structures to provide their special
iterator behavior through this, as well as avoiding a potential short term memory copy.T
- Type of object held as pair's left referencei
- Iterator to source pairs frompublic static <T> java.lang.Iterable<T> iterateRight(java.lang.Iterable<? extends Pair<?,? extends T>> i)
Pair
Iterator
into an iterator that returns the right items. This
has the minor advantage over collectRight(Collection)
in that the collection is not
iterated / copied. Allowing for potential concurrent structures to provide their special
iterator behavior through this, as well as avoiding a potential short term memory copy.T
- Type of object held as pair's right referencei
- Iterable to source pairs frompublic static <T> java.util.Iterator<T> iterateRight(java.util.Iterator<? extends Pair<?,? extends T>> i)
Pair
Iterator
into an iterator that returns the right items. This
has the minor advantage over collectRight(Collection)
in that the collection is not
iterated / copied. Allowing for potential concurrent structures to provide their special
iterator behavior through this, as well as avoiding a potential short term memory copy.T
- Type of object held as pair's right referencei
- Iterator to source pairs frompublic static <T> java.util.List<T> collectLeft(java.util.Collection<? extends Pair<? extends T,?>> source)
T
- Type of object held as pair's left referencesource
- Source collection of pairspublic static <T> java.util.List<T> collectRight(java.util.Collection<? extends Pair<?,? extends T>> source)
T
- Type of object held as pair's right referencesource
- Source collection of pairspublic static boolean containsLeft(java.lang.Iterable<? extends Pair<?,?>> search, java.lang.Object value)
null
elements.search
- Iterable to search overvalue
- Value to be searching for from left elementstrue
if the value is found as a left element from the iterable providedpublic static boolean containsRight(java.lang.Iterable<? extends Pair<?,?>> search, java.lang.Object value)
null
elements.search
- Iterable to search overvalue
- Value to be searching for from right elementstrue
if the value is found as a right element from the iterable providedpublic static <T> T getRightFromLeft(java.lang.Iterable<? extends Pair<?,? extends T>> search, java.lang.Object left)
Object.equals(Object)
), the right side is returned. If no match is found,
null
will be returned. Although the implementer must be aware that since nulls can
be kept kept inside pairs, that does not strictly indicate a match failure.T
- Type of object held as pair's right referencesearch
- Iteratable to search through looking for a matchleft
- Object to be looking searching for as a left referencenull
if none is foundpublic static <T> T getLeftFromRight(java.lang.Iterable<? extends Pair<? extends T,?>> search, java.lang.Object right)
Object.equals(Object)
), the left side is returned. If no match is found,
null
will be returned. Although the implementer must be aware that since nulls can
be kept kept inside pairs, that does not strictly indicate a match failure.T
- Type of object held as pair's left referencesearch
- Iteratable to search through looking for a matchright
- Object to be looking searching for as a left referencenull
if none is foundpublic L getLeft()
public R getRight()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object