P
- First type to be contained in the pair.V
- Second type to be contained in the pair.public class Pair<P,V>
extends java.lang.Object
PairintStr = new Pair (5, "Hello"); intStr.p == 5 intStr.v == "Hello"
Modifier and Type | Field and Description |
---|---|
P |
p
Direct access to the p element is allowed.
|
V |
v
Direct access to the v element is allowed.
|
Constructor and Description |
---|
Pair(P p,
V v)
Constructor that sets the given p and v values.
|
Modifier and Type | Method and Description |
---|---|
static <P extends java.lang.Comparable<P>,V> |
disjointPartition(java.util.List<Pair<P,V>> list)
Given a collection of Pair
it will put all V values that have the same P-value together in a set and return a collection of those sets with their associated P. |
boolean |
equals(java.lang.Object o)
Returns true if both the p and v of the given pair equal p and v in the
current Pair.
|
Pair<V,P> |
flip()
Returns a Pair with the type and the contents of the current Pair flipped
from P to V.
|
static <P,V> java.util.List<Pair<V,P>> |
flipList(java.util.List<Pair<P,V>> list)
Returns a list of pairs with P and V being switched.
|
int |
hashCode() |
static <P> java.lang.Iterable<P> |
iterableP(java.lang.Iterable<? extends Pair<P,?>> iterable)
Given an iterable in Pair
will return an iterable in P. |
static <V> java.lang.Iterable<V> |
iterableV(java.lang.Iterable<? extends Pair<?,V>> iterable)
Given an iterable in Pair
will return an iterable in P. |
static <P> java.util.Iterator<P> |
iteratorP(java.util.Iterator<? extends Pair<P,?>> iterator)
Given an Iterator in Pair
, will return an Iterator in P that proxies all calls to the given iterator. |
static <V> java.util.Iterator<V> |
iteratorV(java.util.Iterator<? extends Pair<?,V>> iterator)
Given an Iterator in Pair
, will return an Iterator in V that proxies all calls to the given iterator. |
static <P extends java.lang.Comparable<P>,V> |
pCompare()
Returns a comparator that compares by p.
|
static <P> java.util.Comparator<? super Pair<P,?>> |
pCompare(java.util.Comparator<P> comp)
Given a comparator for p elements, returns a Comparator for pairs which
uses this given comparator to make the comparison.
|
static <P> java.util.List<P> |
pList(java.util.List<? extends Pair<P,?>> list)
Unzips the given pair list by returning a list of the p values.
|
java.lang.String |
toString()
Debugging Output method using the toString method of P and V.
|
static <V extends java.lang.Comparable<V>> |
vCompare()
Returns a comparator that compares by v.
|
static <V> java.util.Comparator<? super Pair<?,V>> |
vCompare(java.util.Comparator<V> vComp)
Given a comparator for v elements, returns a Comparator for pairs which
uses this given comparator to make the comparison.
|
static <V> java.util.List<V> |
vList(java.util.List<? extends Pair<?,V>> list)
Unzips the given pair by return a list of the v values.
|
static <P,V> java.util.List<Pair<P,V>> |
zip(java.util.List<P> ps,
java.util.List<V> vs)
Takes a list of P and list of V and returns a list of Pair
. |
public P p
public V v
public static <P extends java.lang.Comparable<P>,V> java.util.Comparator<Pair<P,V>> pCompare()
V
- The V type is not important for this method.P
- The P type of the pair needs to be comparable.public static <P> java.util.Comparator<? super Pair<P,?>> pCompare(java.util.Comparator<P> comp)
V
- The V-Type of the Pair.P
- The P-Type of the Pair.comp
- A comparator which will be wrapped so that it can be used to
comparepublic Pair<V,P> flip()
Pair<Integer, String> intString = new Pair<Integer, String>(5, "Hallo"); Pair<String, Integer> strInteger = intString.flip();
public static <P,V> java.util.List<Pair<V,P>> flipList(java.util.List<Pair<P,V>> list)
P
- V
- list
- public static <P extends java.lang.Comparable<P>,V> java.util.List<Pair<P,java.util.Set<V>>> disjointPartition(java.util.List<Pair<P,V>> list)
it will put all V values that have the same P-value together in a set and return a collection of those sets with their associated P. Example:
Collection<Pair<Integer, String>> c = new LinkedList<Pair<Integer, String>>(); c.add(new Pair<Integer, String>(3, "Hallo")); c.add(new Pair<Integer, String>(4, "Bye")); c.add(new Pair<Integer, String>(3, "Adios")); Collection<Pair<Integer, Set<String>>> result = Pair.disjointPartition(c); result == [(3, ["Hallo", "Adios"]), (4, ["Bye"])]
P
- V
- list
- public static <V extends java.lang.Comparable<V>> java.util.Comparator<? super Pair<?,V>> vCompare()
P
- The P type is not important for this method.V
- The V type of the pair needs to be comparable.public static <V> java.util.Comparator<? super Pair<?,V>> vCompare(java.util.Comparator<V> vComp)
P
- The P-Type of the Pair.V
- The V-Type of the Pair.vComp
- A comparator which will be wrapped so that it can be used to
comparepublic static <P,V> java.util.List<Pair<P,V>> zip(java.util.List<P> ps, java.util.List<V> vs)
. If the lengths of the lists differ missing values are padded by null.
P
- V
- ps
- vs
- public static <P> java.util.List<P> pList(java.util.List<? extends Pair<P,?>> list)
P
- V
- list
- public static <V> java.util.List<V> vList(java.util.List<? extends Pair<?,V>> list)
V
- list
- public static <V> java.util.Iterator<V> iteratorV(java.util.Iterator<? extends Pair<?,V>> iterator)
, will return an Iterator in V that proxies all calls to the given iterator.
public static <V> java.lang.Iterable<V> iterableV(java.lang.Iterable<? extends Pair<?,V>> iterable)
will return an iterable in P.
public static <P> java.util.Iterator<P> iteratorP(java.util.Iterator<? extends Pair<P,?>> iterator)
, will return an Iterator in P that proxies all calls to the given iterator.
public static <P> java.lang.Iterable<P> iterableP(java.lang.Iterable<? extends Pair<P,?>> iterable)
will return an iterable in P.
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object