codesimian.wrap
Class DefaultWrapAbilities

java.lang.Object
  extended by codesimian.wrap.DefaultWrapAbilities
All Implemented Interfaces:
WrapAbilities

public class DefaultWrapAbilities
extends java.lang.Object
implements WrapAbilities

starts empty. add any abilities. Each WrapAbility is a FROM Class, a TO Class, and an optional ACCURACY and COST for the conversion.

This is called DefaultWrapAbilities because it is the default implementation of WrapAbilities. It does not contain any abilities by default. You have to add them.


Nested Class Summary
 
Nested classes/interfaces inherited from interface codesimian.wrap.WrapAbilities
WrapAbilities.WrapWrapAbilities
 
Field Summary
static double COST_OF_IMPOSSIBLE
           
 
Constructor Summary
DefaultWrapAbilities()
           
 
Method Summary
 double accuracyOfWrap(java.lang.Class from, java.lang.Class to)
          returns 0 if can not wrap that way, else returns a number between 0 and 1.
 void addWrapAbility(java.lang.Class from, java.lang.Class to)
           
 void addWrapAbility(java.lang.Class from, java.lang.Class to, double accuracy)
           
 void addWrapAbility(java.lang.Class from, java.lang.Class to, double accuracy, double cost)
           
 double costOfWrap(java.lang.Class from, java.lang.Class to)
          default should be 1000
 java.util.List<java.lang.Class> getAllFrom()
          all types of input objects that can be used to create at least 1 other type of object each
 java.util.List<java.lang.Class> getAllFromForThisTo(java.lang.Class to)
          returns all input types that can be converted to the 'to' type
 java.util.List<java.lang.Class> getAllTo()
          all types that can be created, given the required input object
 java.util.List<java.lang.Class> getAllToForThisFrom(java.lang.Class from)
          returns all output types that can be converted to the 'from' type
 java.util.List<WrapAbility> getAllWrapAbilitys()
          beware: these could be generated at the time this function is called
static void main(java.lang.String[] s)
          test
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COST_OF_IMPOSSIBLE

public static final double COST_OF_IMPOSSIBLE
See Also:
Constant Field Values
Constructor Detail

DefaultWrapAbilities

public DefaultWrapAbilities()
Method Detail

accuracyOfWrap

public double accuracyOfWrap(java.lang.Class from,
                             java.lang.Class to)
Description copied from interface: WrapAbilities
returns 0 if can not wrap that way, else returns a number between 0 and 1.

For example, accuracyOfWrap(byte.class,int.class) should return 1, but accuracyOfWrap(int.class,byte.class) should return 0.25 since 3/4 of the bits are lost, but since ints use all their bits less often than bytes use all their bytes, you may return (for example) .4 instead.

accuracyOfWrap(StringBuffer.class,String.class) should return a high fraction. accuracyOfWrap(boolean.class,ANYTHINGEXCEPTBOOLEAN.class) should return a very low fraction because there is only 1 bit of information in a boolean.

Specified by:
accuracyOfWrap in interface WrapAbilities

costOfWrap

public double costOfWrap(java.lang.Class from,
                         java.lang.Class to)
Description copied from interface: WrapAbilities
default should be 1000

Specified by:
costOfWrap in interface WrapAbilities

addWrapAbility

public void addWrapAbility(java.lang.Class from,
                           java.lang.Class to)

addWrapAbility

public void addWrapAbility(java.lang.Class from,
                           java.lang.Class to,
                           double accuracy)

addWrapAbility

public void addWrapAbility(java.lang.Class from,
                           java.lang.Class to,
                           double accuracy,
                           double cost)

getAllFrom

public java.util.List<java.lang.Class> getAllFrom()
all types of input objects that can be used to create at least 1 other type of object each

Specified by:
getAllFrom in interface WrapAbilities

getAllTo

public java.util.List<java.lang.Class> getAllTo()
all types that can be created, given the required input object

Specified by:
getAllTo in interface WrapAbilities

getAllFromForThisTo

public java.util.List<java.lang.Class> getAllFromForThisTo(java.lang.Class to)
returns all input types that can be converted to the 'to' type

Specified by:
getAllFromForThisTo in interface WrapAbilities

getAllToForThisFrom

public java.util.List<java.lang.Class> getAllToForThisFrom(java.lang.Class from)
returns all output types that can be converted to the 'from' type

Specified by:
getAllToForThisFrom in interface WrapAbilities

getAllWrapAbilitys

public java.util.List<WrapAbility> getAllWrapAbilitys()
Description copied from interface: WrapAbilities
beware: these could be generated at the time this function is called

Specified by:
getAllWrapAbilitys in interface WrapAbilities

main

public static void main(java.lang.String[] s)
test