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

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.AbstractWeighted
          extended by gov.sandia.cognition.util.DefaultWeightedValue<ValueType>
Type Parameters:
ValueType - Type of the value contained in the class
All Implemented Interfaces:
CloneableSerializable, Weighted, WeightedValue<ValueType>, Serializable, Cloneable
Direct Known Subclasses:
DefaultWeightedValueDiscriminant, SuccessiveOverrelaxation.Entry

@CodeReview(reviewer="Kevin R. Dixon",
            date="2007-11-25",
            changesNeeded=false,
            comments="Looks fine.")
public class DefaultWeightedValue<ValueType>
extends AbstractWeighted
implements WeightedValue<ValueType>

The WeightedValue class implements a simple generic container that holds a value and a weight assigned to the value.

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

Nested Class Summary
static class DefaultWeightedValue.WeightComparator
          A comparator for weighted values based on the weight.
 
Field Summary
protected  ValueType value
          The value.
 
Fields inherited from class gov.sandia.cognition.util.AbstractWeighted
DEFAULT_WEIGHT, weight
 
Constructor Summary
DefaultWeightedValue()
          Creates a new instance of WeightedValue.
DefaultWeightedValue(ValueType value)
          Creates a new instance of WeightedValue with the given value and a default weight of 1.0.
DefaultWeightedValue(ValueType value, double weight)
          Creates a new instance of WeightedValue.
DefaultWeightedValue(WeightedValue<? extends ValueType> other)
          Creates a new shallow copy of a WeightedValue.
 
Method Summary
 DefaultWeightedValue<ValueType> clone()
          Creates a shallow copy of the WeightedValue.
static
<ValueType>
DefaultWeightedValue<ValueType>
create(ValueType value, double weight)
          Convenience method to create a new WeightedValue.
 ValueType getValue()
          Gets the value.
 void setValue(ValueType value)
          Sets the value.
 
Methods inherited from class gov.sandia.cognition.util.AbstractWeighted
getWeight, setWeight
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.util.Weighted
getWeight
 

Field Detail

value

protected ValueType value
The value.

Constructor Detail

DefaultWeightedValue

public DefaultWeightedValue()
Creates a new instance of WeightedValue. The weight defaults to 1.0 and the value defaults to null.


DefaultWeightedValue

public DefaultWeightedValue(ValueType value)
Creates a new instance of WeightedValue with the given value and a default weight of 1.0.

Parameters:
value - The value.

DefaultWeightedValue

public DefaultWeightedValue(ValueType value,
                            double weight)
Creates a new instance of WeightedValue.

Parameters:
weight - The weight.
value - The value.

DefaultWeightedValue

public DefaultWeightedValue(WeightedValue<? extends ValueType> other)
Creates a new shallow copy of a WeightedValue.

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

clone

public DefaultWeightedValue<ValueType> clone()
Creates a shallow copy of the WeightedValue. The weight is copied but the value is not.

Specified by:
clone in interface CloneableSerializable
Overrides:
clone in class AbstractCloneableSerializable
Returns:
A new shallow copy of this WeightedValue.

getValue

public ValueType getValue()
Gets the value.

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

setValue

public void setValue(ValueType value)
Sets the value.

Parameters:
value - The value.

create

public static <ValueType> DefaultWeightedValue<ValueType> create(ValueType value,
                                                                 double weight)
Convenience method to create a new WeightedValue.

Type Parameters:
ValueType - The type of the value.
Parameters:
value - The value.
weight - The weight.
Returns:
A new weighted value with the given value and weight.