gov.sandia.cognition.util
Class DefaultNamedValue<ValueType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.AbstractNamed
          extended by gov.sandia.cognition.util.DefaultNamedValue<ValueType>
Type Parameters:
ValueType - Type of value contained in the class
All Implemented Interfaces:
CloneableSerializable, Named, NamedValue<ValueType>, Serializable, Cloneable

@CodeReviews(reviews={@CodeReview(reviewer="Kevin R. Dixon",date="2008-10-02",changesNeeded=false,comments={"Moved previous code review to CodeReview annotation.","Otherwise, looks fine."}),@CodeReview(reviewer="Kevin R. Dixon",date="2007-11-25",changesNeeded=false,comments="Looks fine.")})
public class DefaultNamedValue<ValueType>
extends AbstractNamed
implements NamedValue<ValueType>

The DefaultNamedValue class implements a container of a name-value pair.

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

Field Summary
protected  ValueType value
          The value.
 
Fields inherited from class gov.sandia.cognition.util.AbstractNamed
name
 
Constructor Summary
DefaultNamedValue()
          Creates a new instance of DefaultNamedValue.
DefaultNamedValue(DefaultNamedValue<? extends ValueType> other)
          Creates a shallow copy of the given DefaultNamedValue.
DefaultNamedValue(String name, ValueType value)
          Creates a new instance of DefaultNamedValue from the given name and value.
 
Method Summary
 DefaultNamedValue<ValueType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
static
<T> DefaultNamedValue<T>
create(String name, T value)
          Convenience method for creating an new DefaultNamedValue.
static
<T extends Named>
ArrayList<DefaultNamedValue<T>>
createNamedValuesList(Collection<T> values)
          Creates a list of named values from a collection of named objects.
 ValueType getValue()
          Gets the value stored in the name-value pair.
 void setName(String name)
          Sets the name of this Object.
 void setValue(ValueType value)
          Sets the value stored in the name-value pair.
 
Methods inherited from class gov.sandia.cognition.util.AbstractNamed
getName, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.util.Named
getName
 

Field Detail

value

protected ValueType value
The value.

Constructor Detail

DefaultNamedValue

public DefaultNamedValue()
Creates a new instance of DefaultNamedValue. The name and value both default to null.


DefaultNamedValue

public DefaultNamedValue(String name,
                         ValueType value)
Creates a new instance of DefaultNamedValue from the given name and value.

Parameters:
name - The name.
value - The value.

DefaultNamedValue

public DefaultNamedValue(DefaultNamedValue<? extends ValueType> other)
Creates a shallow copy of the given DefaultNamedValue.

Parameters:
other - The other DefaultNamedValue to shallow copy.
Method Detail

clone

public DefaultNamedValue<ValueType> 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 AbstractNamed
Returns:
A clone of this object.

setName

public void setName(String name)
Description copied from class: AbstractNamed
Sets the name of this Object.

Overrides:
setName in class AbstractNamed
Parameters:
name - The new name for the Object.

getValue

public ValueType getValue()
Gets the value stored in the name-value pair.

Specified by:
getValue in interface NamedValue<ValueType>
Returns:
The value.

setValue

public void setValue(ValueType value)
Sets the value stored in the name-value pair.

Parameters:
value - The value.

create

public static <T> DefaultNamedValue<T> create(String name,
                                              T value)
Convenience method for creating an new DefaultNamedValue.

Type Parameters:
T - The value type.
Parameters:
name - The name.
value - The value.
Returns:
A new default named value with the given name and value.

createNamedValuesList

public static <T extends Named> ArrayList<DefaultNamedValue<T>> createNamedValuesList(Collection<T> values)
Creates a list of named values from a collection of named objects. This is useful for cases where objects may have a name but that name is not the toString representation of the object but you want to treat it as such, by using DefaultNamedValue. This new list of DefaultNamedValues can then be used to represent the values by their name via toString. This is useful in some GUI applications. Note that this is not meant to be used with existing DefaultNamedValue objects because it will just end up putting another DefaultNamedValue wrapper around it.

Type Parameters:
T - The value type.
Parameters:
values - The values to created a named-value list from.
Returns:
A new list of named-values with the name of the object as the name and the value as the value.