codesimian
Class N

java.lang.Object
  extended by codesimian.CS<CSGeneric>
      extended by codesimian.DefaultCS
          extended by codesimian.N
All Implemented Interfaces:
CodeSimian

public class N
extends DefaultCS

A decimal NUMBER, with one instance var: double.


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'.


Field Summary
 double value
          value of this N
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
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 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 (need to write some more code), uses Class objects to instantiate the default constructor
 CS P(int index)
          returns this CS.
static double parseDoubleFromNaturalLanguage(java.lang.String natLangNumber)
          example: "10 million and fiftyseven point 9"
 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 toJavaCode(CSCallOptions options, JavaCodeWritingState state)
          returns the code for a new subclass of CS that does the same thing as this network of code.
 java.lang.String toString()
          problem: toString() does not return the same as L(String.class).
 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, javaCode, 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, setPType, setS, setZ, start, V, Z
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addS, addZ, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, GETS, GETZ, IForProxy, isIllusion, 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, reflect6, setB, SETB, setC, SETC, setCost, SETD, setDescription, setF, SETF, setHeap, setI, SETI, setJ, SETJ, SETL, setL, setL, setParent, setParsePriority, setProxyOf, setS, SETS, setTester, setZ, 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 (or neg?) 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 throwFromAdd('P') if did not add.

newInstance

public CS newInstance()
Description copied from class: DefaultCS
temporarily (need to write some more code), uses Class objects to instantiate the default constructor

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

toString

public java.lang.String toString()
Description copied from class: DefaultCS
problem: toString() does not return the same as L(String.class). toString returns code and L returns params as char values. Maybe only decompile() should be used for code instead.

Overrides:
toString 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

toJavaCode

public java.lang.String toJavaCode(CSCallOptions options,
                                   JavaCodeWritingState state)
Description copied from class: CS
returns the code for a new subclass of CS that does the same thing as this network of code. Parts of the network that cant be converted to java code become the parameters of this new type of CS.

Must return an atomic string of Java code. For example "(3+PD(4)*5)" or "3" or "Math.sin(3.45)" are ok but "3+(PD(4)*5)" and "3+4*5" are not. For example, if 2 of these return a primitive (but not boolean), then I should be able to put "+" between them and it be valid Java code.

Possibly useful code: Reflect6.java has this design reflect6(return instance getSetInsertOrDelete location size value)

Overrides:
toJavaCode in class CS

parseDoubleFromNaturalLanguage

public static double parseDoubleFromNaturalLanguage(java.lang.String natLangNumber)
                                             throws NatLangException
example: "10 million and fiftyseven point 9"

Throws:
NatLangException