Package wt.util
Class Pair<T1,T2>
java.lang.Object
wt.util.Pair<T1,T2>
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Pair.UnorderedPair,WTPair
Aggregates an ordered pair of objects and handles them as a unique combination.
Two Pair objects will test equal if their component objects test equal.
A Pair's hash code is a combination of its component object hash codes,
which allows them to be added to collections and used as map keys.
Supported API: true
Extendable: false
Supported API: true
Extendable: false
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classAggregates an unordered pair of objects and handles them as a unique combination. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanPairs are equal if their two component objects are equal.static CollectiongetAllObjs(Collection pairs, Collection objs, boolean getFirst, boolean getSecond) Populate collection of all first and/or second objects from a collection of Pairs.getObj1()Get pair's first object.getObj2()Get pair's second object;
Supported API: truebooleanReturn true if first object is null.booleanReturn true if second object is null.voidSet pair's first object.voidSet pair's second object.voidSet pair's objects.toString()Returns a string representation of the pair: "[{obj1.toString()}{obj2.toString()}]".
-
Constructor Details
-
Pair
public Pair()Construct a default Pair with null component objects.
Supported API: true -
Pair
Construct a Pair object from components.
Supported API: true- Parameters:
obj1- Object 1.obj2- Object 2.
-
Pair
Construct a Pair copy. The pair's individual objects are referenced in the copy, not duplicated.
Supported API: true- Parameters:
pair- Pair object to be copied.
-
-
Method Details
-
getObj1
Get pair's first object.
Supported API: true -
getObj2
Get pair's second object;
Supported API: true -
setObj1
Set pair's first object.
Supported API: true- Parameters:
obj1- New first object.
-
setObj2
Set pair's second object.
Supported API: true- Parameters:
obj2- New second object.
-
setObjs
Set pair's objects.
Supported API: true- Parameters:
obj1- New first object.obj2- New second object.
-
isObj1Null
public boolean isObj1Null()Return true if first object is null.
Supported API: true -
isObj2Null
public boolean isObj2Null()Return true if second object is null.
Supported API: true -
getAllObjs
public static Collection getAllObjs(Collection pairs, Collection objs, boolean getFirst, boolean getSecond) Populate collection of all first and/or second objects from a collection of Pairs.
Supported API: true- Parameters:
pairs- Collection of Pair objects.objs- Collection populated with first and/or second objects (Set will be created if null).getFirst- True to get first objects.getSecond- True to get second objects.- Returns:
- The objs collection that was passed in (or created) with the Pair's objects added. Will contain null entries if one or more Pair objects had null component objects.
-
equals
Pairs are equal if their two component objects are equal. Component objects are compared using their equals() method.
Supported API: true -
toString
Returns a string representation of the pair: "[{obj1.toString()}{obj2.toString()}]".
Supported API: true
-