gov.sandia.cognition.evaluator
Class CompositeEvaluatorTriple<InputType,FirstIntermediateType,SecondIntermediateType,OutputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.util.DefaultTriple<Evaluator<? super InputType,? extends FirstIntermediateType>,Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType>,Evaluator<? super SecondIntermediateType,? extends OutputType>>
          extended by gov.sandia.cognition.evaluator.CompositeEvaluatorTriple<InputType,FirstIntermediateType,SecondIntermediateType,OutputType>
Type Parameters:
InputType - The input type for the first evaluator. This is also the input type for the composite evaluator.
FirstIntermediateType - The output type of the first evaluator and the input type of the second evaluator.
SecondIntermediateType - The output type of the second evaluator and the input type of the third evaluator.
OutputType - The output type of the third evaluator. This is also the output type of the composite evaluator.
All Implemented Interfaces:
Evaluator<InputType,OutputType>, CloneableSerializable, Triple<Evaluator<? super InputType,? extends FirstIntermediateType>,Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType>,Evaluator<? super SecondIntermediateType,? extends OutputType>>, Serializable, Cloneable

@CodeReview(reviewer="Kevin R. Dixon",
            date="2008-12-02",
            changesNeeded=false,
            comments="Please see my diatribe in CompositeEvaluatorPair")
public class CompositeEvaluatorTriple<InputType,FirstIntermediateType,SecondIntermediateType,OutputType>
extends DefaultTriple<Evaluator<? super InputType,? extends FirstIntermediateType>,Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType>,Evaluator<? super SecondIntermediateType,? extends OutputType>>
implements Evaluator<InputType,OutputType>, Serializable

Implements a composition of three evaluators. The input is passed to the first evaluator, then the output of the first is passed to the second, then the output of the second is passed to the third, and the output of the third is returned. If the first evaluator is f1, the second is f2, the third is f3, and the input is x, the composition is f3(f2(f1(x)). It is useful for adapting both the input and the output of an evaluator to be turned into different types. To follow that pattern, the first evaluator would convert the input type, the second would do the actual evaluation, and the third would convert the output type.

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

Field Summary
 
Fields inherited from class gov.sandia.cognition.util.DefaultTriple
first, second, third
 
Constructor Summary
CompositeEvaluatorTriple()
          Creates a new CompositeEvalutorTriple.
CompositeEvaluatorTriple(Evaluator<? super InputType,? extends FirstIntermediateType> first, Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType> second, Evaluator<? super SecondIntermediateType,? extends OutputType> third)
          Creates a new CompositeEvaluatorTriple from the three given evaluators.
 
Method Summary
static
<InputType,FirstIntermediateType,SecondIntermediateType,OutputType>
CompositeEvaluatorTriple<InputType,FirstIntermediateType,SecondIntermediateType,OutputType>
create(Evaluator<? super InputType,? extends FirstIntermediateType> first, Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType> second, Evaluator<? super SecondIntermediateType,? extends OutputType> third)
          A convenience method for creating composite evaluators.
 OutputType evaluate(InputType input)
          Evaluates the function on the given input and returns the output.
 
Methods inherited from class gov.sandia.cognition.util.DefaultTriple
clone, getFirst, getSecond, getThird, mergeCollections, setFirst, setSecond, setThird
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompositeEvaluatorTriple

public CompositeEvaluatorTriple()
Creates a new CompositeEvalutorTriple. The three internal evaluators are initialized to null.


CompositeEvaluatorTriple

public CompositeEvaluatorTriple(Evaluator<? super InputType,? extends FirstIntermediateType> first,
                                Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType> second,
                                Evaluator<? super SecondIntermediateType,? extends OutputType> third)
Creates a new CompositeEvaluatorTriple from the three given evaluators.

Parameters:
first - The first evaluator.
second - The second evaluator.
third - The third evaluator.
Method Detail

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.

create

public static <InputType,FirstIntermediateType,SecondIntermediateType,OutputType> CompositeEvaluatorTriple<InputType,FirstIntermediateType,SecondIntermediateType,OutputType> create(Evaluator<? super InputType,? extends FirstIntermediateType> first,
                                                                                                                                                                                     Evaluator<? super FirstIntermediateType,? extends SecondIntermediateType> second,
                                                                                                                                                                                     Evaluator<? super SecondIntermediateType,? extends OutputType> third)
A convenience method for creating composite evaluators.

Type Parameters:
InputType - The input type for the first evaluator. This is also the input type for the composite evaluator.
FirstIntermediateType - The output type of the first evaluator and the input type of the second evaluator.
SecondIntermediateType - The output type of the second evaluator and the input type of the third evaluator.
OutputType - The output type of the third evaluator. This is also the output type of the composite evaluator.
Parameters:
first - The first evaluator.
second - The second evaluator.
third - The third evaluator.
Returns:
A new CompositeEvaluatorTriple from the three given evaluators.