net.ponder2
Class Path

java.lang.Object
  extended by net.ponder2.Path
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Iterable<java.lang.String>

public class Path
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>, java.lang.Cloneable

A path manipulation library. Handles Unix style path names and can index separate parts of the path, extract parts of the path and normalise pathnames.

Version:
$Id: Path.java,v 1.3 2005/10/01 14:35:03 kpt Exp $
Author:
Kevin Twidle

Field Summary
static java.lang.String DOT
          Default string for the current directory/domain
static java.lang.String DOTDOT
          Default string for a parent directory/domain
static java.lang.String ROOT
          Default string for the root
static java.lang.String SLASH
          Default string for a path separator
 
Constructor Summary
Path(Path path)
          creates a new Path as a copy of another Path
Path(Path path, java.lang.String extra)
          creates a new Path as a concatenation of a Path and a String joined with a SLASH
Path(java.lang.String path)
          creates a new Path based on a String value
 
Method Summary
 void add(java.lang.String path)
          adds a component to the end of the Path.
 java.lang.String child()
          Returns the child part of the Path as a String
 void clear()
          clears the content of the Path
 java.lang.Object clone()
           
 java.lang.String head(int index)
          returns beginning n elements of the path.
 boolean isAbsolute()
          Checks whether the path starts from the root
 boolean isComplete()
          Checks whether the path is complete or goes up from the current element
 boolean isRelative()
          Checks whether the path starts from the current domain
 java.util.Iterator<java.lang.String> iterator()
           
 Path parent()
          Returns a new Path being the parent of the current one
 void set(java.lang.String path)
          sets the Path to be the same as a String
 int size()
          returns the number of elements in the path
 java.lang.String subpath(int start)
          returns a subset of the path from the n'th element to the end.
 java.lang.String subpath(int start, int end)
          returns a subset of the path indexed by the start element and the end element
 java.lang.String tail(int index)
          returns the last n elements of the Path.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DOT

public static final java.lang.String DOT
Default string for the current directory/domain

See Also:
Constant Field Values

SLASH

public static final java.lang.String SLASH
Default string for a path separator

See Also:
Constant Field Values

ROOT

public static final java.lang.String ROOT
Default string for the root

See Also:
Constant Field Values

DOTDOT

public static final java.lang.String DOTDOT
Default string for a parent directory/domain

See Also:
Constant Field Values
Constructor Detail

Path

public Path(java.lang.String path)
creates a new Path based on a String value

Parameters:
path - the String pathname

Path

public Path(Path path)
creates a new Path as a copy of another Path

Parameters:
path - the Path to be copied

Path

public Path(Path path,
            java.lang.String extra)
creates a new Path as a concatenation of a Path and a String joined with a SLASH

Parameters:
path - the first component of the pathname
extra - the last component of the pathname
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

clear

public void clear()
clears the content of the Path


isComplete

public boolean isComplete()
Checks whether the path is complete or goes up from the current element

Returns:
true if the path is complete

isRelative

public boolean isRelative()
Checks whether the path starts from the current domain

Returns:
true if the path is relative

isAbsolute

public boolean isAbsolute()
Checks whether the path starts from the root

Returns:
true if the path starts from the root

iterator

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

parent

public Path parent()
Returns a new Path being the parent of the current one

Returns:
the Path of the parent

child

public java.lang.String child()
Returns the child part of the Path as a String

Returns:
the child of the Path

set

public void set(java.lang.String path)
sets the Path to be the same as a String

Parameters:
path - the new full pathname

add

public void add(java.lang.String path)
adds a component to the end of the Path. A SLASH is also added as a Separator if necessary.

Parameters:
path -

size

public int size()
returns the number of elements in the path

Returns:
the number of elements in the path

head

public java.lang.String head(int index)
returns beginning n elements of the path. If the index is negative, returns all but the first n elements.

Parameters:
index - the number of elements to return
Returns:
the required part of the path as a string

tail

public java.lang.String tail(int index)
returns the last n elements of the Path. If the index is negative, returns all but the last n elements.

Parameters:
index - the number of elements to return
Returns:
the beginning of the Path as a String

subpath

public java.lang.String subpath(int start)
returns a subset of the path from the n'th element to the end.

Parameters:
start - the first element to copy
Returns:
a string containing the subset of the Path

subpath

public java.lang.String subpath(int start,
                                int end)
returns a subset of the path indexed by the start element and the end element

Parameters:
start - the index of the first element of the substring
end - the index of the last element of the substring
Returns:
the substring

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2008 Imperial College. All Rights Reserved.