Class Path

java.lang.Object
com.yahoo.path.Path

public final class Path extends Object
Represents a path as a list of elements. Immutable.
Author:
Ulf Lilleengen, bratseth
  • Method Details

    • from

      public static Path from(List<String> segments)
      Creates a new path with the given segments.
    • isChildOf

      public boolean isChildOf(Path parent)
      Returns whether this path is an immediate child of the given path
    • append

      public Path append(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 String getName()
      Returns the name of this path element, typically the last element in the path string
    • getRelative

      public 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 String last()
      Returns the last element in this, or the empty string if this path is empty
    • withLast

      public Path withLast(String element)
      Returns a new path with the last element replaced by the given element.
      Throws:
      IllegalStateException - if this path is empty
    • getAbsolute

      public String getAbsolute()
      Returns a string representation of this path where the delimiter is prepended
    • isRoot

      public boolean isRoot()
    • iterator

      public Iterator<String> iterator()
    • elements

      public List<String> elements()
      Returns an immutable list of the elements of this path in order
    • toString

      public String toString()
      Returns this as a string
      Overrides:
      toString in class Object
    • fromString

      public static Path fromString(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(String path, 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(String delimiter)
      Create an empty root path with delimiter.
      Returns:
      an empty root path that can be appended
    • toFile

      public File toFile()
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object