Class Pair<T>

java.lang.Object
edu.uci.ics.jung.graph.util.Pair<T>
All Implemented Interfaces:
Serializable, Iterable<T>, Collection<T>

public final class Pair<T> extends Object implements Collection<T>, Serializable
An implementation of Collection that stores exactly 2 non-null objects and is not mutable. They respect equals and may be used as indices or map keys.

Note that they do not protect from malevolent behavior: if one or another object in the tuple is mutable, then it can be changed with the usual bad effects.

See Also:
  • Field Details

    • first

      private T first
    • second

      private T second
  • Constructor Details

    • Pair

      public Pair(T value1, T value2)
      Creates a Pair from the specified elements.
      Parameters:
      value1 - the first value in the new Pair
      value2 - the second value in the new Pair
      Throws:
      IllegalArgumentException - if either argument is null
    • Pair

      public Pair(Collection<? extends T> values)
      Creates a Pair from the passed Collection. The size of the Collection must be 2.
      Parameters:
      values - the elements of the new Pair
      Throws:
      IllegalArgumentException - if the input collection is null, contains null values, or has != 2 elements.
    • Pair

      public Pair(T[] values)
      Creates a Pair from the passed array. The size of the array must be 2.
      Parameters:
      values - the values to be used to construct this Pair
      Throws:
      IllegalArgumentException - if the input array is null, contains null values, or has != 2 elements.
  • Method Details