# Class Path

java.lang.Object
org.gradle.util.Path

All Implemented Interfaces:
  `Comparable<Path>`

public class Path extends Object implements Comparable<Path>
Represents a path in Gradle.

Since:
  0.9

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final Path`
  `ROOT`
  Path.
  `static final String`
  `SEPARATOR`
  The separator.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `absolutePath(String path)`
  Resolves the given name relative to this path.
  `Path`
  `absolutePath(Path path)`
  Absolute path.
  `Iterable<Path>`
  `ancestors()`
  Iterate over all ancestors of this path, starting with the root path (if absolute) or the first segment (if relative) and not including this path.
  `Path`
  `append(Path path)`
  Appends the supplied path to this path, returning the new path.
  `String`
  `asString()`
  Returns the full path as a string.
  `Path`
  `child(String name)`
  Creates a child of this path with the given name.
  `int`
  `compareTo(Path other)`
  `boolean`
  `equals(@Nullable Object o)`
  `@Nullable String`
  `getName()`
  Returns the base name of this path, or null if this path is the root path.
  `@Nullable Path`
  `getParent()`
  Returns the parent of this path, or null if this path has no parent.
  `String`
  `getPath()`
  Deprecated.
  use `asString()` instead
  `int`
  `hashCode()`
  `boolean`
  `isAbsolute()`
  Returns whether absolute is set.
  `static Path`
  `path(@Nullable String path)`
  Path.
  `String`
  `relativePath(String path)`
  Calculates a path relative to this path.
  `Path`
  `relativePath(Path path)`
  Relative path.
  `Path`
  `removeFirstSegments(int n)`
  Remove first segments.
  `String`
  `segment(int index)`
  Segment.
  `int`
  `segmentCount()`
  Segment count.
  `List<String>`
  `segments()`
  returns an immutable list of the segments of this path
  `boolean`
  `startsWith(Path other)`
  Determines if this path starts with the given path.
  `Path`
  `takeFirstSegments(int n)`
  Returns a `Path` containing only the first `n` segments of this `Path`.
  `String`
  `toString()`
  `static void`
  `validatePath(@Nullable String path)`
  throws if no path is specified

  ### Methods inherited from class Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Field Details

  - ### ROOT

    public static final Path ROOT
    Path.
    Since:
      0.9

  - ### SEPARATOR

    public static final String SEPARATOR
    The separator.
    Since:
      4.2
    See Also:
      - Constant Field Values

- ## Method Details

  - ### path

    public static Path path(@Nullable String path)
    Path.
    Since:
      0.9

  - ### validatePath

    @Incubating public static void validatePath(@Nullable String path)
    throws if no path is specified
    Since:
      8.5

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### append

    public Path append(Path path)
    Appends the supplied path to this path, returning the new path. The resulting path with be absolute or relative based on the path being appended _to_. It makes no difference if the _appended_ path is absolute or relative.

        path(':a:b').append(path(':c:d')) == path(':a:b:c:d')
        path(':a:b').append(path('c:d')) == path(':a:b:c:d')
        path('a:b').append(path(':c:d')) == path('a:b:c:d')
        path('a:b').append(path('c:d')) == path('a:b:c:d')

    Since:
      4.0

  - ### getPath

    @Deprecated public String getPath()
    Deprecated.
    use `asString()` instead
    Returns string representation of this path.
    Returns:
      string representation of this path
    Since:
      0.9

  - ### asString

    public String asString()
    Returns the full path as a string.
    Since:
      9.2.0

  - ### segments

    @Incubating public List<String> segments()
    returns an immutable list of the segments of this path
    Since:
      8.5

  - ### equals

    public boolean equals(@Nullable Object o)
    Overrides:
      `equals` in class `Object`

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`

  - ### compareTo

    public int compareTo(Path other)
    Specified by:
      `compareTo` in interface `Comparable<Path>`

  - ### getParent

    public @Nullable Path getParent()
    Returns the parent of this path, or null if this path has no parent.
    Returns:
      The parent of this path.
    Since:
      0.9

  - ### getName

    public @Nullable String getName()
    Returns the base name of this path, or null if this path is the root path.
    Returns:
      The base name,
    Since:
      0.9

  - ### child

    public Path child(String name)
    Creates a child of this path with the given name.
    Since:
      3.3

  - ### absolutePath

    public String absolutePath(String path)
    Resolves the given name relative to this path. If an absolute path is provided, it is returned.
    Since:
      0.9

  - ### absolutePath

    public Path absolutePath(Path path)
    Absolute path.
    Since:
      4.0

  - ### isAbsolute

    public boolean isAbsolute()
    Returns whether absolute is set.
    Since:
      6.8

  - ### relativePath

    public String relativePath(String path)
    Calculates a path relative to this path. If the given path is not a child of this path, it is returned unmodified.
    Since:
      0.9

  - ### relativePath

    public Path relativePath(Path path)
    Relative path.
    Since:
      4.0

  - ### segmentCount

    public int segmentCount()
    Segment count.
    Since:
      6.8

  - ### removeFirstSegments

    public Path removeFirstSegments(int n)
    Remove first segments.
    Since:
      6.8

  - ### segment

    public String segment(int index)
    Segment.
    Since:
      6.8

  - ### takeFirstSegments

    @Incubating public Path takeFirstSegments(int n)
    Returns a `Path` containing only the first `n` segments of this `Path`. The returned `Path` will be absolute if this `Path` is absolute.
    Parameters:
      `n` - number of segments to take from this Path, must be greater than or equal to 1
    Since:
      8.4

  - ### ancestors

    @Incubating public Iterable<Path> ancestors()
    Iterate over all ancestors of this path, starting with the root path (if absolute) or the first segment (if relative) and not including this path.

    For example, the path `:a:b:c` has the ancestors `:`, `:a`, and `:a:b`. The path `a:b:c` has the ancestors `a`, and `a:b`.

    Since:
      8.13

  - ### startsWith

    @Incubating public boolean startsWith(Path other)
    Determines if this path starts with the given path.
    Parameters:
      `other` - The path to check if this path starts with.
    Returns:
      True if this path starts with the given path, false otherwise. Returns false if one path is absolute and the other is not.
    Since:
      9.1.0