net.sf.cotta
Class TPath

java.lang.Object
  extended by net.sf.cotta.TPath
All Implemented Interfaces:
java.lang.Comparable<TPath>

public class TPath
extends java.lang.Object
implements java.lang.Comparable<TPath>

An object presentation of path to mainly used by the implemenation of Cotta classes. The methods on TPath has been exposed through TFile and TDirectory


Method Summary
 int compareTo(TPath that)
          Compare two path by comparing each elements.
 boolean equals(java.lang.Object o)
           
 int hashCode()
           
 boolean isChildOf(TPath path)
          Check if current path is the child of the given path.
 boolean isRelative()
          Check is the current path is a relative path or absolute path
 TPath join(java.lang.String name)
          Join with an pat element to form a new path.
 TPath join(TPath path)
          Join with another relative path.
 java.lang.String lastElementName()
          The name of the last element, used by TFile and TDirectory to get the name
 TPath parent()
          The path of the parent, used by TFile and TDirectory to get the parent
static TPath parse(java.lang.String pathString)
          Parses a path string into a TPath object.
 TPath pathFrom(TPath path)
          Dericve the relative path from the other path, to be used by TFile and TDirectory
 java.lang.String toPathString()
           
 java.lang.String toPathString(PathSeparator pathSeparator)
           
 java.lang.String toString()
          String representation of the path.
 java.lang.String toSystemPathString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

lastElementName

public java.lang.String lastElementName()
The name of the last element, used by TFile and TDirectory to get the name

Returns:
the name of the last element
See Also:
TEntry.name(), TEntry.name()

parent

public TPath parent()
The path of the parent, used by TFile and TDirectory to get the parent

Returns:
parent path
See Also:
TEntry.parent(), TEntry.parent()

join

public TPath join(java.lang.String name)
Join with an pat element to form a new path. Used by TDirectory to get subdirectory or file

Parameters:
name - The name of the path element to join
Returns:
The resulting path under current path
See Also:
TDirectory.file(String), TDirectory.dir(String)

join

public TPath join(TPath path)
Join with another relative path. Used by TDirectory to get directory or file based on relative path

Parameters:
path - The relative path to join
Returns:
The result of the join.
Throws:
java.lang.IllegalArgumentException - if the path passed in is not a relative path
See Also:
TDirectory.file(TPath), TDirectory.dir(TPath)

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
String representation of the path. To get the path string understood by most other application please use toPathString()

Overrides:
toString in class java.lang.Object
Returns:
path string
See Also:
toPathString()

parse

public static TPath parse(java.lang.String pathString)
Parses a path string into a TPath object. Both '/' and '\' are treated as the file separator

Parameters:
pathString - The path string that represents the path
Returns:
The path object that match to the path string
Throws:
java.lang.IllegalArgumentException - if the path string is null

toPathString

public java.lang.String toPathString()

toPathString

public java.lang.String toPathString(PathSeparator pathSeparator)

toSystemPathString

public java.lang.String toSystemPathString()

isChildOf

public boolean isChildOf(TPath path)
Check if current path is the child of the given path. This used by TFile and TDirectory to see if it is under another directory

Parameters:
path - The path to check to see if current path is its child
Returns:
true if current path is the child of the given path
See Also:
TEntry.isChildOf(TDirectory), TEntry.isChildOf(TDirectory)

isRelative

public boolean isRelative()
Check is the current path is a relative path or absolute path

Returns:
true if the current path is a relative path.

pathFrom

public TPath pathFrom(TPath path)
Dericve the relative path from the other path, to be used by TFile and TDirectory

Parameters:
path - The other path to derive relative path from
Returns:
The relative path from the other path

compareTo

public int compareTo(TPath that)
Compare two path by comparing each elements.

Specified by:
compareTo in interface java.lang.Comparable<TPath>
Parameters:
that - the other path
Returns:
comparing result