Class ResourcePath

  • All Implemented Interfaces:
    java.lang.Comparable<ResourcePath>, java.lang.Iterable<java.lang.String>

    public class ResourcePath
    extends java.lang.Object
    implements java.lang.Iterable<java.lang.String>, java.lang.Comparable<ResourcePath>
    An abstract path used to represent a resource or its parent. The resource path may be may be mapped to a file-system path or some other form by the ResourceStorageDao implementation. The elements of the path must not contain a forward slash (/).
    Author:
    jwhite
    • Constructor Detail

      • ResourcePath

        public ResourcePath​(java.lang.String... path)
      • ResourcePath

        public ResourcePath​(java.lang.Iterable<java.lang.String> pathElements)
      • ResourcePath

        public ResourcePath​(ResourcePath parent,
                            java.lang.String... path)
      • ResourcePath

        public ResourcePath​(ResourcePath parent,
                            java.lang.Iterable<java.lang.String> pathElements)
    • Method Detail

      • get

        public static ResourcePath get​(java.lang.String... path)
        Convenience method.
      • get

        public static ResourcePath get​(java.lang.Iterable<java.lang.String> pathElements)
        Convenience method.
      • get

        public static ResourcePath get​(ResourcePath parent,
                                       java.lang.Iterable<java.lang.String> path)
        Convenience method.
      • getName

        public java.lang.String getName()
      • elements

        public java.lang.String[] elements()
      • relativeDepth

        public int relativeDepth​(ResourcePath child)
        Determines the relative depth of a child path.
        Returns:
        the relative depth >= 0, or -1 if the given child is not actually a child
      • hasParent

        public boolean hasParent()
      • iterator

        public java.util.Iterator<java.lang.String> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.String>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

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

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(ResourcePath other)
        Specified by:
        compareTo in interface java.lang.Comparable<ResourcePath>
      • sanitize

        public static java.lang.String sanitize​(java.lang.String path)
      • resourceToFilesystemPath

        public static java.nio.file.Path resourceToFilesystemPath​(ResourcePath path)
        Converts the given resource path to a relative path on filesystem.
        Parameters:
        path - the resource path to resolve
        Returns:
        the relative path of the resource on disk
      • fromString

        public static ResourcePath fromString​(java.lang.String s)
      • toString

        public static java.lang.String toString​(ResourcePath path)