codesimian
Class N

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.N
All Implemented Interfaces:
CodeSimian, java.io.Serializable

public class N
extends DefaultCS

An efficient and flexible decimal NUMBER, with one instance var: double.
N is EFFICIENT because you can get/set its value directly as a public instance var.
Its FLEXIBLE because the param system can also be used to get/set its value.

Call setP(x) to set the number value to x.D().
For any x, P(x) returns this N.

There can be 0 or 1 params. There never really is a param (even if countP()==1), but P and setP etc can make it appear to have 1 param. If countP()==0, the number value returned by DForProxy() still returns the current value, which can instead be changed by changing the instace var 'value'.

See Also:
Serialized Form

Field Summary
 double value
          value of this N
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
N()
           
N(boolean b)
           
N(byte b)
           
N(char c)
           
N(double d)
           
N(float f)
           
N(int i)
           
N(long L)
           
N(java.lang.Number n)
           
N(short s)
           
 
Method Summary
 CS addP(CS addMe)
          always sets the value to addMe.D(), but if countP()==1 then returns false to show the countP did not increase
 int countP()
          0 or 1.
 boolean deleteP(int index)
          WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          returns 'value'
 java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
          This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 CS newInstance()
          temporarily, uses Class objects to instantiate the default constructor.
 CS P(int index)
          returns this CS.
 boolean setD(double d)
          all setX functions return setD by default.
 boolean setL(java.lang.Object o)
          setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.
 boolean setP(int index, CS newValue)
          sets the value of this N to newValue.D().
 java.lang.String toStringG(java.util.HashSet h)
           
 
Methods inherited from class codesimian.DefaultCS
B, C, decrementMyFuel, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, LForProxy, LForProxy, myFuel, name, objectToCS, objectToCSArray, objectToCSArray, prevD, prevL, PType, S, setB, setC, setCountP, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL1, setMyFuel, setName, setObject, setPrevExec, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, isIllusion, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

value

public double value
value of this N

Constructor Detail

N

public N()

N

public N(double d)

N

public N(float f)

N

public N(byte b)

N

public N(char c)

N

public N(short s)

N

public N(int i)

N

public N(long L)

N

public N(boolean b)

N

public N(java.lang.Number n)
Method Detail

DForProxy

public double DForProxy()
returns 'value'

Specified by:
DForProxy in class DefaultCS

P

public CS P(int index)
returns this CS. Ignores index. Removes the illusion (if its there) of having 1 param, to avoid infinite loops. There are 0 params left after this.

Overrides:
P in class DefaultCS
Parameters:
index - range 0 to countP()-1 inclusive
See Also:
CS.heap()

setP

public boolean setP(int index,
                    CS newValue)
sets the value of this N to newValue.D(). Ignores index. Sets quantity of params to 1.

Overrides:
setP in class DefaultCS

countP

public int countP()
0 or 1. Changes weirdly when other functions in this N are called.

Overrides:
countP in class DefaultCS

deleteP

public boolean deleteP(int index)
Description copied from class: DefaultCS
WARNING: if returns false, could have deleted but not moved other params down 1 index.
WARNING: if duplicates not allowed, can not slide params down 1 index the standard way, returns false.

Overrides:
deleteP in class DefaultCS

addP

public CS addP(CS addMe)
always sets the value to addMe.D(), but if countP()==1 then returns false to show the countP did not increase

Overrides:
addP in class CS
Returns:
'this' CS if added param, or null if did not add.

newInstance

public CS newInstance()
Description copied from class: DefaultCS
temporarily, uses Class objects to instantiate the default constructor. This should be fixed to copy this CS. See oldNewInstance().

Overrides:
newInstance in class DefaultCS

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

toStringG

public java.lang.String toStringG(java.util.HashSet h)

setD

public boolean setD(double d)
Description copied from class: DefaultCS
all setX functions return setD by default. setD returns false by default. Override in subclass. For example, class N has a public variable value, and N.value is set to setToThisValue.

Overrides:
setD in class DefaultCS

setL

public boolean setL(java.lang.Object o)
Description copied from class: CS
setL setD setF setJ setI setS setC setB setZ are functions that SET THE VALUE OF THIS CS to some object, primitive, or array.

Overrides:
setL in class DefaultCS

javaCode

public java.lang.String javaCode(CS listOfCodeAlreadyTraversed)
Description copied from class: DefaultCS
This will work with the basic operators like + / * - and probably a few others, but complex CSs will have to override this function to specify how to translate itself into Java code in combination with its children and descendent CSs.

Example:
CodeSimian code: *(+(2 3) /(4 5))
becomes this Java code: (2+3)*(4/5) There could be problems with Java's parsing order...

Overrides:
javaCode in class DefaultCS
Returns:
String of Java code, or null if this CS does not know how to convert itself to Java code.