Package com.yahoo.path
Class Path
- java.lang.Object
-
- com.yahoo.path.Path
-
@Beta public final class Path extends java.lang.Object
Represents a path represented by a list of elements. Immutable- Author:
- Ulf Lilleengen, bratseth
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Path
append(Path path)
Appends a path to another path, thereby creating a new path with the provided path appended to this.Path
append(java.lang.String path)
Append an element to the path.static Path
createRoot()
Create an empty root path with '/' delimiter.static Path
createRoot(java.lang.String delimiter)
Create an empty root path with delimiter.java.util.List<java.lang.String>
elements()
Returns an immutable list of the elements of this path in orderboolean
equals(java.lang.Object other)
static Path
fromString(java.lang.String path)
Creates a path from a string.static Path
fromString(java.lang.String path, java.lang.String delimiter)
Create a path from a string.java.lang.String
getAbsolute()
Returns a string representation of this path where the delimiter is prependedPath
getChildPath()
Returns the child path: A path containing all elements of this except the firstjava.lang.String
getName()
Returns the name of this path element, typically the last element in the path stringPath
getParentPath()
Returns the parent path: A path containing all elements of this except the lastjava.lang.String
getRelative()
Returns a string representation of the path represented by thisint
hashCode()
boolean
isChildOf(Path parent)
Returns whether this path is an immediate child of the given pathboolean
isRoot()
java.util.Iterator<java.lang.String>
iterator()
java.lang.String
last()
Returns the last element in this, or the empty string if this path is emptyjava.io.File
toFile()
java.lang.String
toString()
Returns this as a stringPath
withLast(java.lang.String element)
Returns a new path with the last element replaced by the given element.
-
-
-
Method Detail
-
isChildOf
public boolean isChildOf(Path parent)
Returns whether this path is an immediate child of the given path
-
append
public Path append(java.lang.String path)
Append an element to the path. Returns a new path with the given path appended.- Parameters:
path
- the path to append to this- Returns:
- the new path
-
append
public Path append(Path path)
Appends a path to another path, thereby creating a new path with the provided path appended to this.- Parameters:
path
- the path to append- Returns:
- a new path with argument appended to it
-
getName
public java.lang.String getName()
Returns the name of this path element, typically the last element in the path string
-
getRelative
public java.lang.String getRelative()
Returns a string representation of the path represented by this
-
getParentPath
public Path getParentPath()
Returns the parent path: A path containing all elements of this except the last
-
getChildPath
public Path getChildPath()
Returns the child path: A path containing all elements of this except the first
-
last
public java.lang.String last()
Returns the last element in this, or the empty string if this path is empty
-
withLast
public Path withLast(java.lang.String element)
Returns a new path with the last element replaced by the given element.- Throws:
java.lang.IllegalStateException
- if this path is empty
-
getAbsolute
public java.lang.String getAbsolute()
Returns a string representation of this path where the delimiter is prepended
-
isRoot
public boolean isRoot()
-
iterator
public java.util.Iterator<java.lang.String> iterator()
-
elements
public java.util.List<java.lang.String> elements()
Returns an immutable list of the elements of this path in order
-
toString
public java.lang.String toString()
Returns this as a string- Overrides:
toString
in classjava.lang.Object
-
fromString
public static Path fromString(java.lang.String path)
Creates a path from a string. The string is treated as a relative path, and all redundant '/'-characters are stripped.- Parameters:
path
- the relative path that this path should represent- Returns:
- a path object that may be used with the application package
-
fromString
public static Path fromString(java.lang.String path, java.lang.String delimiter)
Create a path from a string. The string is treated as a relative path, and all redundant delimiter-characters are stripped.- Parameters:
path
- the relative path that this path should represent- Returns:
- a path object that may be used with the application package
-
createRoot
public static Path createRoot()
Create an empty root path with '/' delimiter.- Returns:
- an empty root path that can be appended
-
createRoot
public static Path createRoot(java.lang.String delimiter)
Create an empty root path with delimiter.- Returns:
- an empty root path that can be appended
-
toFile
public java.io.File toFile()
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
-