sdsi.sexp
Class SexpList

java.lang.Object
  |
  +--sdsi.sexp.Sexp
        |
        +--sdsi.sexp.SexpList
All Implemented Interfaces:
java.io.Serializable

public class SexpList
extends Sexp

This class is used to represent S-Expressions which are not simple byte-strings. That is, they are lists of other S-Expressions.

Author:
Alexander Morcos, Sameer Ajmani
See Also:
Sexp, Serialized Form

Field Summary
(package private)  java.util.Vector elements
           
 
Fields inherited from class sdsi.sexp.Sexp
base64Digit, hexDigit
 
Constructor Summary
SexpList(java.io.PushbackInputStream p)
          Create a new SexpList by parsing an S-Expression out of the input stream.
SexpList(Sexp[] expressions)
          Create a new SexpList containing all the Sexp's given in the array.
 
Method Summary
 boolean allElementsStrings()
          Tests whether all the elements in this SexpList are simple strings or if there is a list.
 Sexp[] arrayOfElements()
          Puts all the Sexp's in the list into an array of the correct size and returns it
 Sexp elementAt(int index)
          Returns the Sexp located at the given index.
 java.util.Enumeration elements()
          Returns an enumeration of the elements in the SexpList.
 int getCanonLen()
          Calculates the length of the canonical representation of this S-expression.
 byte[] getCanonRep()
          Generates the canonical representation of this S-expression.
(package private)  int getReadableLen()
           
 java.lang.String getType()
          Returns a string representing the first elemenent in the list.
 int size()
          Returns the number of elements in this list
 java.lang.String toReadableString(int offset, int width, int last)
          Returns a readable string representation of this S-expression.
 
Methods inherited from class sdsi.sexp.Sexp
base64ToInt, base64ToOctet, isBase64Digit, isDecimalDigit, isHexDigit, isTokenChar, isWhiteSpace, parse, toString, toString, toVerbatimString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

elements

java.util.Vector elements
Constructor Detail

SexpList

public SexpList(Sexp[] expressions)
Create a new SexpList containing all the Sexp's given in the array.

Parameters:
expressions - the array of expressions to be contained in the SexpList

SexpList

public SexpList(java.io.PushbackInputStream p)
         throws SexpException
Create a new SexpList by parsing an S-Expression out of the input stream. Assumes that we have already parsed the first parenthesis of a list S-Expression.

Parameters:
p - the PushbackInputStream which contains the bytes of an S-Expression.
Throws:
SexpException - if there was a problem parsing the S-Expression
Method Detail

getType

public java.lang.String getType()
Returns a string representing the first elemenent in the list. This string is equal to the ASCII translation of the content of the first Sexp in the list. If the first Sexp is a list then the function returns "list"

Returns:
the first string in the list or "list"

getCanonLen

public int getCanonLen()
Description copied from class: Sexp
Calculates the length of the canonical representation of this S-expression. @return the length of the canonical representation.

Specified by:
getCanonLen in class Sexp

getCanonRep

public byte[] getCanonRep()
Description copied from class: Sexp
Generates the canonical representation of this S-expression.

Specified by:
getCanonRep in class Sexp
Returns:
a byte array containing exactly the canonical representation.

getReadableLen

int getReadableLen()
Specified by:
getReadableLen in class Sexp

toReadableString

public java.lang.String toReadableString(int offset,
                                         int width,
                                         int last)
Description copied from class: Sexp
Returns a readable string representation of this S-expression. Given format parameters, returns a nicely formatted readable representation of this S-expression, using base-64 and hexadecimal representation to handle unprintable characters.

Specified by:
toReadableString in class Sexp
Parameters:
offset - the number of spaces that should appear before every line of the string.
width - the total width that the string should take up in characters.
last - the number of spaces that should be left at the end of every line (for possible closing parens).
Returns:
a nicely formatted string representation of this S-expression.

elementAt

public Sexp elementAt(int index)
Returns the Sexp located at the given index. This is used when we know that we want to get to the element at a particular location in the list

Parameters:
index - the index of the Sexp to return
Returns:
the Sexp located at index

size

public int size()
Returns the number of elements in this list

Returns:
the number of Sexp's in this SexpList.

elements

public java.util.Enumeration elements()
Returns an enumeration of the elements in the SexpList. These will need to be cast to Sexp's.

Returns:
an enumberation of the elements in the SexpList.

arrayOfElements

public Sexp[] arrayOfElements()
Puts all the Sexp's in the list into an array of the correct size and returns it

Returns:
an array of Sexp's from the list

allElementsStrings

public boolean allElementsStrings()
Tests whether all the elements in this SexpList are simple strings or if there is a list.

Returns:
false if there is a SexpList inside this SexpList, true otherwise.