codesimian
Class Static

java.lang.Object
  extended by codesimian.Static

public class Static
extends java.lang.Object

Static functions used in various subclasses of CS. CS should be as simple as possible, so these functions were moved from CS to Static. Many of them should be moved to whatever class they are most relevant to.


Nested Class Summary
static class Static.AddDefaultCommand
          wrapper for CSFactory.add(CS)
static class Static.DefaultCommands
          wrapper for Static.defaultListOfCSs()
static class Static.DefaultExec
          1/06 this is not the default exec anymore.
static class Static.DefaultList
           
static class Static.DefaultStack
           
static class Static.SingletonList
           
 
Field Summary
static int ALWAYS_CALCULATE
          Deprecated. 
static java.lang.Number defaultMaxExecAdd
           
static java.lang.Number defaultMaxLoops
           
static java.lang.String optionsFileName
           
static StackNeverEmpty<CS> optionsStack
          A stack of CS's.
static boolean pPrints
           
 
Constructor Summary
Static()
           
 
Method Summary
static CS arrayToCS(java.lang.Object array)
          converts any type of array to a CS, using objectToCS to interpret individual Objects
static CS[] boundedGraphSet(CS root, java.util.Set<CS> dontTraversePastThese, boolean returnBounds)
          Same as graphSet, except will not traverse past a given set of CSs.
static CS collectionToCS(java.util.Collection c)
           
static boolean copyOptions(CS from, CS to)
          copies one CS's options to an other CS.
static CS deepCopyExcept(CS root, CS doNotCopyThese)
          same as deepCopy(CS[]) but does not copy any of the CSs in doNotCopyThese (a list of CSs) or past them.
static CS defaultCompiler()
          note: the same type of compiler (with keyword "compile") exists in defaultListOfCSs()
static java.lang.String defaultKeywordForClass(java.lang.Class c)
           
static CS defaultListOfCSs()
          everything CodeSimian language includes before typing any code, like +(0 0), *(0 0), /(0 0), list(), sound(0), window(0), etc.
static CS defaultStack()
           
static java.lang.String[] defaultVarNames()
          returns the default variable names that can be used with CS.L(String) and CS.setL(String,Object);
static java.lang.Class[] defaultVarTypes()
          returns the Class types of the variables whose names are returned by defaultVarNames.
static java.lang.String detailString(CS describeMe)
          a longer string about this CS
static boolean doubleToBoolean(double d)
          Returns true if 0.0 < d, else false.
static byte doubleToByte(double d)
           
static char doubleToChar(double d)
          Wraps d around char range 0 - 127 (inclusive) and rounds; return (char) Math.round(wrapRange(-.5, d, 127.5));
static int doubleToInt(double d)
          If d is in int range, returns d rounded to int.
static int doubleToIntRange(int min, double d, int max)
          The standard way to convert doubles to ints.
static int doubleToIntRangeFasterIfInRange(int min, double d, int max)
          like doubleToIntRange() except more efficient if d is already in range (just return d).
static long doubleToLong(double d)
          If d is in long range, returns d rounded to long.
static short doubleToShort(double d)
           
static void err(java.lang.String errorText)
          abbrev.
static CS getCopyOfOption(java.lang.String optionName)
           
static CS getCopyOfOptions()
           
static CS getDefaultType()
          This fuzzy-type always answers TRUE - everything is that type.
static CS[] graphSet(CS root)
          Returns an unordered array containing each CS in the parameter graph exactly once.
static float minValueMax(float min, float value, float max)
          returns value if its between min and max, else returns min or max
static java.lang.String nextName()
           CodeSimian allows the same CS to be in the string code multiple times.
static CS objectToCS(java.lang.Object convertMeToCS)
          Converts an Object to a CS by wrapping.
static void p(java.lang.String println)
          System.err.println
static int paramIndex(CS[] array, CS findMe)
          returns the index or -1 if not found
static CS peekOptions()
          All new CSs should set their options to the same options as I have.
For example: Num n = new Num(3.7); n.setRoot( CS.peekOptions().getRoot() );
But you do not have to do that, because setOptions() should do it automatically (not implemented yet 5/05).
static CS popOptions()
           
