gov.sandia.cognition.evaluator
Class ValueMapper<InputType,OutputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.evaluator.ValueMapper<InputType,OutputType>
Type Parameters:
InputType - The input value for the evaluator and its map.
OutputType - The output type for the evaluator and its map.
All Implemented Interfaces:
Evaluator<InputType,OutputType>, CloneableSerializable, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-12-02",
            changesNeeded=false,
            comments={"Removed redundant claim to implement Serializable","Looks good."})
public class ValueMapper<InputType,OutputType>
extends AbstractCloneableSerializable
implements Evaluator<InputType,OutputType>

An evaluator that uses a map to map input values to their appropriate output values. All it does is perform a lookup in the map.

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

Field Summary
protected  Map<InputType,OutputType> valueMap
          The map to use to map input values to output values.
 
Constructor Summary
ValueMapper()
          Creates a new ValueMapper.
ValueMapper(Map<InputType,OutputType> valueMap)
          Creates a new ValueMapper with the given map.
 
Method Summary
 ValueMapper<InputType,OutputType> clone()
          This makes public the clone method on the Object class and removes the exception that it throws.
static
<InputType,OutputType>
ValueMapper<InputType,OutputType>
create(Map<InputType,OutputType> valueMap)
          Creates an evaluator who is backed by the given map.
 OutputType evaluate(InputType input)
          Evaluates the function on the given input and returns the output.
 Map<InputType,OutputType> getValueMap()
          Gets the map of input values to output values.
 void setValueMap(Map<InputType,OutputType> valueMap)
          Sets the map of input values to output values.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

valueMap

protected Map<InputType,OutputType> valueMap
The map to use to map input values to output values.

Constructor Detail

ValueMapper

public ValueMapper()
Creates a new ValueMapper. It creates an empty HashMap for the value map.


ValueMapper

public ValueMapper(Map<InputType,OutputType> valueMap)
Creates a new ValueMapper with the given map.

Parameters:
valueMap - The map to use.
Method Detail

clone

public ValueMapper<InputType,OutputType> 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.

evaluate

public OutputType evaluate(InputType input)
Description copied from interface: Evaluator
Evaluates the function on the given input and returns the output.

Specified by:
evaluate in interface Evaluator<InputType,OutputType>
Parameters:
input - The input to evaluate.
Returns:
The output produced by evaluating the input.

getValueMap

public Map<InputType,OutputType> getValueMap()
Gets the map of input values to output values.

Returns:
The value map.

setValueMap

public void setValueMap(Map<InputType,OutputType> valueMap)
Sets the map of input values to output values.

Parameters:
valueMap - The value map.

create

public static <InputType,OutputType> ValueMapper<InputType,OutputType> create(Map<InputType,OutputType> valueMap)
Creates an evaluator who is backed by the given map.

Type Parameters:
InputType - The input value for the evaluator and its map.
OutputType - The output type for the evaluator and its map.
Parameters:
valueMap - The value map.
Returns:
A new ValueMapper that uses the given map.