gov.sandia.cognition.evaluator
Class ForwardReverseEvaluatorPair<InputType,OutputType,ForwardType extends Evaluator<? super InputType,? extends OutputType>,ReverseType extends Evaluator<? super OutputType,? extends InputType>>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.evaluator.ForwardReverseEvaluatorPair<InputType,OutputType,ForwardType,ReverseType>
Type Parameters:
InputType - The type of input the forward evaluator. Also the output of the reverse evaluator.
OutputType - The type of output of the forward evaluator. Also the input of the reverse evaluator
ForwardType - The type of the forward evaluator.
ReverseType - The type of the reverse evaluator.
All Implemented Interfaces:
Evaluator<InputType,OutputType>, ReversibleEvaluator<InputType,OutputType,ForwardReverseEvaluatorPair<OutputType,InputType,ReverseType,ForwardType>>, CloneableSerializable, Serializable, Cloneable

public class ForwardReverseEvaluatorPair<InputType,OutputType,ForwardType extends Evaluator<? super InputType,? extends OutputType>,ReverseType extends Evaluator<? super OutputType,? extends InputType>>
extends AbstractCloneableSerializable
implements ReversibleEvaluator<InputType,OutputType,ForwardReverseEvaluatorPair<OutputType,InputType,ReverseType,ForwardType>>

Represents a both a (normal) forward evaluator and its reverse as a pair. This makes it easy to couple two such functions together, even if they were not originally implemented as reversible.

Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
protected  ForwardType forward
          The forward evaluator from input type to output type.
protected  ReverseType reverse
          The reverse evaluator from output type to input type.
 
Constructor Summary
ForwardReverseEvaluatorPair()
          Creates a new, empty ForwardReverseEvaluatorPair.
ForwardReverseEvaluatorPair(ForwardType forward, ReverseType reverse)
          Creates a new ForwardReverseEvaluatorPair.
 
Method Summary
static
<InputType,OutputType,ForwardType extends Evaluator<? super InputType,? extends OutputType>,ReverseType extends Evaluator<? super OutputType,? extends InputType>>
ForwardReverseEvaluatorPair<InputType,OutputType,ForwardType,ReverseType>
create(ForwardType forward, ReverseType reverse)
          Convenience method for creating a new forward-reverse evaluator pair.
 OutputType evaluate(InputType input)
          Evaluates the function on the given input and returns the output.
 InputType evaluateReverse(OutputType output)
          Evaluates the reverse evaluator on a given object of output type.
 ForwardType getForward()
          Gets the forward evaluator that maps input type to output type.
 ReverseType getReverse()
          Gets the reverse evaluator that maps output type to input type.
 ForwardReverseEvaluatorPair<OutputType,InputType,ReverseType,ForwardType> reverse()
          Gets the data converter that performs the reverse conversion.
 void setForward(ForwardType forward)
          Sets the forward evaluator that maps input type to output type.
 void setReverse(ReverseType reverse)
          Sets the reverse evaluator that maps output type to input type.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

forward

protected ForwardType extends Evaluator<? super InputType,? extends OutputType> forward
The forward evaluator from input type to output type.


reverse

protected ReverseType extends Evaluator<? super OutputType,? extends InputType> reverse
The reverse evaluator from output type to input type.

Constructor Detail

ForwardReverseEvaluatorPair

public ForwardReverseEvaluatorPair()
Creates a new, empty ForwardReverseEvaluatorPair.


ForwardReverseEvaluatorPair

public ForwardReverseEvaluatorPair(ForwardType forward,
                                   ReverseType reverse)
Creates a new ForwardReverseEvaluatorPair.

Parameters:
forward - The forward evaluator.
reverse - The reverse evaluator.
Method Detail

reverse

public ForwardReverseEvaluatorPair<OutputType,InputType,ReverseType,ForwardType> reverse()
Description copied from interface: ReversibleEvaluator
Gets the data converter that performs the reverse conversion.

Specified by:
reverse in interface ReversibleEvaluator<InputType,OutputType,ForwardReverseEvaluatorPair<OutputType,InputType,ReverseType extends Evaluator<? super OutputType,? extends InputType>,ForwardType extends Evaluator<? super InputType,? extends OutputType>>>
Returns:
The reverse converter.

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.

evaluateReverse

public InputType evaluateReverse(OutputType output)
Evaluates the reverse evaluator on a given object of output type.

Parameters:
output - The object of output type to pass to the reverse evaluator.
Returns:
The object of input type returned by the reverse evaluator.

getForward

public ForwardType getForward()
Gets the forward evaluator that maps input type to output type.

Returns:
The forward evaluator.

setForward

public void setForward(ForwardType forward)
Sets the forward evaluator that maps input type to output type.

Parameters:
forward - The forward evaluator.

getReverse

public ReverseType getReverse()
Gets the reverse evaluator that maps output type to input type.

Returns:
The reverse evaluator.

setReverse

public void setReverse(ReverseType reverse)
Sets the reverse evaluator that maps output type to input type.

Parameters:
reverse - The reverse evaluator.

create

public static <InputType,OutputType,ForwardType extends Evaluator<? super InputType,? extends OutputType>,ReverseType extends Evaluator<? super OutputType,? extends InputType>> ForwardReverseEvaluatorPair<InputType,OutputType,ForwardType,ReverseType> create(ForwardType forward,
                                                                                                                                                                                                                                                                  ReverseType reverse)
Convenience method for creating a new forward-reverse evaluator pair.

Type Parameters:
InputType - The input type for the forward evaluator. Also the output type of the reverse evaluator.
OutputType - The output type for the forward evaluator. Also the input type of the reverse evaluator.
ForwardType - The type of the forward evaluator.
ReverseType - The type of the reverse evaluator.
Parameters:
forward - The forward evaluator.
reverse - The reverse evaluator.
Returns:
A new evaluator pair.