au.com.zip.cs
Class HierUtil

java.lang.Object
  extended by au.com.zip.cs.HierUtil

public class HierUtil
extends Object

A bunch of operations for use by implementations of Hier.

Author:
Cameron Simpson <cs@zip.com.au> 5may2003

Method Summary
static MapHier edit(MapHier h)
          Run the external editor on this MapHier and return a new MapHier parsed from the edited text.
static ParseException mkPE(String err, Reader tail)
          Return a new ParseException.
static ParseException mkPE(String err, String tail)
          Return a new ParseException.
static MapHier newPathHier(File path)
          Return a new MapHier attached to the specified file or directory.
static MapHier newPathHier(String path)
          Return a new MapHier attached to the specified file or directory.
static Hier readEntity(PushbackReader r)
          Read a Hier entity from the supplied PushbackReader.
static MapHier saveHier(File path, MapHier hier, boolean merge)
          Save a MapHier to a path, possibly merging with the existing content, and return a new MapHier attached to the supplied path.
static Hier toHier(Object o)
          Convert an arbitrary Object to a Hier.
static ListHier toListHier(List l)
          Produce a ListHier from a List.
static MapHier toMapHier(Map m)
          Produce a MapHier from a Map.
static String transcribe(Hier h, int indent)
          Return a single line String transcription of this object.
static int transcribe(Writer w, Hier h, int indent)
          Transcribe a Hier.
static int writeMap(Writer w, MapHier h, int indent)
          Transcribe a MapHier.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

edit

public static final MapHier edit(MapHier h)
                          throws IOException,
                                 ParseException
Run the external editor on this MapHier and return a new MapHier parsed from the edited text.

Parameters:
h - the MapHier to edit
Returns:
the new MapHier
Throws:
IOException
ParseException
See Also:
Editor

newPathHier

public static final MapHier newPathHier(File path)
                                 throws IOException,
                                        ParseException
Return a new MapHier attached to the specified file or directory.

Parameters:
path - the file or directory reference
Returns:
the new MapHier
Throws:
IOException
ParseException

newPathHier

public static final MapHier newPathHier(String path)
                                 throws IOException,
                                        ParseException
Return a new MapHier attached to the specified file or directory.

Parameters:
path - the file or directory reference
Returns:
the new MapHier
Throws:
IOException
ParseException

saveHier

public static final MapHier saveHier(File path,
                                     MapHier hier,
                                     boolean merge)
                              throws IOException
Save a MapHier to a path, possibly merging with the existing content, and return a new MapHier attached to the supplied path.
Note: the merge/overwrite behaviour only extends to the directory/file hierachy on disc. The contents of individual files are completely replaced.

Parameters:
path - the path
hier - the MapHier to save
merge - whther to merge or replace the existing content
Returns:
the new MapHier attached to the path
Throws:
IOException

readEntity

public static final Hier readEntity(PushbackReader r)
                             throws IOException,
                                    ParseException
Read a Hier entity from the supplied PushbackReader.

Parameters:
r - the Reader
Returns:
the new Hier
Throws:
IOException
ParseException

transcribe

public static final String transcribe(Hier h,
                                      int indent)
Return a single line String transcription of this object.

Parameters:
h - the Hier to transcribe
indent - the prevailing indent preceeding this output, or -1 for single line output
Returns:
the transcribed String

transcribe

public static int transcribe(Writer w,
                             Hier h,
                             int indent)
                      throws IOException
Transcribe a Hier.

Parameters:
w - the Writer to which to transcribe the data
h - the Hier
indent - the prevailing indent preceeding this output, or -1 for single line output
Returns:
the width of the last line of output
Throws:
IOException

writeMap

public static final int writeMap(Writer w,
                                 MapHier h,
                                 int indent)
                          throws IOException
Transcribe a MapHier.

Parameters:
w - the Writer to which to transcribe the data
h - the MapHier
indent - the prevailing indent preceeding this output, or -1 for single line output
Returns:
the incremental width of the last line of output
Throws:
IOException

toHier

public static final Hier toHier(Object o)
Convert an arbitrary Object to a Hier.

Parameters:
o - the object
Returns:
the Hier

toMapHier

public static final MapHier toMapHier(Map m)
Produce a MapHier from a Map.

Parameters:
m - the map
Returns:
the MapHier

toListHier

public static final ListHier toListHier(List l)
Produce a ListHier from a List.

Parameters:
l - the list
Returns:
the ListHier

mkPE

public static ParseException mkPE(String err,
                                  String tail)
Return a new ParseException.

Parameters:
err - the complaint
tail - the remaining text where the error was encountered
Returns:
an explainatory ParsException

mkPE

public static ParseException mkPE(String err,
                                  Reader tail)
                           throws IOException
Return a new ParseException.

Parameters:
err - the complaint
tail - a Reader positioned at the remaining text where the error was encountered
Returns:
an explainatory ParsException
Throws:
IOException