Parsing Engine

danbikel.parser
Class SymbolicCollectionWriter

java.lang.Object
  extended bydanbikel.parser.SymbolicCollectionWriter
All Implemented Interfaces:
Serializable

public class SymbolicCollectionWriter
extends Object
implements Serializable

Provides static methods to write out the contents of a Map or a Set in an S-expression format.

See Also:
Serialized Form

Method Summary
static String valueOf(Object obj)
          If the specified object is not an instance of a Sexp object but is an instance of a SexpConvertible object, then the value returned is the string representation of ((SexpConvertible)obj).toSexp(); otherwise, the value returned is that returned by String.valueOf(obj).
static void writeMap(Map map, Symbol name, Writer writer)
          Writes out the contents of map in an S-expression format.
static void writeMap(Map map, Writer writer)
          An alias for writeMap(map, null, writer).
static void writeSet(Set set, Symbol name, Writer writer)
          Writes out the contents of the specified set in an S-expression format.
static void writeSet(Set set, Symbol name, Writer writer, String sep)
          Writes out the contents of the specified set in an S-expression format.
static void writeSet(Set set, Writer writer)
          Writes the specified set to the specified writer (with no header).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeSet

public static void writeSet(Set set,
                            Symbol name,
                            Writer writer)
                     throws IOException
Writes out the contents of the specified set in an S-expression format. The S-expression will have the form
 (name (element1 element2 elementN))
 
or
 (element1 element2  ... elementN)
 
if the specified name is null, where elementi is the result of valueOf(Object) for an object found in the specified set, and where a single space character separates set elements.

Parameters:
set - the set to write out to the specified character writer
name - the name of the set, or null if the set is to be unnamed
writer - the character writer to which to output the specified set as an S-expression
Throws:
IOException

writeSet

public static void writeSet(Set set,
                            Symbol name,
                            Writer writer,
                            String sep)
                     throws IOException
Writes out the contents of the specified set in an S-expression format. The S-expression will have the form
 (name (element1 element2 elementN))
 
or
 (element1 element2  ... elementN)
 
if the specified name is null, where elementi is the result of valueOf(Object) for an object found in the specified set.

Parameters:
set - the set to write out to the specified character writer
name - the name of the set, or null if the set is to be unnamed
writer - the character writer to which to output the specified set as an S-expression
sep - the string to separate set elements
Throws:
IOException - if the specified writer throws an IOException during writing
IllegalArgumentException - if the specified separator string does not consist entirely of whitespace characters

writeSet

public static void writeSet(Set set,
                            Writer writer)
                     throws IOException
Writes the specified set to the specified writer (with no header). Synonymous with writeSet(set, null, writer).

Parameters:
set - the set whose elements are to be written to the specified writer
writer - the writer to which to write the specified set
Throws:
IOException - if there is a problem writing the elements of the specified set to the specified writer

writeMap

public static void writeMap(Map map,
                            Symbol name,
                            Writer writer)
                     throws IOException
Writes out the contents of map in an S-expression format. Each key-value pair is written on its own line as
 (name key value) 
where key is the result of calling valueOf(key) and value is the result of calling valueOf(value). If name is null, then the format will be
 (key value) 
If the value in a key-value pair is an instance of Set then each of that set's members is output in a space-separated list within parentheses; otherwise, the normal string representation of value is written.

Parameters:
map - the map to write out
name - the name to prepend to each key-value pair, or null if the key-value pairs are to be unnamed
writer - the output stream to write to
Throws:
IOException
See Also:
valueOf(Object)

writeMap

public static void writeMap(Map map,
                            Writer writer)
                     throws IOException
An alias for writeMap(map, null, writer).

Parameters:
map - the map to write out
writer - the output stream to write to
Throws:
IOException

valueOf

public static final String valueOf(Object obj)
If the specified object is not an instance of a Sexp object but is an instance of a SexpConvertible object, then the value returned is the string representation of ((SexpConvertible)obj).toSexp(); otherwise, the value returned is that returned by String.valueOf(obj).


Parsing Engine

Author: Dan Bikel.