Class SimplePath

java.lang.Object
com.atlassian.bitbucket.content.SimplePath
All Implemented Interfaces:
Path, Serializable, Comparable<SimplePath>

public class SimplePath extends Object implements Comparable<SimplePath>, Path, Serializable
See Also:
  • Field Details

    • EMPTY

      public static final String[] EMPTY
    • ROOT

      public static final SimplePath ROOT
  • Constructor Details

  • Method Details

    • join

      public static String join(String a, String b)
      Intelligently put a "/" between two strings.
      Parameters:
      a - first path component
      b - second path component
      Returns:
      merged path
    • split

      public static String[] split(CharSequence aPath)
    • split

      public static String[] split(CharSequence aPath, boolean allowSloshes)
    • abbreviate

      public SimplePath abbreviate(int maxLength)
      Abbreviates the path by removing path components from the middle until the length of the path is not greater than maxLength.

      The first and last path component are always in the returned path. If any path components are removed, an ellipses ("...") will appear in the middle. The returned path may in some cases still be greater than the specified maxLength.

      Parameters:
      maxLength - maximum number of characters
      Returns:
      an abbreviated path
    • abbreviatePathComponents

      public SimplePath[] abbreviatePathComponents(int maxLength)
      Returns a similar result to getPathComponents(), but abbreviates the result (inserts null at the break point)
      Parameters:
      maxLength - maximum length
      Returns:
      an abbreviated array of path components for the current path
    • compareTo

      public int compareTo(SimplePath o)
      Specified by:
      compareTo in interface Comparable<SimplePath>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • getCommonRoot

      public SimplePath getCommonRoot(SimplePath other)
    • getComponent

      public String getComponent(int i)
    • getComponents

      @Nonnull public String[] getComponents()
      Specified by:
      getComponents in interface Path
      Returns:
      an array of Strings representing the directories followed by a possible file name
    • getExtension

      public String getExtension()
      Specified by:
      getExtension in interface Path
      Returns:
      the file extension of the path (with no .), or null if there is no file extension
    • getName

      @Nonnull public String getName()
      Specified by:
      getName in interface Path
      Returns:
      everything after the last "/" (the last component), including the extension, or an empty string if there are no components
    • getNumComponents

      public int getNumComponents()
    • getParent

      public String getParent()
      Specified by:
      getParent in interface Path
      Returns:
      the parent string - everything up to the last component, or an empty string if root
    • getParentPath

      public SimplePath getParentPath()
    • getPath

      public String getPath()
      Returns:
      the string representation of the path
    • getPath

      public String getPath(boolean caseSensitive)
    • getPathComponents

      public SimplePath[] getPathComponents()
    • getPathHead

      public SimplePath getPathHead()
    • getStripTail

      public SimplePath getStripTail(SimplePath other, boolean caseSensitive)
      if other is an exact tail of this, return the path leading up to that tail otherwise return null
      Parameters:
      other - the other path
      caseSensitive - true if case sensitive
      Returns:
      the stripped path, or null if the other path is not a tail of this path
    • getSubPath

      public SimplePath getSubPath(int depth)
    • getTail

      public String getTail()
      Returns:
      a String composed of all the path segments after the first segment
    • getTailPath

      public SimplePath getTailPath()
    • hasPrefix

      public boolean hasPrefix(SimplePath p)
      determines if this path begins with all of p
      Parameters:
      p - the prefix to check
      Returns:
      true if it has the prefix path
    • hasPrefix

      public boolean hasPrefix(SimplePath p, boolean caseSensitive)
    • hashCode

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

      public boolean isAncestor(SimplePath descendant)
    • isRoot

      public boolean isRoot()
    • simplify

      public SimplePath simplify()
    • toString

      @Nonnull public String toString()
      Specified by:
      toString in interface Path
      Overrides:
      toString in class Object
      Returns:
      a string representation of the path - the components separated by "/"s
    • trimFirst

      public SimplePath trimFirst()
    • trimFirst

      public SimplePath trimFirst(int n)
      Parameters:
      n - number of components to trim
      Returns:
      the trimmed path or same path if the length was 0
    • trimLast

      public SimplePath trimLast()