Top Description Fields Constructors Methods
org.eclipse.xtend.lib.macro.file

public final Class Path

extends Object
Class Inheritance
Annotations
@Beta
Static Imports
com.google.common.collect.Lists.newArrayList

A path points to some file or folder within a FileSystemSupport and MutableFileSystemSupport. A path either starts with a slash which denotes an absolute path or a segment which denotes a relative path. Note that this is an abstraction over different 'real' file systems and doesn't understand platform specific things like, e.g. "c:/" on windows. The path segment separator is '/'.
Author
Sven Efftinge

Field Summary

Modifier and TypeField and Description
private final boolean
public static final Path
ROOT

the root path

public static final char
SEGMENT_SEPARATOR

the segment separator used.

private final ImmutableList<String>
private static final Splitter

Constructor Summary

AccessConstructor and Description
public
Path(String pathAsString)

Constructs a new Path object from a given string.

private
Path(List<String> segments, boolean isAbsolute)

Method Summary

Modifier and TypeMethod and Description
public Path

Returns:

a new Path with the given suffix appended to this path's segments.
append
(String
the suffix to append to this path
suffix
)

Appends the given suffix to this path.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public Path

Returns:

the absolute path
getAbsolutePath
(String relativePath)

public Path

Returns:

the absolute path
getAbsolutePath
(Path relativePath)

public String

Returns:

the file extension or null if this path's last segment doesn't have a file extension.
getFileExtension
()

public String

Returns:

the trailing segment, i.e. the simple name of the underlying element.
getLastSegment
()

public Path

Returns:

the parent of this path or null if this path is the root path.
getParent
()

Returns the parent of this path or null if this path is the root path.

public List<String>

Returns:

the segments
getSegments
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

private Path
public boolean

Returns:

whether this is an absolute path
isAbsolute
()

private Iterable<String>
public Path

Returns:

the resulting relative path or null if neither of the given paths is a prefix of the other
relativize
(String
a string representing a path
other
)

See relativize(Path)

public Path

Returns:

the resulting relative path or null if neither of the given paths is a prefix of the other
relativize
(Path
the path to relativize against this path
other
)

Constructs a relative path between this path and a given path.

public boolean

Returns:

whether the given path is a prefix of this path
startsWith
(Path
the path, which might be a prefix of this path
other
)

Returns whether this path starts with the same segments and has the same isAbsolute() value.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

absoluteback to summary
private final boolean absolute
ROOTback to summary
public static final Path ROOT

the root path

SEGMENT_SEPARATORback to summary
public static final char SEGMENT_SEPARATOR

the segment separator used.

segmentsback to summary
private final ImmutableList<String> segments
splitterback to summary
private static final Splitter splitter

Constructor Detail

Pathback to summary
public Path(String pathAsString)

Constructs a new Path object from a given string. the used file separator is '/' and a leading one indicates an absolute path.

Pathback to summary
private Path(List<String> segments, boolean isAbsolute)

Method Detail

appendback to summary
public Path append(String suffix)

Appends the given suffix to this path.

Parameters
suffix:String

the suffix to append to this path

Returns:Path

a new Path with the given suffix appended to this path's segments.

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Annotations
@Override
getAbsolutePathback to summary
public Path getAbsolutePath(String relativePath)
Returns:Path

the absolute path

getAbsolutePathback to summary
public Path getAbsolutePath(Path relativePath)
Returns:Path

the absolute path

getFileExtensionback to summary
public String getFileExtension()
Returns:String

the file extension or null if this path's last segment doesn't have a file extension.

getLastSegmentback to summary
public String getLastSegment()
Returns:String

the trailing segment, i.e. the simple name of the underlying element.

getParentback to summary
public Path getParent()

Returns the parent of this path or null if this path is the root path.

Returns:Path

the parent of this path or null if this path is the root path.

getSegmentsback to summary
public List<String> getSegments()
Returns:List<String>

the segments

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Annotations
@Override
internalRelativizeback to summary
private Path internalRelativize(Path path, Path prefix)
isAbsoluteback to summary
public boolean isAbsolute()
Returns:boolean

whether this is an absolute path

normalizeback to summary
private Iterable<String> normalize(Iterable<String> segments)
relativizeback to summary
public Path relativize(String other)

See relativize(Path)

Parameters
other:String

a string representing a path

Returns:Path

the resulting relative path or null if neither of the given paths is a prefix of the other

relativizeback to summary
public Path relativize(Path other)

Constructs a relative path between this path and a given path.

Relativization is the inverse of resolution. This method attempts to construct a relative path that when resolved against this path, yields a path that locates the same file as the given path. For example, on UNIX, if this path is "/a/b" and the given path is "/a/b/c/d" then the resulting relative path would be "c/d". Both paths must be absolute and and either this path or the given path must be a prefix of the other.

Parameters
other:Path

the path to relativize against this path

Returns:Path

the resulting relative path or null if neither of the given paths is a prefix of the other

Exceptions
IllegalArgumentException:
if this path and other are not both absolute or relative
startsWithback to summary
public boolean startsWith(Path other)

Returns whether this path starts with the same segments and has the same isAbsolute() value.

Parameters
other:Path

the path, which might be a prefix of this path

Returns:boolean

whether the given path is a prefix of this path

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override