ValueType
- Type of value contained in the class@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>
DefaultNamedValue
class implements a container of a name-value
pair.Modifier and Type | Field and Description |
---|---|
protected ValueType |
value
The value.
|
name
Constructor and Description |
---|
DefaultNamedValue()
Creates a new instance of
DefaultNamedValue . |
DefaultNamedValue(DefaultNamedValue<? extends ValueType> other)
Creates a shallow copy of the given DefaultNamedValue.
|
DefaultNamedValue(java.lang.String name,
ValueType value)
Creates a new instance of DefaultNamedValue from the given name and value.
|
Modifier and Type | Method and Description |
---|---|
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(java.lang.String name,
T value)
Convenience method for creating an new
DefaultNamedValue . |
static <T extends Named> |
createNamedValuesList(java.util.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(java.lang.String name)
Sets the name of this Object.
|
void |
setValue(ValueType value)
Sets the value stored in the name-value pair.
|
getName, toString
protected ValueType value
public DefaultNamedValue()
DefaultNamedValue
. The name and value both
default to null.public DefaultNamedValue(java.lang.String name, ValueType value)
name
- The name.value
- The value.public DefaultNamedValue(DefaultNamedValue<? extends ValueType> other)
other
- The other DefaultNamedValue to shallow copy.public DefaultNamedValue<ValueType> 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 AbstractNamed
public void setName(java.lang.String name)
AbstractNamed
setName
in class AbstractNamed
name
- The new name for the Object.public ValueType getValue()
getValue
in interface NamedValue<ValueType>
public void setValue(ValueType value)
value
- The value.public static <T> DefaultNamedValue<T> create(java.lang.String name, T value)
DefaultNamedValue
.T
- The value type.name
- The name.value
- The value.public static <T extends Named> java.util.ArrayList<DefaultNamedValue<T>> createNamedValuesList(java.util.Collection<T> values)
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.T
- The value type.values
- The values to created a named-value list from.