Package org.gradle.util

# 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.

- ## Field Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `String`
  `absolutePath(String path)`
  Resolves the given name relative to this path.
  `Path`
  `absolutePath(Path 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.
  `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()`
  `int`
  `hashCode()`
  `boolean`
  `isAbsolute()`
  `static Path`
  `path(@Nullable String path)`
  `String`
  `relativePath(String path)`
  Calculates a path relative to this path.
  `Path`
  `relativePath(Path path)`
  `Path`
  `removeFirstSegments(int n)`
  `String`
  `segment(int index)`
  `int`
  `segmentCount()`
  `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 java.lang.Object

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

- ## Field Details

  - ### ROOT

    public static final Path ROOT

  - ### SEPARATOR

    public static final String SEPARATOR
    See Also:
      - Constant Field Values

- ## Method Details

  - ### path

    public static Path path(@Nullable String path)

  - ### 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')

  - ### getPath

    public String getPath()

  - ### 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.

  - ### 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,

  - ### child

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

  - ### absolutePath

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

  - ### absolutePath

    public Path absolutePath(Path path)

  - ### isAbsolute

    public boolean isAbsolute()

  - ### 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.

  - ### relativePath

    public Path relativePath(Path path)

  - ### segmentCount

    public int segmentCount()

  - ### removeFirstSegments

    public Path removeFirstSegments(int n)

  - ### segment

    public String segment(int index)

  - ### 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