com.townleyenterprises.common
Class Path

java.lang.Object
  extended bycom.townleyenterprises.common.Path

public final class Path
extends java.lang.Object

This class provides methods equivalent to the UNIX commands dirname and basename based on arbitrary path separators.

Since:
2.1
Version:
$Id: Path.java,v 1.2 2004/07/29 18:33:58 atownley Exp $
Author:
Andrew S. Townley

Method Summary
static java.lang.String basename(java.lang.String path, java.lang.String pd)
          This version of the basename command exposes just the path and the delimiter.
static java.lang.String basename(java.lang.String path, java.lang.String pd, java.lang.String suffix)
          This method is used to strip the path name and optional suffix from a given delimited string representing some kind of path.
static java.lang.String classname(java.lang.String name)
          This method is used to remove the package name from a Java class.
static java.lang.String dirname(java.lang.String path)
          This method provides the exact functionality of the UNIX dirname command.
static java.lang.String getExtension(java.lang.String s)
          This method is used to get the "file extension" from the string.
static java.lang.String pathname(java.lang.String path, java.lang.String pd)
          This method returns the path portion of the delimited string similar to the UNIX dirname command, but for arbitrary delimiters.
static java.lang.String stripExtension(java.lang.String s)
          This method is used to strip the trailing "file extension" from the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

basename

public static java.lang.String basename(java.lang.String path,
                                        java.lang.String pd,
                                        java.lang.String suffix)
This method is used to strip the path name and optional suffix from a given delimited string representing some kind of path. It is useful for dealing with package names as well as regular filesystem paths.

Parameters:
path - the path string
pd - the path delimiter
suffix - the suffix to remove
Returns:
the base path component

basename

public static java.lang.String basename(java.lang.String path,
                                        java.lang.String pd)
This version of the basename command exposes just the path and the delimiter. Suffix stripping is not supported.

Parameters:
path - the path string
pd - the path delimiter
Returns:
the base path component

classname

public static java.lang.String classname(java.lang.String name)
This method is used to remove the package name from a Java class.

Parameters:
name - the Java class name
Returns:
the class name

pathname

public static java.lang.String pathname(java.lang.String path,
                                        java.lang.String pd)
This method returns the path portion of the delimited string similar to the UNIX dirname command, but for arbitrary delimiters.

Parameters:
path - the path string
pd - the path delimiter
Returns:
the path portion of the path

dirname

public static java.lang.String dirname(java.lang.String path)
This method provides the exact functionality of the UNIX dirname command. All of the non-directory suffix is stripped from the path, delimited by the '/' character.

Parameters:
path - the path string
Returns:
the directory name or "." if the path does not have a directory.

stripExtension

public static java.lang.String stripExtension(java.lang.String s)
This method is used to strip the trailing "file extension" from the given string.

Parameters:
s - the string
Returns:
the base of s

getExtension

public static java.lang.String getExtension(java.lang.String s)
This method is used to get the "file extension" from the string.

Parameters:
s - the string
Returns:
the extension or an empty string if none


Copyright © 2002-2004, Andrew S. Townley and Townley Enterprises. All Rights Reserved.
This project is hosted on http://te-code.sourceforge.net.