nl.bluering
Class Expression

java.lang.Object
  |
  +--nl.bluering.Expression

public class Expression
extends java.lang.Object

Expressions are simple trees. It can be used for anything. An expression consists of an object o and zero or more subexpressions (children). It is common that the object is a string, but depending on your needs it can be something different. (it better be printable if you intend to print it. I can also disrecommend null pointers, but it is not forbidden:-) the problems are yours though).


Constructor Summary
Expression(java.lang.Object s, int ch)
          create an Expression with the object s and room for the given number of children.
 
Method Summary
 Expression add(Expression exp)
          Adds an Expression to this class as a child.
 int getc()
          Returns the number of children.
 java.lang.String getfunctionstring()
          return the primary object if it is a string.
 java.lang.Object getobject()
           
 java.lang.String getprototype()
          returns the primary string concatenated with the number of children. this is used to look up functions in hashtables.
 boolean isbasic()
          Returns if this is a basic function.
 boolean isfunction(java.lang.String f)
          returns true if the primary object of this Expression is a string that is equal to f.
 boolean isfunction(java.lang.String f, int children)
          returns true if the primary object of this Expression is a string that is equal to f,and the number of children is correct.
 void setobject(java.lang.Object o)
           
 java.lang.String toString()
          Converts the complete expression to a one-line string, including it's childs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Expression

public Expression(java.lang.Object s,
                  int ch)
create an Expression with the object s and room for the given number of children.
Parameters:
s - the object in this expression. Often a string
ch - the estimated number of children. You can give any value, regardless what number of children you will really add, but memory use is more efficient if it is correct. Note that -1 is allowed: it indicates that it came in in a notation that does not allow arguments: for instance "123" and "a" do not allow children, but "f()" does.
Method Detail

isfunction

public boolean isfunction(java.lang.String f)
returns true if the primary object of this Expression is a string that is equal to f.

isfunction

public boolean isfunction(java.lang.String f,
                          int children)
returns true if the primary object of this Expression is a string that is equal to f,and the number of children is correct. You can make children -1 to test for basicness.

getfunctionstring

public java.lang.String getfunctionstring()
return the primary object if it is a string. Otherwise it returns the cryptic string "__undisplayable__object__" (mostly useful for debugging purposes).

getprototype

public java.lang.String getprototype()
returns the primary string concatenated with the number of children. this is used to look up functions in hashtables.

isbasic

public boolean isbasic()
Returns if this is a basic function. A basic function does not allow arguments: for instance "123" and "a" do not allow children, but "f()" does.

add

public Expression add(Expression exp)
Adds an Expression to this class as a child.

getc

public int getc()
Returns the number of children.

getobject

public java.lang.Object getobject()

setobject

public void setobject(java.lang.Object o)

toString

public java.lang.String toString()
Converts the complete expression to a one-line string, including it's childs.
Overrides:
toString in class java.lang.Object