com.partnersoft.data
Class PathBuilder

java.lang.Object
  extended by com.partnersoft.data.PathBuilder
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>

public class PathBuilder
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>

A builder class for Path.

Since Paths are immutable, you have to construct them in one go and not change them. This is a mutable path; it has methods for building a Path from scratch, or modifying an existing Path structure.

Copyright 2006 Partner Software, Inc.

Version:
$Id: PathBuilder.java,v 1.1.2.1 2006-07-21 20:54:47 russell Exp $
Author:
Paul Reavis

Constructor Summary
PathBuilder()
          Creates a builder initialized with an empty, relative Path.
PathBuilder(Path source)
          Creates a builder based upon the given Path.
PathBuilder(PathBuilder nother)
          Creates a builder with the same contents as the given builder.
PathBuilder(java.lang.String pathString)
          Creates a builder and initializes it by parsing the given path string.
PathBuilder(java.lang.String[] parts, boolean absolute)
          Creates a builder initialized with the given parts and absoluteness
 
Method Summary
 void invert()
          Inverts the path, so that the parts are in reverse order.
 boolean isAbsolute()
          Is this path absolute?
 java.util.Iterator<java.lang.String> iterator()
           
 java.lang.String pop()
          Removes and returns the last part of the path.
 void push(java.lang.String name)
          Adds a part to the path.
 void pushArray(java.lang.String[] parts)
          Treats the given array as a path, and pushes all parts just like pushPath(Path).
 void pushPath(Path nother)
          Pushes all parts of the given Path onto this one.
 void setAbsolute(boolean tizit)
          Set whether path is absolute.
 java.lang.String[] toArray()
          Returns an array copy of the path's parts.
 Path toPath()
          The actual goal of building a path is to create a path.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PathBuilder

public PathBuilder()
Creates a builder initialized with an empty, relative Path.


PathBuilder

public PathBuilder(Path source)
Creates a builder based upon the given Path.

Parameters:
source - path to start with

PathBuilder

public PathBuilder(PathBuilder nother)
Creates a builder with the same contents as the given builder.

Parameters:
nother - builder to copy

PathBuilder

public PathBuilder(java.lang.String pathString)
Creates a builder and initializes it by parsing the given path string.

Parameters:
pathString - string representation of initial path for builder

PathBuilder

public PathBuilder(java.lang.String[] parts,
                   boolean absolute)
Creates a builder initialized with the given parts and absoluteness

Parameters:
parts - parts of the path
absolute - true if an absolute path
Method Detail

toPath

public Path toPath()
The actual goal of building a path is to create a path. This does so.


push

public void push(java.lang.String name)
Adds a part to the path. Canonicalizes automatically, eliminating ".", resolving embedded ".." by popping. Leaves ".." parts in at the top level if it's not an absolute path. If absolute, ".." entries that would go above the root cause an IllegalArgumentException.

Parameters:
name - part name to add to the path

pop

public java.lang.String pop()
Removes and returns the last part of the path.

Returns:
the last part of the path.

pushPath

public void pushPath(Path nother)
Pushes all parts of the given Path onto this one. If the path is absolute, replaces the current path. Resolves any ".." or "." parts just as push() does.

Parameters:
nother - path to push onto currently built path

pushArray

public void pushArray(java.lang.String[] parts)
Treats the given array as a path, and pushes all parts just like pushPath(Path).

Parameters:
parts -

isAbsolute

public boolean isAbsolute()
Is this path absolute?

Returns:
true if path is absolute

setAbsolute

public void setAbsolute(boolean tizit)
Set whether path is absolute.

Parameters:
tizit - true if path is absolute

toArray

public java.lang.String[] toArray()
Returns an array copy of the path's parts.


iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>

invert

public void invert()
Inverts the path, so that the parts are in reverse order. Handy for when you're building a path from the bottom-up instead of the top-down.