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

public class Pair<T1,T2> extends Object implements Serializable
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
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Aggregates an unordered pair of objects and handles them as a unique combination.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Construct a default Pair with null component objects.
    Pair(T1 obj1, T2 obj2)
    Construct a Pair object from components.
    Pair(Pair<T1,T2> pair)
    Construct a Pair copy.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Pairs are equal if their two component objects are equal.
    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.
    Get pair's first object.
    Get pair's second object;

    Supported API: true
    boolean
    Return true if first object is null.
    boolean
    Return true if second object is null.
    void
    setObj1(T1 obj1)
    Set pair's first object.
    void
    setObj2(T2 obj2)
    Set pair's second object.
    void
    setObjs(T1 obj1, T2 obj2)
    Set pair's objects.
    Returns a string representation of the pair: "[{obj1.toString()}{obj2.toString()}]".

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Pair

      public Pair()
      Construct a default Pair with null component objects.

      Supported API: true
    • Pair

      public Pair(T1 obj1, T2 obj2)
      Construct a Pair object from components.

      Supported API: true
      Parameters:
      obj1 - Object 1.
      obj2 - Object 2.
    • Pair

      public Pair(Pair<T1,T2> 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

      public T1 getObj1()
      Get pair's first object.

      Supported API: true
    • getObj2

      public T2 getObj2()
      Get pair's second object;

      Supported API: true
    • setObj1

      public void setObj1(T1 obj1)
      Set pair's first object.

      Supported API: true
      Parameters:
      obj1 - New first object.
    • setObj2

      public void setObj2(T2 obj2)
      Set pair's second object.

      Supported API: true
      Parameters:
      obj2 - New second object.
    • setObjs

      public void setObjs(T1 obj1, T2 obj2)
      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

      public boolean equals(Object obj)
      Pairs are equal if their two component objects are equal. Component objects are compared using their equals() method.

      Supported API: true
      Overrides:
      equals in class Object
      See Also:
    • toString

      public String toString()
      Returns a string representation of the pair: "[{obj1.toString()}{obj2.toString()}]".

      Supported API: true
      Overrides:
      toString in class Object