net.aavalla.utils.general
Class Pair<T>
java.lang.Object
net.aavalla.utils.general.Pair<T>
public final class Pair<T>
- extends java.lang.Object
Represents a pair of objects. equals() and hashCode() return the same value
for reversed pair. hashCode() is (lazily) initialized only once, so member
objects should be immutable (or immutated :)). Pair class is itself
immutable. Pair's objects cannot be null.
- Author:
- Lari Natri
Constructor Summary |
Pair(T o1,
T o2)
Constructor. |
Method Summary |
boolean |
equals(java.lang.Object obj)
Returns true if (obj.o1==this.o1 && obj.o2==this.o2) ||
(obj.o1==this.o2 && obj.o2==this.o1). |
int |
hashCode()
Returns same hash for pairs regardless of their order. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
o1
public final T o1
o2
public final T o2
Pair
public Pair(T o1,
T o2)
throws java.lang.NullPointerException
- Constructor.
- Parameters:
o1
- first object to store in the pairo2
- second object to store in the pair
- Throws:
java.lang.NullPointerException
- Thrown if either or both of the objects
is null
equals
public final boolean equals(java.lang.Object obj)
- Returns true if (obj.o1==this.o1 && obj.o2==this.o2) ||
(obj.o1==this.o2 && obj.o2==this.o1).
Uses objects' equals() method for '=='.
- Overrides:
equals
in class java.lang.Object
- Parameters:
obj
- other object to compare to
- Returns:
- true if objects are equal, false otherwise
hashCode
public final int hashCode()
- Returns same hash for pairs regardless of their order. Hash code
is lazily calculated only once when first needed.
- Overrides:
hashCode
in class java.lang.Object
- Returns:
- hash code