static java.lang.String propertiesString(CS c)
          Returns a String representing the variables: outputToStack, inputFromStack, and myFuel.
static boolean pushOptions(CS pushMe)
           
static boolean setDefaultType(CS dt)
           
static CS[] setOfDuplicatesInGraph(CS root)
          like graphSet(), but only returns the CSs that have 2 or more parents - duplicates.
static CS staticCompile(java.lang.String code)
          if you want to compile something but are confused, try this.
static java.lang.String toStringG(CS root, java.util.HashSet h)
          Recursively builds a String from the GRAPH of CS parameters, using each CS exactly once.
static java.lang.String toStringLimitDepth(CS currentCS, java.util.HashSet noDuplicates, int maxDepth)
          like toStringG(HashSet) except limits depth.
static java.lang.String toStringLimitDepth(CS root, int maxDepth)
          depth-first traversal of the param graph, with limited depth.
static java.lang.String toStringOne(CS c)
          this 1 CS, no paranthesis, possibly with modifiers.
Example: +$3#nameOfThisPlus
toString() might have returned (for that same example): +$3#nameOfThisPlus(1 2$7 *(3 4))
static java.lang.String toStringSafe(CS c)
          minimum info about this CS.
static double wrapRange(double min, double wrapMe, double max)
          Wraps a double around a range.
static float wrapRange(float min, float wrapMe, float max)
           
static double wrapRangeFasterIfInRange(double min, double wrapMe, double max)
          Checks if wrapMe is in range, and returns wrapMe if so, else returns wrapRange(min,wrapMe,max).
static double wrapRangeInclusive(double min, double wrapMe, double max)
          never converts min to max or max to min
static float wrapRangeInclusive(float min, float wrapMe, float max)
          never converts min to max or max to min
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

optionsFileName

public static java.lang.String optionsFileName

ALWAYS_CALCULATE

@Deprecated
public static final int ALWAYS_CALCULATE
Deprecated. 
If myFuel == ALWAYS_CALCULATE (default), and Options.costAvailable is big enough, D() always calculates DForProxy() instead of returning the previous value. If not, returns the previous value, or 0 if this is the first value.

See Also:
Constant Field Values

defaultMaxExecAdd

public static java.lang.Number defaultMaxExecAdd

defaultMaxLoops

public static java.lang.Number defaultMaxLoops

optionsStack

public static StackNeverEmpty<CS> optionsStack
A stack of CS's. When a new CS is instantiated, it should copy the options of the CS on top of this stack.

See Also:
pushOptions(), peekOptions(), popOptions()

pPrints

public static boolean pPrints
Constructor Detail

Static

public Static()
Method Detail

getCopyOfOptions

public static CS getCopyOfOptions()

getCopyOfOption

public static CS getCopyOfOption(java.lang.String optionName)

defaultListOfCSs

public static CS defaultListOfCSs()
everything CodeSimian language includes before typing any code, like +(0 0), *(0 0), /(0 0), list(), sound(0), window(0), etc.

Modifying the returned list changes things GLOBALLY because there is only 1 list. Make a copy if you want to change it locally.

Currently copies the list in CSFactory then returns that same list forever.


defaultVarNames

public static java.lang.String[] defaultVarNames()
returns the default variable names that can be used with CS.L(String) and CS.setL(String,Object);


defaultVarTypes

public static java.lang.Class[] defaultVarTypes()
returns the Class types of the variables whose names are returned by defaultVarNames. The indexs are the same. Example: if defaultVarNames()[1] is "cost", then defaultVarTypes()[1] is Double.class; double.class cant be returned by CS.L(String) because its primitive so use Double.class instead.


defaultCompiler

public static CS defaultCompiler()
note: the same type of compiler (with keyword "compile") exists in defaultListOfCSs()


getDefaultType

public static CS getDefaultType()
This fuzzy-type always answers TRUE - everything is that type. This is slow because it makes a copy() of defaultParamType. Thats necessary because its mutable.


setDefaultType

public static boolean setDefaultType(CS dt)

defaultStack

public static CS defaultStack()

doubleToByte

public static final byte doubleToByte(double d)

doubleToShort

