Package org.planit.utils.misc
Class Pair<A,B>
- java.lang.Object
-
- org.planit.utils.misc.Pair<A,B>
-
- Type Parameters:
A
- first object in pairB
- second object in pair
public class Pair<A,B> extends Object
Custom pair class similar to C++. By default we compare based on the first value- Author:
- markr
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
anyIsNotNull()
check if any of the two values is not nullboolean
bothNotNull()
check if both values are not nullstatic <A,B>
Pair<A,B>create(A valueA, B valueB)
Factory methodboolean
equals(Object other)
Compare to another pairA
first()
Get first object in pairObject
getEarliestNonNull()
int
hashCode()
boolean
isExactlyOneNonNull()
B
second()
Get second object in pairString
toString()
Convert to string
-
-
-
Method Detail
-
create
public static <A,B> Pair<A,B> create(A valueA, B valueB)
Factory method- Type Parameters:
A
- type of valueAB
- type of valueB- Parameters:
valueA
- firstvalueB
- second- Returns:
- new pair
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classObject
- Returns:
- hashCode for this entity
- See Also:
Object.hashCode()
-
equals
public boolean equals(Object other)
Compare to another pair- Overrides:
equals
in classObject
- Parameters:
other
- pair being compared to- See Also:
Object.equals(java.lang.Object)
-
toString
public String toString()
Convert to string- Overrides:
toString
in classObject
- See Also:
Object.toString()
-
first
public A first()
Get first object in pair- Returns:
- first object in pair
-
second
public B second()
Get second object in pair- Returns:
- second object in pair
-
anyIsNotNull
public boolean anyIsNotNull()
check if any of the two values is not null- Returns:
- true when one of the entries is not null
-
bothNotNull
public boolean bothNotNull()
check if both values are not null- Returns:
- true when both entries are not null
-
isExactlyOneNonNull
public boolean isExactlyOneNonNull()
- Returns:
- true when exactly one of the two is not null
-
getEarliestNonNull
public Object getEarliestNonNull()
- Returns:
- earliest entry (first before second) that is nonNull, when both are null, null is returned
-
-