|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A path is an ordered collection of string segments,
separated by a standard separator character, "/".
A path may also have a leading and/or a trailing separator.
Paths also be prefixed by an optional device id, which includes
the character(s) which separate the device id from the rest
of the path. For example, "C:" and "Server/Volume:" are typical
device ids.
A device independent path has null
for a device id.
Note that paths are value objects; all operations on paths return a new path; the path that is operated on is unscathed.
UNC paths are denoted by leading double-slashes such
as //Server/Volume/My/Path
. When a new path
is constructed all double-slashes are removed except those
appearing at the beginning of the path.
This interface is not intended to be implemented by clients.
Path
Field Summary | |
static char |
DEVICE_SEPARATOR
Device separator character constant ":" used in paths. |
static char |
SEPARATOR
Path separator character constant "/" used in paths. |
Method Summary | |
IPath |
addFileExtension(String extension)
Returns a new path which is the same as this path but with the given file extension added. |
IPath |
addTrailingSeparator()
Returns a path with the same segments as this path but with a trailing separator added. |
IPath |
append(IPath path)
Returns the canonicalized path obtained from the concatenation of the given path's segments to the end of this path. |
IPath |
append(String path)
Returns the canonicalized path obtained from the concatenation of the given string path to the end of this path. |
Object |
clone()
Returns a copy of this path. |
boolean |
equals(Object obj)
Returns whether this path equals the given object. |
String |
getDevice()
Returns the device id for this path, or null if this
path has no device id. |
String |
getFileExtension()
Returns the file extension portion of this path, or null if there is none. |
boolean |
hasTrailingSeparator()
Returns whether this path has a trailing separator. |
boolean |
isAbsolute()
Returns whether this path is an absolute path (ignoring any device id). |
boolean |
isEmpty()
Returns whether this path has no segments and is not a root path. |
boolean |
isPrefixOf(IPath anotherPath)
Returns whether this path is a prefix of the given path. |
boolean |
isRoot()
Returns whether this path is a root path. |
boolean |
isUNC()
Returns a boolean value indicating whether or not this path is considered to be in UNC form. |
boolean |
isValidPath(String path)
Returns whether the given string is syntactically correct as a path. |
boolean |
isValidSegment(String segment)
Returns whether the given string is valid as a segment in a path. |
String |
lastSegment()
Returns the last segment of this path, or null if it does not have any segments. |
IPath |
makeAbsolute()
Returns an absolute path with the segments and device id of this path. |
IPath |
makeRelative()
Returns a relative path with the segments and device id of this path. |
IPath |
makeUNC(boolean toUNC)
Return a new path which is the equivalent of this path converted to UNC form (if the given boolean is true) or this path not as a UNC path (if the given boolean is false). |
int |
matchingFirstSegments(IPath anotherPath)
Returns a count of the number of segments which match in this path and the given path (device ids are ignored), comparing in increasing segment number order. |
IPath |
removeFileExtension()
Returns a new path which is the same as this path but with the file extension removed. |
IPath |
removeFirstSegments(int count)
Returns a copy of this path with the given number of segments removed from the beginning. |
IPath |
removeLastSegments(int count)
Returns a copy of this path with the given number of segments removed from the end. |
IPath |
removeTrailingSeparator()
Returns a path with the same segments as this path but with a trailing separator removed. |
String |
segment(int index)
Returns the specified segment of this path, or null if the path does not have such a segment. |
int |
segmentCount()
Returns the number of segments in this path. |
String[] |
segments()
Returns the segments in this path in order. |
IPath |
setDevice(String device)
Returns a new path which is the same as this path but with the given device id. |
File |
toFile()
Returns a java.io.File corresponding to this path. |
String |
toOSString()
Returns a string representation of this path which uses the platform-dependent path separator defined by java.io.File . |
String |
toString()
Returns a string representation of this path, including its device id. |
IPath |
uptoSegment(int count)
Returns a copy of this path truncated after the given number of segments. |
Field Detail |
public static final char SEPARATOR
public static final char DEVICE_SEPARATOR
Method Detail |
public IPath addFileExtension(String extension)
The file extension portion is defined as the string following the last period (".") character in the last segment. The given extension should not include a leading ".".
extension
- the file extension to append
public IPath addTrailingSeparator()
If this path already has a trailing separator, this path is returned.
hasTrailingSeparator()
,
removeTrailingSeparator()
public IPath append(String path)
path
- the string path to concatenate
isValidPath(java.lang.String)
public IPath append(IPath path)
path
- the path to concatenate
public Object clone()
clone
in class Object
public boolean equals(Object obj)
Equality for paths is defined to be: same sequence of segments, same absolute/relative status, and same device. Trailing separators are disregarded. Paths are not generally considered equal to objects other than paths.
equals
in class Object
obj
- the other object
true
if the paths are equivalent,
and false
if they are notpublic String getDevice()
null
if this
path has no device id. Note that the result will end in ':'.
null
setDevice(java.lang.String)
public String getFileExtension()
null
if there is none.
The file extension portion is defined as the string following the last period (".") character in the last segment. If there is no period in the last segment, the path has no file extension portion. If the last segment ends in a period, the file extension portion is the empty string.
null
public boolean hasTrailingSeparator()
Note: In the root path ("/"), the separator is considered to be leading rather than trailing.
true
if this path has a trailing
separator, and false
otherwiseaddTrailingSeparator()
,
removeTrailingSeparator()
public boolean isAbsolute()
Absolute paths start with a path separator.
A root path, like /
or C:/
,
is considered absolute.
true
if this path is an absolute path,
and false
otherwisepublic boolean isEmpty()
true
if this path is empty,
and false
otherwisepublic boolean isPrefixOf(IPath anotherPath)
An empty path is a prefix of all paths with the same device; a root path is a prefix of all absolute paths with the same device.
anotherPath
- the other path
true
if this path is a prefix of the given path,
and false
otherwisepublic boolean isRoot()
The root path is the absolute path with zero segments;
e.g., /
or C:/
.
The separator is considered a leading separator, not a trailing one.
true
if this path is a root path,
and false
otherwisepublic boolean isUNC()
Path.SEPARATOR
.
public boolean isValidPath(String path)
true
if the given string is a valid path,
and false
otherwiseisValidSegment(java.lang.String)
public boolean isValidSegment(String segment)
segment
- the path segment to check
true
if the given path segment is valid,
and false
otherwiseCharacter.isWhitespace(char)
public String lastSegment()
null
if it does not have any segments.
null
public IPath makeAbsolute()
public IPath makeRelative()
public IPath makeUNC(boolean toUNC)
Path.SEPARATOR
. If not UNC, the
first 2 characters of the returned path string will not be Path.SEPARATOR
.
toUNC
- true if converting to UNC, false otherwise
public int matchingFirstSegments(IPath anotherPath)
anotherPath
- the other path
public IPath removeFileExtension()
The file extension portion is defined as the string following the last period (".") character in the last segment. If there is no period in the last segment, the path has no file extension portion. If the last segment ends in a period, the file extension portion is the empty string.
public IPath removeFirstSegments(int count)
public IPath removeLastSegments(int count)
If this path has a trailing separator, it will still have a trailing separator after the last segments are removed (assuming there are some segments left). If there is no trailing separator, the result will not have a trailing separator. If the number equals or exceeds the number of segments in this path, an empty path is returned.
public IPath removeTrailingSeparator()
If this path does not have a trailing separator, this path is returned.
addTrailingSeparator()
,
hasTrailingSeparator()
public String segment(int index)
null
if the path does not have such a segment.
index
- the 0-based segment index
null
public int segmentCount()
Note that both root and empty paths have 0 segments.
public String[] segments()
public IPath setDevice(String device)
null
.
For example, "C:" and "Server/Volume:" are typical device ids.
device
- the device id or null
getDevice()
public File toFile()
java.io.File
corresponding to this path.
public String toOSString()
java.io.File
.
This method is like toString()
except that the
latter always uses the same separator (/
) regardless of platform.
This string is suitable for passing to java.io.File(String)
.
public String toString()
Example result strings (without and with device id):
"/foo/bar.txt" "bar.txt" "/foo/" "foo/" "" "/" "C:/foo/bar.txt" "C:bar.txt" "C:/foo/" "C:foo/" "C:" "C:/"This string is suitable for passing to
Path(String)
.
toString
in class Object
Path
public IPath uptoSegment(int count)
If this path has a trailing separator, the result will too (assuming there are some segments left). If there is no trailing separator, the result will not have a trailing separator. Copying up to segment zero simply means making an copy with no path segments.
count
- the segment number at which to truncate the path
|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |