InputType - The input value for the evaluator and its map.OutputType - The output type for the evaluator and its map.@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>
| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<InputType,OutputType> |
valueMap
The map to use to map input values to output values.
|
| Constructor and Description |
|---|
ValueMapper()
Creates a new
ValueMapper. |
ValueMapper(java.util.Map<InputType,OutputType> valueMap)
Creates a new
ValueMapper with the given map. |
| Modifier and Type | Method and Description |
|---|---|
ValueMapper<InputType,OutputType> |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
static <InputType,OutputType> |
create(java.util.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.
|
java.util.Map<InputType,OutputType> |
getValueMap()
Gets the map of input values to output values.
|
void |
setValueMap(java.util.Map<InputType,OutputType> valueMap)
Sets the map of input values to output values.
|
protected java.util.Map<InputType,OutputType> valueMap
public ValueMapper()
ValueMapper. It creates an empty HashMap
for the value map.public ValueMapper(java.util.Map<InputType,OutputType> valueMap)
ValueMapper with the given map.valueMap - The map to use.public ValueMapper<InputType,OutputType> clone()
AbstractCloneableSerializableObject 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 CloneableSerializableclone in class AbstractCloneableSerializablepublic OutputType evaluate(InputType input)
Evaluatorevaluate in interface Evaluator<InputType,OutputType>input - The input to evaluate.public java.util.Map<InputType,OutputType> getValueMap()
public void setValueMap(java.util.Map<InputType,OutputType> valueMap)
valueMap - The value map.public static <InputType,OutputType> ValueMapper<InputType,OutputType> create(java.util.Map<InputType,OutputType> valueMap)
InputType - The input value for the evaluator and its map.OutputType - The output type for the evaluator and its map.valueMap - The value map.ValueMapper that uses the given map.