gov.sandia.cognition.util
Class DefaultPair<FirstType,SecondType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.DefaultPair<FirstType,SecondType>
Type Parameters:
FirstType - Type of the first object in the pair.
SecondType - Type of the second object in the pair.
All Implemented Interfaces:
CloneableSerializable, Pair<FirstType,SecondType>, Serializable, Cloneable
Direct Known Subclasses:
CompositeEvaluatorPair, DefaultWeightedPair, SumSquaredErrorCostFunction.GradientPartialSSE

@CodeReviews(reviews={@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>

The DefaultPair class implements a simple structure for a pair of two objects, potentially of different types.

Since:
2.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  FirstType first
          The first object.
protected  SecondType second
          The second object.
 
Constructor Summary
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.
 
Method Summary
 DefaultPair<FirstType,SecondType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
static
<FirstType,SecondType>
DefaultPair<FirstType,SecondType>
create()
          Creates a new, empty DefaultPair with both values being null.
static
<FirstType,SecondType>
DefaultPair<FirstType,SecondType>
create(FirstType first, SecondType second)
          Creates a new DefaultPair from the given values.
 boolean equals(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>
ArrayList<DefaultPair<FirstType,SecondType>>
mergeCollections(Collection<FirstType> firsts, 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.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

first

protected FirstType first
The first object.


second

protected SecondType second
The second object.

Constructor Detail

DefaultPair

public DefaultPair()
Creates a new instance of DefaultPair with no members.


DefaultPair

public DefaultPair(FirstType first,
                   SecondType second)
Creates a new instance of DefaultPair.

Parameters:
first - The first object.
second - The second object.

DefaultPair

public DefaultPair(Pair<? extends FirstType,? extends SecondType> other)
Copy constructor.

Parameters:
other - Pair to copy.
Method Detail

clone

public DefaultPair<FirstType,SecondType> clone()
Description copied from class: AbstractCloneableSerializable
This makes public the clone method on the 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.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A clone of this object.

equals

public boolean equals(Object other)
Overrides:
equals in class Object

equals

public boolean equals(Pair<FirstType,SecondType> other)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

create

public static <FirstType,SecondType> DefaultPair<FirstType,SecondType> create()
Creates a new, empty DefaultPair with both values being null.

Type Parameters:
FirstType - Type of the first object in the pair.
SecondType - Type of the second object in the pair.
Returns:
A new, empty DefaultPair.

create

public static <FirstType,SecondType> DefaultPair<FirstType,SecondType> create(FirstType first,
                                                                              SecondType second)
Creates a new DefaultPair from the given values.

Type Parameters:
FirstType - Type of the first object in the pair.
SecondType - Type of the second object in the pair.
Parameters:
first - The first value.
second - The second value.
Returns:
A new DefaultPair containing the two values.

getFirst

public FirstType getFirst()
Gets the first object.

Specified by:
getFirst in interface Pair<FirstType,SecondType>
Returns:
The first object.

getSecond

public SecondType getSecond()
Gets the second object.

Specified by:
getSecond in interface Pair<FirstType,SecondType>
Returns:
The second object.

setFirst

public void setFirst(FirstType first)
Sets the first object.

Parameters:
first - The new value for the first object.

setSecond

public void setSecond(SecondType second)
Sets the second object.

Parameters:
second - The new value for the second object.

mergeCollections

public static <FirstType,SecondType> ArrayList<DefaultPair<FirstType,SecondType>> mergeCollections(Collection<FirstType> firsts,
                                                                                                   Collection<SecondType> seconds)
Takes two collections of data of the same size and creates a new single ArrayList<DefaultPair> out of their elements.

Type Parameters:
FirstType - The type of the first element.
SecondType - The type of the second element.
Parameters:
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
Returns:
A new array list of pairs of the same time as the first and second collections.