gov.sandia.cognition.data.convert.number
Class DefaultBooleanToNumberConverter

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.data.convert.AbstractDataConverter<InputType,OutputType>
          extended by gov.sandia.cognition.data.convert.AbstractReversibleDataConverter<InputType,OutputType>
              extended by gov.sandia.cognition.data.convert.AbstractReverseCachedDataConverter<Boolean,Number,DefaultBooleanToNumberConverter.Reverse>
                  extended by gov.sandia.cognition.data.convert.number.DefaultBooleanToNumberConverter
All Implemented Interfaces:
DataConverter<Boolean,Number>, ReversibleDataConverter<Boolean,Number>, Evaluator<Boolean,Number>, ReversibleEvaluator<Boolean,Number,DataConverter<? super Number,? extends Boolean>>, CloneableSerializable, Serializable, Cloneable

public class DefaultBooleanToNumberConverter
extends AbstractReverseCachedDataConverter<Boolean,Number,DefaultBooleanToNumberConverter.Reverse>

Converts a Boolean to a Number by using predefined values for true, false, and (optionally) null.

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

Nested Class Summary
 class DefaultBooleanToNumberConverter.Reverse
          The reverse converter for the DefaultBooleanToNumberConverter.
 
Field Summary
static double DEFAULT_FALSE_VALUE
          The default value for false is -1.0.
static double DEFAULT_NULL_VALUE
          The default value for null is 0.0.
static double DEFAULT_TRUE_VALUE
          The default value for true is 1.0.
protected  Number falseValue
          The number to use to represent a false value.
protected  Number nullValue
          The number to use to represent a null value.
protected  Number trueValue
          The number to use to represent a true value.
 
Fields inherited from class gov.sandia.cognition.data.convert.AbstractReverseCachedDataConverter
reverse
 
Constructor Summary
DefaultBooleanToNumberConverter()
          Creates a new DefaultBooleanToNumberConverter with default values.
DefaultBooleanToNumberConverter(Number trueValue, Number falseValue, Number nullValue)
          Creates a new DefaultBooleanToNumberConverter.
 
Method Summary
 Boolean convertToBoolean(Number input)
          Converts the given number to a boolean value by determining if it is closer to the number representing true or the number representing false.
 Number convertToNumber(Boolean input)
          Converts the given boolean to a number using the
protected  DefaultBooleanToNumberConverter.Reverse createReverse()
          Creates a new reverse converter.
 Number evaluate(Boolean input)
          Converts an input boolean to a number.
 Number getFalseValue()
          Gets the number that represents a falue value.
 Number getNullValue()
          Gets the number that represents a null value.
 Number getTrueValue()
          Gets the number that represents a true value.
 void setFalseValue(Number falseValue)
          Sets the number that represents a falue value.
 void setNullValue(Number nullValue)
          Sets the number that represents a null value.
 void setTrueValue(Number trueValue)
          Sets the number that represents a true value.
 
Methods inherited from class gov.sandia.cognition.data.convert.AbstractReverseCachedDataConverter
reverse
 
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

DEFAULT_TRUE_VALUE

public static final double DEFAULT_TRUE_VALUE
The default value for true is 1.0.

See Also:
Constant Field Values

DEFAULT_FALSE_VALUE

public static final double DEFAULT_FALSE_VALUE
The default value for false is -1.0.

See Also:
Constant Field Values

DEFAULT_NULL_VALUE

public static final double DEFAULT_NULL_VALUE
The default value for null is 0.0.

See Also:
Constant Field Values

trueValue

protected Number trueValue
The number to use to represent a true value.


falseValue

protected Number falseValue
The number to use to represent a false value.


nullValue

protected Number nullValue
The number to use to represent a null value.

Constructor Detail

DefaultBooleanToNumberConverter

public DefaultBooleanToNumberConverter()
Creates a new DefaultBooleanToNumberConverter with default values.


DefaultBooleanToNumberConverter

public DefaultBooleanToNumberConverter(Number trueValue,
                                       Number falseValue,
                                       Number nullValue)
Creates a new DefaultBooleanToNumberConverter.

Parameters:
trueValue - The number to use for true.
falseValue - The number to use for false.
nullValue - The number to use for null.
Method Detail

evaluate

public Number evaluate(Boolean input)
Converts an input boolean to a number.

Parameters:
input - The input value to convert.
Returns:
The boolean converted to a number.

convertToNumber

public Number convertToNumber(Boolean input)
Converts the given boolean to a number using the

Parameters:
input - The input boolean to convert to a number.
Returns:
The number value for the boolean.

convertToBoolean

public Boolean convertToBoolean(Number input)
Converts the given number to a boolean value by determining if it is closer to the number representing true or the number representing false.

Parameters:
input - The input number to convert to a boolean.
Returns:
The boolean value of the number.

createReverse

protected DefaultBooleanToNumberConverter.Reverse createReverse()
Description copied from class: AbstractReverseCachedDataConverter
Creates a new reverse converter. Should only be called when there is a cache miss for this converter.

Specified by:
createReverse in class AbstractReverseCachedDataConverter<Boolean,Number,DefaultBooleanToNumberConverter.Reverse>
Returns:
The reverse converter.

getTrueValue

public Number getTrueValue()
Gets the number that represents a true value.

Returns:
The number that represents a true value.

setTrueValue

public void setTrueValue(Number trueValue)
Sets the number that represents a true value.

Parameters:
trueValue - The number that represents a true value.

getFalseValue

public Number getFalseValue()
Gets the number that represents a falue value.

Returns:
The number that represents a false value.

setFalseValue

public void setFalseValue(Number falseValue)
Sets the number that represents a falue value.

Parameters:
falseValue - The number that represents a false value.

getNullValue

public Number getNullValue()
Gets the number that represents a null value.

Returns:
The number that represents a null value.

setNullValue

public void setNullValue(Number nullValue)
Sets the number that represents a null value.

Parameters:
nullValue - The number that represents a null value.