|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--sexp.BaseSexp
|
+--sexp.SList
This class implements the list-aspect of a SExpression. All S-Expressions are lists. A list's components are either:
This class is now able to take an S-Expression in its Advanced representation and construct an SList object from it, although it's not particularly good at it, even if it should be as good as Rivest's SEXP tool.
This class underwent some major changes from version 1.8, after which the toAdvanced() method changed return type from String to byte[].
NOTE II: Regarding serialization: an initial test showed that a SList with a transport size of 125 bytes expanded to 2016 bytes when serialized. This size includes all the internal hashtables and whatnots. Do we really want that? Why not implement the java.io.Serializable interface and provide the read-/writeObject methods, and let these write the list in transport format? Hmmm...
TODO: Straighten out javadoc see-references
SExpression,
Sexp| Field Summary | |
private static String |
__me
|
String |
byte_encoding
Encoding used when converting from a byte array to whatever. |
private static boolean |
debug
|
protected static String |
default_encoding
|
protected Hashtable |
hash
Hashtable that's created if needed. |
protected Vector |
list
The list is kept in a Vector object. |
String |
string_encoding
Encoding used when converting from a String to whatever. |
| Fields inherited from class sexp.BaseSexp |
__me |
| Fields inherited from interface sexp.SExpression |
versionString |
| Constructor Summary | |
SList()
Default constructor just initializes default values and stuff. |
|
SList(byte[] input)
Build list object from byte-arrayinput. |
|
SList(InputStream input)
Build list object from byte-arrayinput. |
|
SList(String input)
Build list object from String input. |
|
| Method Summary | |
SList |
add(BigInteger bi)
Add a BigInteger to the end of this list. |
SList |
add(byte[] ba)
Add a byte array to the end of this list. |
SList |
add(SExpression sexp)
Add an S-Expression object to the end of this list. |
SList |
add(String s)
Add a String object to the end of this list. |
Enumeration |
elements()
Return this' list elements as an Enumeration. |
Enumeration |
elementsOfListMatching(String regexp)
Recursively search this for the first sublist mathing the Regular Expression name. |
Enumeration |
elementsOfListNamed(String name)
Recursively search this for the first sublist starting with name. |
boolean |
equals(Object that)
See if this list is equal to the given list. |
SExpression |
fetchAt(int index)
Retrieve a indexed of S-Expressions from this list. |
void |
finalize()
|
void |
free()
Destructive resource deallocation. |
SList |
getListMatching(String regexp)
Recursively search list for first sublist which first element matches a regular expression. |
private void |
getListsMatching(gnu.regexp.RE re,
Vector matches,
boolean singlematch)
|
Vector |
getListsMatching(String regexp)
Recursively search list for any sublists which first element matches a regular expression. |
Vector |
getListsStartingWith(String name)
Recursively search list for any sublists starting with name. |
private void |
getListsStartingWith(String name,
Vector matches)
|
int |
indexOf(SExpression obj)
Searches for the first occurence of the given argument, starting at the beginning of this list. |
int |
indexOf(SExpression obj,
int index)
Searches for the first occurence of the given argument, beginning the search at the given index. |
void |
insertAt(SExpression obj,
int index)
Inserts the specified object as a component in this list at the specified index. |
boolean |
isList()
Returns true if this S-Expression is a list of simpler S-Expressions, or false if this object is an octet-string object. |
SExpression |
item(int index)
Retrieve a indexed of S-Expressions from this list. |
int |
lastIndexOf(SExpression obj)
Searches for the last occurence of the given argument. |
SList |
lookup(String name)
Recursively look up S-Expressions starting with name. |
int |
makeLookupHash()
Make lookup hashtable. |
SList |
nr_lookup(String name)
Non-recursively look up S-Expressions starting with name. |
private void |
readNew(InputStream input)
|
int |
size()
Number of S-Expressions in this list. |
| Methods inherited from class sexp.BaseSexp |
toAdvanced,
toAdvanced,
toCanonical,
toCanonical,
toString,
toTransport,
toTransport |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private static final String __me
protected static String default_encoding
public String string_encoding
public String byte_encoding
private static boolean debug
protected Vector list
protected Hashtable hash
makeLookupHash(),
SList#lookup()| Constructor Detail |
public SList()
public SList(InputStream input)
throws SexpException
input - byte-array input
public SList(byte[] input)
throws SexpException
input - byte-array input
public SList(String input)
throws SexpException
input - string input| Method Detail |
public void finalize()
throws Throwable
private void readNew(InputStream input)
throws IOException
public boolean isList()
public void free()
public boolean equals(Object that)
that - Object to compare this list with. If the object is of some
other class than sexp.SList, that's toString() method is called
and the comparison done agains this list's first element.public SList add(SExpression sexp)
System.out.println(new SList().add("Foo:").add(new
SList().add("Bar").add("871326".getBytes())).toAdvanced());
(Foo:
(Bar "871326"))
sexp - object to add to this list
public SList add(String s)
throws SexpException
s - String object to add to this list
public SList add(byte[] ba)
throws SexpException
ba - Byte array to add to this list.
public SList add(BigInteger bi)
throws SexpException
bi - BigInteger to add to this list.
public void insertAt(SExpression obj,
int index)
obj - SExpression object to insert into this listindex - index to insert object at
public int indexOf(SExpression obj,
int index)
obj - SExpression to look forindex - starting index (0 = first element)public int indexOf(SExpression obj)
obj - SExpression to look forpublic int lastIndexOf(SExpression obj)
obj - SExpression to look forpublic int size()
public SExpression fetchAt(int index)
public SExpression item(int index)
SList#fetchAt()public Enumeration elements()
public Vector getListsStartingWith(String name)
name - String to search for.SList#getListsMatching(),
SList#lookup()
private void getListsStartingWith(String name,
Vector matches)
public Enumeration elementsOfListNamed(String name)
name - String to search for.public Vector getListsMatching(String regexp)
name - Regular expression to use.SList#getListsStartingWith(),
SList#lookup()
private void getListsMatching(gnu.regexp.RE re,
Vector matches,
boolean singlematch)
public Enumeration elementsOfListMatching(String regexp)
name - String to search for.public SList getListMatching(String regexp)
name - Regular expression to use.SList#getListsStartingWith(),
SList#getListsMatching(),
SList#lookup()public int makeLookupHash()
TODO: keep first or last value if some key already exist in the hashtable? Currently we keep the first. This should prehaps be otherwise, or even configurable.
SList#lookup()public SList lookup(String name)
makeLookupHash(),
SList#getListsStartingWith(),
SList#getListsMatching()public SList nr_lookup(String name)
name - the name to look for.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||