org.hecl
Class ListThing

java.lang.Object
  extended by org.hecl.ListThing
All Implemented Interfaces:
RealThing

public class ListThing
extends java.lang.Object
implements RealThing

The ListThing class implements lists, storing them internally as a Vector.

Version:
1.0
Author:
David N. Welton

Field Summary
protected  java.util.Vector val
           
 
Constructor Summary
ListThing()
          Creates a new, empty ListThing instance.
ListThing(java.lang.String s)
          Attempts to create a new ListThing instance from a string.
ListThing(java.util.Vector v)
          Creates a new ListThing instance from a vector.
 
Method Summary
static java.lang.StringBuffer appendListItem(java.lang.StringBuffer buf, Thing thing)
           
static Thing buildCmdList(Thing cmd, Thing[] args)
          The buildCmdList method takes a Thing, treats it as a list, and adds arguments to it from the args array.
static Thing create(java.util.Vector v)
          create allocates and returns a new ListThing typed Thing.
 RealThing deepcopy()
          deepcopy copies a list and all of its elements.
static java.util.Vector get(Thing thing)
          get attempts to transform the given Thing into a List, and return its Vector value.
static Thing[] getArray(Thing thing)
          getArray attempts to transform the given Thing into a List, and return it as an array of Things.
 java.lang.String getStringRep()
          getStringRep returns a string representation of a ListThing.
static Thing stringSplit(java.lang.String str, java.lang.String splitstr)
          The stringSplit method takes a string and splits it according to another string,
 java.lang.String thingclass()
           
static java.lang.String toListString(Thing thing)
          toListString transforms list elements into the string form {foo bar} if the element contains a space.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

val

protected java.util.Vector val
Constructor Detail

ListThing

public ListThing()
Creates a new, empty ListThing instance.


ListThing

public ListThing(java.util.Vector v)
Creates a new ListThing instance from a vector.

Parameters:
v - a Vector value

ListThing

public ListThing(java.lang.String s)
          throws HeclException
Attempts to create a new ListThing instance from a string. May fail if the string can't be parsed into a list.

Parameters:
s - a String value
Throws:
HeclException - if an error occurs
Method Detail

create

public static Thing create(java.util.Vector v)
create allocates and returns a new ListThing typed Thing.

Parameters:
v - a Vector value. Note that the Vector must contain Things, rather than, say, int's or Strings or something else!
Returns:
a Thing value

thingclass

public java.lang.String thingclass()
Specified by:
thingclass in interface RealThing

get

public static java.util.Vector get(Thing thing)
                            throws HeclException
get attempts to transform the given Thing into a List, and return its Vector value.

Parameters:
thing - a Thing value
Returns:
a Vector value
Throws:
HeclException - if an error occurs

getArray

public static Thing[] getArray(Thing thing)
                        throws HeclException
getArray attempts to transform the given Thing into a List, and return it as an array of Things.

Parameters:
thing - a Thing value
Returns:
a Thing[] value
Throws:
HeclException - if an error occurs

deepcopy

public RealThing deepcopy()
                   throws HeclException
deepcopy copies a list and all of its elements.

Specified by:
deepcopy in interface RealThing
Returns:
a RealThing value
Throws:
HeclException

toListString

public static java.lang.String toListString(Thing thing)
toListString transforms list elements into the string form {foo bar} if the element contains a space.

Parameters:
thing - a Thing value
Returns:
a String value

appendListItem

public static java.lang.StringBuffer appendListItem(java.lang.StringBuffer buf,
                                                    Thing thing)

getStringRep

public java.lang.String getStringRep()
getStringRep returns a string representation of a ListThing.

Specified by:
getStringRep in interface RealThing
Returns:
a String value

stringSplit

public static Thing stringSplit(java.lang.String str,
                                java.lang.String splitstr)
The stringSplit method takes a string and splits it according to another string,

Parameters:
str - a String value
splitstr - a String value
Returns:
a Thing value

buildCmdList

public static Thing buildCmdList(Thing cmd,
                                 Thing[] args)
                          throws HeclException
The buildCmdList method takes a Thing, treats it as a list, and adds arguments to it from the args array. The whole thing is returned and is ready to be executed by interp.eval(). This is a convenience function utilized in various callbacks throughout the code.

Parameters:
cmd - a Thing value
args - an array of Thing values
Returns:
a Thing value
Throws:
HeclException - if an error occurs