com.google.template.soy.internal.base
Class Pair<A,B>

java.lang.Object
  extended by com.google.template.soy.internal.base.Pair<A,B>

public class Pair<A,B>
extends Object

An immutable, semantic-free ordered pair of nullable values. These can be accessed using the getFirst() and getSecond() methods. Equality and hashing are defined in the natural way.

This type is devoid of semantics, best used for simple mechanical aggregations of unrelated values in implementation code. Avoid using it in your APIs, preferring an explicit type that conveys the exact semantics of the data. For example, instead of:

Pair<T, T> findMinAndMax(List<T> list) {...} ... use: Range<T> findRange(List<T> list) {...} This usually involves creating a new custom value-object type. This is difficult to do "by hand" in Java, but avoid the temptation to extend Pair to accomplish this; consider using the utilities com.google.common.labs.misc.ComparisonKeys or com.google.common.labs.misc.ValueType to help you with this instead.


Field Summary
 A first
          The first element of the pair; see also getFirst().
 B second
          The second element of the pair; see also getSecond().
 
Constructor Summary
Pair(A first, B second)
          Constructor.
 
Method Summary
 boolean equals(Object object)
           
 A getFirst()
          Returns the first element of this pair; see also first.
 B getSecond()
          Returns the second element of this pair; see also second.
 int hashCode()
           
static
<A,B> Pair<A,B>
of(A first, B second)
          Creates a new pair containing the given elements in order.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

first

public final A first
The first element of the pair; see also getFirst().


second

public final B second
The second element of the pair; see also getSecond().

Constructor Detail

Pair

public Pair(@Nullable
            A first,
            @Nullable
            B second)
Constructor. It is usually easier to call of(A, B).

Method Detail

of

public static <A,B> Pair<A,B> of(@Nullable
                                 A first,
                                 @Nullable
                                 B second)
Creates a new pair containing the given elements in order.


getFirst

public A getFirst()
Returns the first element of this pair; see also first.


getSecond

public B getSecond()
Returns the second element of this pair; see also second.


equals

public boolean equals(@Nullable
                      Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()

This implementation returns a string in the form (first, second), where first and second are the String representations of the first and second elements of this pair, as given by String.valueOf(Object). Subclasses are free to override this behavior.

Overrides:
toString in class Object