Purple Code

com.purpletech.util
Class Path

java.lang.Object
  |
  +--com.purpletech.util.Path

public class Path
extends java.lang.Object

File name parser. Immutable. Always uses '/' as separator. Directories must always end with '/' or they're considered files, with possible bad effect wrt creating relative paths and figuring out parents.

 path = "/foo/bar/baz.gif" ->
 parent = "/foo/bar/"
 name = "baz.gif"
 base = "baz"
 ext = "gif"
 


Constructor Summary
Path(java.io.File f)
          make a new path from the given File.
Path(Path f, java.lang.String s)
          make a new path relative to the given path
Path(java.lang.String fullpath)
          make a new path.
 
Method Summary
 java.lang.String getBase()
           
 java.lang.String getExt()
           
 java.lang.String getName()
           
 java.lang.String getParent()
           
 java.lang.String getPath()
           
 java.lang.String getPathTo(Path target)
          Get a string representing the path from this path to the given path (or rather, from the directory of this path)
 java.lang.String getPathTo(java.lang.String target)
           
protected  void init(java.lang.String fullpath)
           
 boolean isAbsolute()
           
 boolean isDirectory()
           
static void main(java.lang.String[] args)
           
 boolean makeUnique(java.io.File dir)
          make a unique file name in a given directory
 Path toDirectory()
           
 java.io.File toFile()
           
 java.lang.String toParts()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Path

public Path(Path f,
            java.lang.String s)
     throws BadPathException
make a new path relative to the given path


Path

public Path(java.io.File f)
     throws BadPathException
make a new path from the given File. Does the right thing wrt directory and slash.


Path

public Path(java.lang.String fullpath)
     throws BadPathException
make a new path. Parameter can be absolute or relative. Cannot have more "../" than preceding directories, or it throws a BadPathException. Removes redundant "../foo"s and so forth (see FileUtils.fixPath).

Method Detail

init

protected void init(java.lang.String fullpath)
             throws BadPathException
BadPathException

getPath

public java.lang.String getPath()

getParent

public java.lang.String getParent()

getName

public java.lang.String getName()

getBase

public java.lang.String getBase()

getExt

public java.lang.String getExt()

isDirectory

public boolean isDirectory()

isAbsolute

public boolean isAbsolute()

getPathTo

public java.lang.String getPathTo(java.lang.String target)
                           throws BadPathException
BadPathException

getPathTo

public java.lang.String getPathTo(Path target)
Get a string representing the path from this path to the given path (or rather, from the directory of this path)

e.g. from "foo/bar/com/jguru/meats" to "foo/bar/com/microsoft/vegetables" => "../../microsoft/vegetables"

Does the right thing (hopefully) with file-to-directory and so forth

Parameters:
target - another path

makeUnique

public boolean makeUnique(java.io.File dir)
make a unique file name in a given directory


toString

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

toParts

public java.lang.String toParts()

toDirectory

public Path toDirectory()
                 throws BadPathException
BadPathException

toFile

public java.io.File toFile()

main

public static void main(java.lang.String[] args)
                 throws BadPathException
BadPathException

Documentation generated March 5 2003