public static final short doubleToShort(double d)

doubleToInt

public static final int doubleToInt(double d)
If d is in int range, returns d rounded to int. Else wraps d around int range and rounds.


doubleToLong

public static final long doubleToLong(double d)
If d is in long range, returns d rounded to long. Else wraps d around long range and rounds.


doubleToIntRange

public static final int doubleToIntRange(int min,
                                         double d,
                                         int max)
The standard way to convert doubles to ints. Wraps d around range: min to max+1. Then rounds down.


doubleToIntRangeFasterIfInRange

public static final int doubleToIntRangeFasterIfInRange(int min,
                                                        double d,
                                                        int max)
like doubleToIntRange() except more efficient if d is already in range (just return d). Slower if not already in range.


doubleToBoolean

public static final boolean doubleToBoolean(double d)
Returns true if 0.0 < d, else false.


doubleToChar

public static final char doubleToChar(double d)
Wraps d around char range 0 - 127 (inclusive) and rounds; return (char) Math.round(wrapRange(-.5, d, 127.5));


deepCopyExcept

public static CS deepCopyExcept(CS root,
                                CS doNotCopyThese)
same as deepCopy(CS[]) but does not copy any of the CSs in doNotCopyThese (a list of CSs) or past them. Instead, sometimes the same CSs are in the original network and the copied network and in doNotCopyThese.

For efficiency, use doNotCopyThese.indexP(anyCS) to determine if anyCS is in doNotCopyThese.

FIXME: change doNotCopyThese to be a Set instead of CS, and add ability to convert to Set in DefaultCS.L(Class) and .L(int,Class,int).


paramIndex

public static int paramIndex(CS[] array,
                             CS findMe)
returns the index or -1 if not found


copyOptions

public static boolean copyOptions(CS from,
                                  CS to)
copies one CS's options to an other CS. Options include getExec(), myFuel(), and fuel(). Thats not all the options. This function will have to be fixed by adding more options later... These things are usually not copied by newInstance().


wrapRangeInclusive

public static double wrapRangeInclusive(double min,
                                        double wrapMe,
                                        double max)
never converts min to max or max to min


wrapRangeInclusive

public static float wrapRangeInclusive(float min,
                                       float wrapMe,
                                       float max)
never converts min to max or max to min


wrapRange

public static double wrapRange(double min,
                               double wrapMe,
                               double max)
Wraps a double around a range. Example: 22 wrapped around 5-10 = 7. -1 wrapped = 9. 0 wrapped = 5. -.1 wrapped = 9.9. Never returns max. Min and max occupy the same point on the specified number-circle. Would return min instead.
If min <= wrapMe < max, returns wrapMe.

An other example: //returns 2
0.0/3.0 <-- returns 0.0 if wrapMe == 6.0
2.0 <-- returns 2.0 if wrapMe == 5.0
1.0 <-- returns 1.0 if wrapMe == 4.0
0.0/3.0 <-- max = 3.0
2.0
1.0
0.0/3.0 <-- min = 0.0
2.0
1.0
0.0/3.0
2.0 <-- returns 2.0 if wrapMe == -4.0
1.0 <-- returns 1.0 if wrapMe == -5.0
0.0/3.0 <-- returns 0.0 if wrapMe == -6.0


wrapRange

public static float wrapRange(float min,
                              float wrapMe,
                              float max)

wrapRangeFasterIfInRange

public static double wrapRangeFasterIfInRange(double min,
                                              double wrapMe,
                                              double max)
Checks if wrapMe is in range, and returns wrapMe if so, else returns wrapRange(min,wrapMe,max). This function is faster than wrapRange() when wrapMe is already in range, slower if not.


graphSet

public static CS[] graphSet(CS root)
Returns an unordered array containing each CS in the parameter graph exactly once. Graph edges are parameters. bigO(total number of parameters). Starts the search at 'root'.


setOfDuplicatesInGraph

public static CS[] setOfDuplicatesInGraph(CS root)
like graphSet(), but only returns the CSs that have 2 or more parents - duplicates.


boundedGraphSet

public static CS[] boundedGraphSet(CS root,
                                   java.util.Set<CS> dontTraversePastThese,
                                   boolean returnBounds)
