FirstType
- Type of the first object in the pair.SecondType
- Type of the second object in the pair.@CodeReview(reviewer="Kevin R. Dixon",date="2008-10-02",changesNeeded=false,comments={"Moved previous code reviews to CodeReview annotations.","Otherwise, still looks fine."}) @CodeReview(reviewer="Kevin R. Dixon",date="2007-11-25",changesNeeded=false,comments="Still looks fine.") @CodeReview(reviewer="Kevin R. Dixon",date="2006-07-18",changesNeeded=false,comments="Looks fine.") public class DefaultPair<FirstType,SecondType> extends AbstractCloneableSerializable implements Pair<FirstType,SecondType>
DefaultPair
class implements a simple structure for a pair
of two objects, potentially of different types.Modifier and Type | Field and Description |
---|---|
protected FirstType |
first
The first object.
|
protected SecondType |
second
The second object.
|
Constructor and Description |
---|
DefaultPair()
Creates a new instance of DefaultPair with no members.
|
DefaultPair(FirstType first,
SecondType second)
Creates a new instance of DefaultPair.
|
DefaultPair(Pair<? extends FirstType,? extends SecondType> other)
Copy constructor.
|
Modifier and Type | Method and Description |
---|---|
DefaultPair<FirstType,SecondType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
static <FirstType,SecondType> |
create()
Creates a new, empty
DefaultPair with both values being null. |
static <FirstType,SecondType> |
create(FirstType first,
SecondType second)
Creates a new
DefaultPair from the given values. |
boolean |
equals(java.lang.Object other) |
boolean |
equals(Pair<FirstType,SecondType> other) |
FirstType |
getFirst()
Gets the first object.
|
SecondType |
getSecond()
Gets the second object.
|
int |
hashCode() |
static <FirstType,SecondType> |
mergeCollections(java.util.Collection<FirstType> firsts,
java.util.Collection<SecondType> seconds)
Takes two collections of data of the same size and creates a new single
ArrayList<DefaultPair> out of their elements. |
void |
setFirst(FirstType first)
Sets the first object.
|
void |
setSecond(SecondType second)
Sets the second object.
|
protected FirstType first
protected SecondType second
public DefaultPair()
public DefaultPair(FirstType first, SecondType second)
first
- The first object.second
- The second object.public DefaultPair(Pair<? extends FirstType,? extends SecondType> other)
other
- Pair to copy.public DefaultPair<FirstType,SecondType> clone()
AbstractCloneableSerializable
Object
class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone()
to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil
may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone()
as the basis for your implementation.clone
in interface CloneableSerializable
clone
in class AbstractCloneableSerializable
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public boolean equals(Pair<FirstType,SecondType> other)
public int hashCode()
hashCode
in class java.lang.Object
public static <FirstType,SecondType> DefaultPair<FirstType,SecondType> create()
DefaultPair
with both values being null.FirstType
- Type of the first object in the pair.SecondType
- Type of the second object in the pair.DefaultPair
.public static <FirstType,SecondType> DefaultPair<FirstType,SecondType> create(FirstType first, SecondType second)
DefaultPair
from the given values.FirstType
- Type of the first object in the pair.SecondType
- Type of the second object in the pair.first
- The first value.second
- The second value.public FirstType getFirst()
getFirst
in interface Pair<FirstType,SecondType>
public SecondType getSecond()
getSecond
in interface Pair<FirstType,SecondType>
public void setFirst(FirstType first)
first
- The new value for the first object.public void setSecond(SecondType second)
second
- The new value for the second object.public static <FirstType,SecondType> java.util.ArrayList<DefaultPair<FirstType,SecondType>> mergeCollections(java.util.Collection<FirstType> firsts, java.util.Collection<SecondType> seconds)
ArrayList<DefaultPair>
out of their elements.FirstType
- The type of the first element.SecondType
- The type of the second element.firsts
- A collection of the data to transform into the first
element of the pair. Must have the same size as seconds.seconds
- A collection of the data to transform into the second
element of the pair. Must have the same size as firsts