Package gw.fs

Class ResourcePath

    • Field Detail

      • WINDOWS_NETWORK_ROOT

        public static final java.lang.String WINDOWS_NETWORK_ROOT
        See Also:
        Constant Field Values
      • _name

        protected final java.lang.String _name
    • Constructor Detail

      • ResourcePath

        protected ResourcePath​(ResourcePath parent,
                               java.lang.String name)
    • Method Detail

      • parse

        public static ResourcePath parse​(java.lang.String pathString)
      • tokenizePathFragment

        private static DynamicArray<java.lang.String> tokenizePathFragment​(java.lang.String pathString,
                                                                           int lastIndex)
      • normalizePath

        private static DynamicArray<java.lang.String> normalizePath​(DynamicArray<java.lang.String> pathElements)
      • construct

        private static ResourcePath construct​(java.lang.String headElement,
                                              java.util.List<java.lang.String> fullPath,
                                              int nameIndex)
      • getName

        public java.lang.String getName()
        Returns the leaf name of this resource path. If this path object represents the path "/usr/local/bin", then the getName() method will return the String "bin". In the case of the root path element, this method will return the empty string for the unix filesystem root and a windows drive letter, normalized to upper case, with no trailing path separator for a windows path root. This method will never return a null value.
        Returns:
        the name of the last element of the path.
      • getParent

        public ResourcePath getParent()
        Returns the parent of this resource path. If this path object represents the root of the filesystem, this method will return null.
        Returns:
        the parent of this ResourcePath
      • getPathString

        public java.lang.String getPathString()
        Returns the path string for this path using the / path separator.
        Returns:
        the path string for this path using the / path separator.
        See Also:
        getPathString(String)
      • getFileSystemPathString

        public java.lang.String getFileSystemPathString()
        Returns the path string for this path using the default file system separator, as defined by the File.separator property.
        Returns:
        the path string for this path using the default file system separator
        See Also:
        getPathString(String)
      • getPathString

        public java.lang.String getPathString​(java.lang.String separator)
        Returns the path string for this path using the specified path separator. The path constructed will begin with the root of the path, which will be one of:
        • A windows drive letter, normalized to upper case, followed by : and the separator
        • The windows network path start \\
        • Just the separator, in the case of the unix root
        After the path root will follow all path components, separated with the given separator. The separator will not be appended to the end of the path. Some example paths returned by this method are:
        • C:\temp\downloads
        • /
        • \\files\documents
          Parameters:
          separator - the separator to use when constructing the path
          Returns:
          the path string for this path using the specified path separator
        • constructPathString

          private void constructPathString​(java.lang.StringBuilder sb,
                                           java.lang.String separator)
        • join

          public ResourcePath join​(java.lang.String otherPath)
          Takes the specified path fragment and joins it with this ResourcePath to create a new ResourcePath. The specified path can use either \ or / separator characters (or a mix of the two), and it can include . or .. elements in the path, which will be traversed appropriately. The path can start and/or end with a separator character, but it should not start with a windows drive letter or network root. The resulting path will have the same root as this path. Some examples:
          • "/usr/local".join("lib/java") -> "/usr/local/lib/java"
          • "/usr/local".join("/..") -> "/usr"
          • "/usr/local".join("/.") -> "/usr/local
          If .. path elements would lead to traversing backwards past the root element, an IllegalArgumentException will be thrown. An IllegalArgumentException will also be thrown if otherPath is null.
          Parameters:
          otherPath - the path to join with this one
          Returns:
          a ResourcePath that results from appending otherPath to this path and then normalizing the result
        • equals

          public boolean equals​(java.lang.Object obj)
          Two ResourcePath objects are considered to be equal if they represent the same leaf path and if their parents are equal. Note that currently the name matching is case-sensitive, even when this is being called on a case-insensitive file system.
          Overrides:
          equals in class java.lang.Object
          Parameters:
          obj - the other object
          Returns:
          true if the objects are equal, false otherwise
        • hashCode

          public int hashCode()
          Overrides:
          hashCode in class java.lang.Object
        • isDescendant

          public boolean isDescendant​(ResourcePath path)
        • relativePath

          public java.lang.String relativePath​(ResourcePath other)
        • relativePath

          public java.lang.String relativePath​(ResourcePath other,
                                               java.lang.String separator)