public class Pairs extends Object
| Constructor and Description |
|---|
Pairs() |
| Modifier and Type | Method and Description |
|---|---|
static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> |
compare(First firstOfLeft,
Second secondOfLeft,
First firstOfRight,
Second secondOfRight)
compare(a, b, c, d) lexicographically compares the pair
(a, b) with the pair (c, d). |
static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> |
compare(Pair<First,Second> left,
Pair<First,Second> right)
compare(a, b) lexicographically compares the pair
a with the pair b. |
static <F,S> boolean |
equals(Pair<F,S> left,
Object right)
Compares two pairs for equality.
|
static <First,Second> |
from(First first,
Second second)
Create a simple pair from it's first and second component.
|
static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> |
fromComparables(First first,
Second second)
Creates a pair from comparables which is itself
Comparable. |
static <First extends Serializable & Comparable<? super First>,Second extends Serializable & Comparable<? super Second>> |
fromComparableSerializables(First first,
Second second)
Creates a pair from components which are comparable and serializable which
is itself
Comparable and Serializable. |
static <First extends Serializable,Second extends Serializable> |
fromSerializables(First first,
Second second)
Creates a pair from serializables which is itself
Serializable. |
static <F,S> int |
hashCode(Pair<F,S> pair)
Computes the hash code of a pair.
|
static <CommonSuperType,First extends CommonSuperType,Second extends CommonSuperType> |
toArray(Pair<First,Second> pair,
Class<CommonSuperType> commonSuperType)
Transform a pair into an array of the common super type of both components.
|
static <CommonSuperType,First extends CommonSuperType,Second extends CommonSuperType> |
toArray(Pair<First,Second> pair,
CommonSuperType[] target,
int offset)
Write a pair into an array of the common super type of both components.
|
static <K,V,M extends Map<K,V>> |
toMap(Iterable<Pair<K,V>> pairs,
Class<M> mapType)
|
static <K,V,M extends Map<K,V>> |
toMap(Iterable<Pair<K,V>> pairs,
M map)
Adds the pairs from the
Iterable of pairs (k, v) to
the given map. |
public static <First,Second> Pair<First,Second> from(First first, Second second)
first - The first (left) component.second - The second (right) component.public static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> ComparablePair<First,Second> fromComparables(First first, Second second)
Comparable.first - The first (left) component.second - The second (right) component.public static <First extends Serializable,Second extends Serializable> SerializablePair<First,Second> fromSerializables(First first, Second second)
Serializable.first - The first (left) component.second - The second (right) component.public static <First extends Serializable & Comparable<? super First>,Second extends Serializable & Comparable<? super Second>> ComparableSerializablePair<First,Second> fromComparableSerializables(First first, Second second)
Comparable and Serializable.first - The first (left) component.second - The second (right) component.public static <CommonSuperType,First extends CommonSuperType,Second extends CommonSuperType> CommonSuperType[] toArray(Pair<First,Second> pair, Class<CommonSuperType> commonSuperType)
pair - The pair.commonSuperType - A common super type that both First and Second inherit from.public static <CommonSuperType,First extends CommonSuperType,Second extends CommonSuperType> CommonSuperType[] toArray(Pair<First,Second> pair, CommonSuperType[] target, int offset)
pair - The pair.public static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> int compare(Pair<First,Second> left, Pair<First,Second> right)
compare(a, b) lexicographically compares the pair
a with the pair b.
If you create your pairs using
fromComparables(Comparable, Comparable) you have it
Comparable anyhow.left - The left pair.right - The right pair.0 if both pairs are the same, a value less then zero
if the left pair is lexicographically lesser than the right one, or
a value greater than zero.public static <First extends Comparable<? super First>,Second extends Comparable<? super Second>> int compare(First firstOfLeft, Second secondOfLeft, First firstOfRight, Second secondOfRight)
compare(a, b, c, d) lexicographically compares the pair
(a, b) with the pair (c, d).
If you create your pairs using
fromComparables(Comparable, Comparable) you have it
Comparable anyhow.firstOfLeft - The first component of the left pair.secondOfLeft - The second component of the left pair.firstOfRight - The first component of the right pair.secondOfRight - The second component of the right pair.0 if both pairs are the same, a value less then zero
if the left pair is lexicographically lesser than the right one, or
a value greater than zero.public static <K,V,M extends Map<K,V>> M toMap(Iterable<Pair<K,V>> pairs, Class<M> mapType)
pairs - The pairs.mapType - The map type (must have a public default constructor).pairs or
null, if the Map could not be instantiated.public static <K,V,M extends Map<K,V>> M toMap(Iterable<Pair<K,V>> pairs, M map)
Iterable of pairs (k, v) to
the given map.pairs - The key/value pairs.map - The map to add the key/value pairs to.IllegalArgumentException - if the given Map is null.public static <F,S> boolean equals(Pair<F,S> left, Object right)
F - The type of the first component.S - The type of the second component.left - The left pair.right - The right pair.public static <F,S> int hashCode(Pair<F,S> pair)
F - The type of the first component.S - The type of the second component.pair - The pair.Copyright © 2015. All rights reserved.