Class PathBase<T,P extends Path<T>>

java.lang.Object
org.aksw.commons.path.core.PathBase<T,P>
Type Parameters:
T -
P -
All Implemented Interfaces:
Serializable, Comparable<Path<T>>, Iterable<Path<T>>, Path<T>
Direct Known Subclasses:
PathJson, PathStr

public class PathBase<T,P extends Path<T>> extends Object implements Path<T>, Serializable
Generic base implementation of the path interface. Internally keeps a flag for whether the path is absolute and a list of path segments. All methods of this class are implemented against the PathOps interface. Complex or verbose type expressions can be abstracted by extending this class as sketched below.
 class MyPath extends PathBase<ComplexTypeExpression, MyPath> {
    MyPath(PathOps<T, P> pathOps, boolean isAbsolute, List segments) {
      super(pathOps, isAbsolute, segments);
    }
 }

 class MyPathOps implements PathOps {
   MyPath newPath(boolean isAbsolute, List segments) {
     return new MyPath(this, isAbsolute, segments);
   }

   // Implement remaining methods
 }
 
Author:
raven
See Also:
  • Field Details

    • isAbsolute

      protected boolean isAbsolute
    • segments

      protected transient List<T> segments
    • segmentsView

      protected transient List<T> segmentsView
    • pathOps

      protected PathOps<T,P extends Path<T>> pathOps
  • Constructor Details

    • PathBase

      public PathBase(PathOps<T,P> pathOps, boolean isAbsolute, List<T> segments)
  • Method Details

    • newPath

      protected P newPath(boolean isAbsolute, List<T> segments)
    • getPathOps

      public PathOps<T,P> getPathOps()
    • toAbsolutePath

      public P toAbsolutePath()
      Specified by:
      toAbsolutePath in interface Path<T>
    • isAbsolute

      public boolean isAbsolute()
      Specified by:
      isAbsolute in interface Path<T>
    • getRoot

      public P getRoot()
      Specified by:
      getRoot in interface Path<T>
    • getFileName

      public P getFileName()
      Specified by:
      getFileName in interface Path<T>
    • getParent

      public P getParent()
      Specified by:
      getParent in interface Path<T>
    • getNameCount

      public int getNameCount()
      Specified by:
      getNameCount in interface Path<T>
    • getName

      public P getName(int index)
      Specified by:
      getName in interface Path<T>
    • subpath

      public P subpath(int beginIndex, int endIndex)
      Specified by:
      subpath in interface Path<T>
    • subpath

      public P subpath(int beginIndex)
      Description copied from interface: Path
      Experimental. Not part of nio Path.
      Specified by:
      subpath in interface Path<T>
    • startsWith

      public boolean startsWith(Path<T> other)
      Specified by:
      startsWith in interface Path<T>
    • endsWith

      public boolean endsWith(Path<T> other)
      Specified by:
      endsWith in interface Path<T>
    • normalize

      public P normalize()
      Specified by:
      normalize in interface Path<T>
    • isParentToken

      protected boolean isParentToken(T item)
    • toList

      public static <T> List<T> toList(Path<T> path)
    • resolveStr

      public P resolveStr(String other)
      Specified by:
      resolveStr in interface Path<T>
    • resolve

      public P resolve(Path<T> other)
      Specified by:
      resolve in interface Path<T>
    • relativize

      public P relativize(Path<T> other)
      Specified by:
      relativize in interface Path<T>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • relativize

      public static <T> List<T> relativize(List<T> a, List<T> b, T parentToken)
    • getSegments

      public List<T> getSegments()
      Specified by:
      getSegments in interface Path<T>
    • resolve

      public P resolve(T other)
      Specified by:
      resolve in interface Path<T>
    • resolveSiblingStr

      public P resolveSiblingStr(String other)
      Specified by:
      resolveSiblingStr in interface Path<T>
    • resolveSibling

      public P resolveSibling(T other)
      Specified by:
      resolveSibling in interface Path<T>
    • resolveSibling

      public P resolveSibling(Path<T> other)
      Specified by:
      resolveSibling in interface Path<T>
    • iterator

      public Iterator<Path<T>> iterator()
      Specified by:
      iterator in interface Iterable<T>
    • compareTo

      public int compareTo(Path<T> other)
      Specified by:
      compareTo in interface Comparable<T>
    • compareLists

      public static <T> int compareLists(List<T> a, List<T> b, Comparator<T> comparator)
    • getSystem

      public Object getSystem()
      Description copied from interface: Path
      Returns an object such as the file system underlying this path. Returns null if not applicable. Experimental.
      Specified by:
      getSystem in interface Path<T>
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object