|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.quick.Pair
Pair constructs an immutable pair object from two
non-null objects that are referred to as A and B.
The methods equals and hashCode are
designed so that two Pair objects whose contents are
equal will be considered equal and will return the same hash code.
| Field Summary | |
private Object |
a
Item A of the pair. |
private Object |
b
Item B of the pair. |
| Constructor Summary | |
Pair(Object[] data)
Constructor that constructs a pair using a non- null array of Object
such that the array has 2 non-null items. |
|
Pair(Object a,
Object b)
Constructor that constructs a pair using two non- null Objects. |
|
| Method Summary | |
boolean |
equals(Object entity)
If the given entity is an instance of Pair and if the
corresponding items in this pair and the given entity are equal,
then returns true; otherwise returns false. |
Object |
getA()
Returns the A object in the pair. |
static Object[] |
getAObjects(Pair[] pairs)
Returns the array of A-objects from this array of pairs. |
Object |
getB()
Returns the B object in the pair. |
static Object[] |
getBObjects(Pair[] pairs)
Returns the array of B-objects from this array of pairs. |
int |
hashCode()
Returns a hash code value for this pair that is computed as the exclusive OR of the hash code values for the two items in the pair. |
static Pair |
makePair(Object[] data)
Factory method that returns a Pair if the data array is
non-null and has exactly two non-null items;
otherwise returns null. |
static Pair |
makePair(Object a,
Object b)
Factory method that returns a Pair if the two objects
are non-null; otherwise returns null. |
Object[] |
toArray()
Returns the contents of the pair as an array of Object
of length 2. |
static Pair[] |
toArray(Object[][] array)
Returns the contents of the given Object[][] array as
a Pair[] array. |
static Object[][] |
toArray(Pair[] pairs)
Returns the contents of the given Pair[] array as an
Object[][] array. |
String |
toString()
Returns the String constructed as:
(astring, bstring),
where astring is the toString for item A
and bstring is the toString for item B. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
private Object a
private Object b
| Constructor Detail |
public Pair(Object a,
Object b)
Constructor that constructs a pair using
two non-null Objects.
a - the A object for the pairb - the B object for the pair
NullPointerException - if either data item is
nullpublic Pair(Object[] data)
Constructor that constructs a pair using
a non-null array of Object
such that the array has 2 non-null items.
data - the array with exactly two non-null items
NullPointerException - if data is null
or if an array item in data is null
IllegalArgumentException - if data does not have length 2| Method Detail |
public Object getA()
public Object getB()
public boolean equals(Object entity)
If the given entity is an instance of Pair and if the
corresponding items in this pair and the given entity are equal,
then returns true; otherwise returns false.
entity - the entity to compare to this pair
public int hashCode()
Returns a hash code value for this pair that is computed as the exclusive OR of the hash code values for the two items in the pair.
public String toString()
Returns the String constructed as:
(astring, bstring),
where astring is the toString for item A
and bstring is the toString for item B.
public Object[] toArray()
Returns the contents of the pair as an array of Object
of length 2.
public static Pair makePair(Object a,
Object b)
Factory method that returns a Pair if the two objects
are non-null; otherwise returns null.
Does not throw any exceptions.
a - the A object for the pairb - the B object for the pairpublic static Pair makePair(Object[] data)
Factory method that returns a Pair if the data array is
non-null and has exactly two non-null items;
otherwise returns null.
Does not throw any exceptions.
data - the data with which to form the pair if possiblePair(Object[])public static Object[][] toArray(Pair[] pairs)
Returns the contents of the given Pair[] array as an
Object[][] array.
pairs - the 1-dimensional pair array
public static Pair[] toArray(Object[][] array)
Returns the contents of the given Object[][] array as
a Pair[] array.
Uses makePair(Object[]) to make the individual items
in the returned Pair[] array. In this way, items in
the original array that cannot make a suitable pair will map to
null.
array - the 2-dimensional object array
public static Object[] getAObjects(Pair[] pairs)
pairs - the 1-dimensional pair array
public static Object[] getBObjects(Pair[] pairs)
pairs - the 1-dimensional pair array
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||