Same as graphSet, except will not traverse past a given set of CSs. ReturnBounds determines if the bounding set (the parts of it found from traversing) is returned. Only Set.contains() is used, so HashSet is fast, but an array or list is slow.


staticCompile

public static CS staticCompile(java.lang.String code)
if you want to compile something but are confused, try this. staticCompile uses default CodeSimian compiling options for the parameter 'code'.

THIS FUNCTION SHOULD BE RENAMED TO Static.defaultCompile(String)


pushOptions

public static boolean pushOptions(CS pushMe)
See Also:
optionsStack

popOptions

public static CS popOptions()
See Also:
optionsStack

peekOptions

public static CS peekOptions()
All new CSs should set their options to the same options as I have.
For example: Num n = new Num(3.7); n.setRoot( CS.peekOptions().getRoot() );
But you do not have to do that, because setOptions() should do it automatically (not implemented yet 5/05).

See Also:
optionsStack

propertiesString

public static java.lang.String propertiesString(CS c)
Returns a String representing the variables: outputToStack, inputFromStack, and myFuel. Should be part of the CodeSimian string language (1/05 not yet implemented).


toStringOne

public static java.lang.String toStringOne(CS c)
this 1 CS, no paranthesis, possibly with modifiers.
Example: +$3#nameOfThisPlus
toString() might have returned (for that same example): +$3#nameOfThisPlus(1 2$7 *(3 4))


objectToCS

public static CS objectToCS(java.lang.Object convertMeToCS)
Converts an Object to a CS by wrapping. This function is the temporary root of a group of functions for converting various Object types to CS. It will later be moved to a new subclass of CS, which will access it with setL(Object).


collectionToCS

public static CS collectionToCS(java.util.Collection c)

arrayToCS

public static CS arrayToCS(java.lang.Object array)
converts any type of array to a CS, using objectToCS to interpret individual Objects


detailString

public static java.lang.String detailString(CS describeMe)
a longer string about this CS


toStringSafe

public static java.lang.String toStringSafe(CS c)
minimum info about this CS. Assumes the quantity of params could be out of valid range, or other errors could have occured or could be caused easily. Ends recursion at its childs, 1 level down, with less info about them. Not valid code.


err

public static void err(java.lang.String errorText)
abbrev. for: throw new Error(errorText)


p

public static void p(java.lang.String println)
System.err.println


toStringLimitDepth

public static java.lang.String toStringLimitDepth(CS root,
                                                  int maxDepth)
depth-first traversal of the param graph, with limited depth. Example, maxDepth==1 uses only this CS and its childs.


toStringLimitDepth

public static java.lang.String toStringLimitDepth(CS currentCS,
                                                  java.util.HashSet noDuplicates,
                                                  int maxDepth)
like toStringG(HashSet) except limits depth. The returned String is usually not valid CodeSimian code, because of the limited depth.

Parameters:
currentCS - was added when this function was moved from CS to Static.

nextName

public static java.lang.String nextName()
                CodeSimian allows the same CS to be in the string code multiple times.
                Any CS in the code more than once must have a name (name()),
                but name() often returns null for anonymous.
                This function returns the name you should give this CS if that name
                is not a duplicate of some other name you're using.

                Example: +#adder(2 *#mul(3 4.5) mul adder 6 /#div(7 8) adder div)
                Then if you called setName(null) on that + and *, but not the /,
                the +'s decompile() should return something like...
                +#n20(2 *#n21(3 4.5) n21 n20 6 /#div(7 8) n20 div)
        


toStringG

public static java.lang.String toStringG(CS root,
                                         java.util.HashSet h)
Recursively builds a String from the GRAPH of CS parameters, using each CS exactly once. Adds CSs to the HashSet when it gets their Strings, and doesnt use any already in the HashSet. "@"+keyword() is put in the String for CSs that have already been traversed in depth-first order, instead of infinitely traversing them again.


minValueMax

public static float minValueMax(float min,
                                float value,
                                float max)
returns value if its between min and max, else returns min or max


defaultKeywordForClass

public static java.lang.String defaultKeywordForClass(java.lang.Class c)