codesimian
Class NumberStack

java.lang.Object
  extended by java.lang.Number
      extended by codesimian.NumberStack
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
NumberStack.NeverEmpty

Deprecated.

@Deprecated
public class NumberStack
extends java.lang.Number

This class became almost obsolete when CS stopped being a subclass of Number, although CS still can be cast to Number, but often the dynamic properties are lost.

A stack of Numbers. Number functions return the same call on the top value.

WARNING: Be careful not to put this NumberStack inside itsself, or some other cycle. It does not have infinite-loop-protection (CSs do), but if it contains only CSs (CS extends Number) and they have that protection option on, then they can stop the infinite-loops.

NumberStack makes the syntax for specifying complex OPTIONS easy. Just use a Number variable and set its first value in my constructor. NumberStack is often used as a stack of default values for a certain option. Others can push and pop their own options without damaging anyone else's options.

If you do this: Number n = new NumberStack(...),
instead of: NumberStack n = new NumberStack(...),
then: users of your class might not know it is a NumberStack,
and they can simply replace it with new Integer(5) for example.
If they suspect its a NumberStack, they can check its type and push/pop.
It has almost the simplicity of a primitive type, but supports complex behavior.

Example:
Number defaultSize = new NumberStack(7.3);
int size = defaultSize.intValue(); //7, not 7.3
((NumberStack)defaultSize) .push((byte)3);
. //defaultSize returns 3
. CS complexValue = CS.compile("*(?xSize ?ySize ?zSize)"); . ((NumberStack)defaultSize) .push(complexValue);
. . //defaultSize returns complexValue.doubleValue() or .intValue() etc
. ((NumberStack)defaultSize) .pop();
. //defaultSize returns 3
((NumberStack)defaultSize) .pop();
//defaultSize returns 7.3

See Also:
Serialized Form

Nested Class Summary
static class NumberStack.NeverEmpty
          Deprecated. replaces pop() with peek() if pop() would empty the stack.
 
Field Summary
protected  java.util.List<java.lang.Number> stack
          Deprecated. Default: new java.util.ArrayList(4)
 
Constructor Summary
NumberStack()
          Deprecated.  
NumberStack(byte pushMe)
          Deprecated.  
NumberStack(double pushMe)
          Deprecated.  
NumberStack(float pushMe)
          Deprecated.  
NumberStack(int pushMe)
          Deprecated.  
NumberStack(long pushMe)
          Deprecated.  
NumberStack(java.lang.Number pushMe)
          Deprecated.  
NumberStack(short pushMe)
          Deprecated.  
 
Method Summary
 byte byteValue()
          Deprecated. returns the byte value of the top Number on this stack
 double doubleValue()
          Deprecated.  
 float floatValue()
          Deprecated.  
 int intValue()
          Deprecated.  
 long longValue()
          Deprecated.  
 java.lang.Number peek()
          Deprecated.  
 java.lang.Number pop()
          Deprecated.  
 void push(byte pushMe)
          Deprecated.  
 void push(double pushMe)
          Deprecated.  
 void push(float pushMe)
          Deprecated.  
 void push(int pushMe)
          Deprecated.  
 void push(long pushMe)
          Deprecated.  
 void push(java.lang.Number pushMe)
          Deprecated.  
 void push(short pushMe)
          Deprecated.  
 short shortValue()
          Deprecated.  
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stack

protected java.util.List<java.lang.Number> stack
Deprecated. 
Default: new java.util.ArrayList(4)

Constructor Detail

NumberStack

public NumberStack()
Deprecated. 

NumberStack

public NumberStack(java.lang.Number pushMe)
Deprecated. 

NumberStack

public NumberStack(byte pushMe)
Deprecated. 

NumberStack

public NumberStack(short pushMe)
Deprecated. 

NumberStack

public NumberStack(int pushMe)
Deprecated. 

NumberStack

public NumberStack(long pushMe)
Deprecated. 

NumberStack

public NumberStack(float pushMe)
Deprecated. 

NumberStack

public NumberStack(double pushMe)
Deprecated. 
Method Detail

push

public void push(java.lang.Number pushMe)
Deprecated. 

push

public void push(byte pushMe)
Deprecated. 

push

public void push(short pushMe)
Deprecated. 

push

public void push(int pushMe)
Deprecated. 

push

public void push(long pushMe)
Deprecated. 

push

public void push(float pushMe)
Deprecated. 

push

public void push(double pushMe)
Deprecated. 

peek

public java.lang.Number peek()
Deprecated. 

pop

public java.lang.Number pop()
Deprecated. 

byteValue

public byte byteValue()
Deprecated. 
returns the byte value of the top Number on this stack

Overrides:
byteValue in class java.lang.Number

shortValue

public short shortValue()
Deprecated. 
Overrides:
shortValue in class java.lang.Number

intValue

public int intValue()
Deprecated. 
Specified by:
intValue in class java.lang.Number

longValue

public long longValue()
Deprecated. 
Specified by:
longValue in class java.lang.Number

floatValue

public float floatValue()
Deprecated. 
Specified by:
floatValue in class java.lang.Number

doubleValue

public double doubleValue()
Deprecated. 
Specified by:
doubleValue in class java.lang.Number