- java.lang.Object
-
- com.github.robtimus.filesystems.AbstractPath
-
- Direct Known Subclasses:
SimpleAbstractPath
public abstract class AbstractPath extends Object implements Path
This class provides a skeletal implementation of thePathinterface to minimize the effort required to implement this interface.- Author:
- Rob Spoor
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractPath()Creates a new path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanendsWith(String other)Tests if this path ends with aPath, constructed by converting the given path string.PathgetFileName()Returns the name of the file or directory denoted by this path as aPathobject.PathgetName(int index)Returns a name element of this path as aPathobject.Iterator<Path>iterator()Returns an iterator over the name elements of this path.WatchKeyregister(WatchService watcher, WatchEvent.Kind<?>... events)Registers the file located by this path with a watch service.Pathresolve(String other)Converts a given path string to aPathand resolves it against thisPath.PathresolveSibling(String other)Converts a given path string to aPathand resolves it against this path'sparentpath.PathresolveSibling(Path other)Resolves the given path against this path'sparentpath.booleanstartsWith(String other)Tests if this path starts with aPath, constructed by converting the given path string.FiletoFile()Returns aFileobject representing this path.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface java.nio.file.Path
compareTo, endsWith, equals, getFileSystem, getNameCount, getParent, getRoot, hashCode, isAbsolute, normalize, register, relativize, resolve, startsWith, subpath, toAbsolutePath, toRealPath, toString, toUri
-
-
-
-
Method Detail
-
getFileName
public Path getFileName()
Returns the name of the file or directory denoted by this path as aPathobject.This implementation returns
getName(i), whereiis equal toPath.getNameCount()- 1. IfgetNameCount()returns0this method returnsnull.- Specified by:
getFileNamein interfacePath
-
getName
public Path getName(int index)
Returns a name element of this path as aPathobject.This implementation calls
subpath(index, index + 1).
-
startsWith
public boolean startsWith(String other)
Tests if this path starts with aPath, constructed by converting the given path string.This implementation uses this path's
FileSystemtoconvertthe given string into aPath, then callsPath.startsWith(Path).- Specified by:
startsWithin interfacePath
-
endsWith
public boolean endsWith(String other)
Tests if this path ends with aPath, constructed by converting the given path string.This implementation uses this path's
FileSystemtoconvertthe given string into aPath, then callsPath.endsWith(Path).
-
resolve
public Path resolve(String other)
Converts a given path string to aPathand resolves it against thisPath.This implementation uses this path's
FileSystemtoconvertthe given string into aPath, then callsPath.resolve(Path).
-
resolveSibling
public Path resolveSibling(String other)
Converts a given path string to aPathand resolves it against this path'sparentpath.This implementation uses this path's
FileSystemtoconvertthe given string into aPath, then callsresolveSibling(Path).- Specified by:
resolveSiblingin interfacePath
-
resolveSibling
public Path resolveSibling(Path other)
Resolves the given path against this path'sparentpath.This implementation returns
getParent().resolve(other), orotherif this path has no parent.- Specified by:
resolveSiblingin interfacePath
-
toFile
public File toFile()
Returns aFileobject representing this path.This implementation will always throw an
UnsupportedOperationExceptionas per the contract ofPath.toFile().
-
register
public WatchKey register(WatchService watcher, WatchEvent.Kind<?>... events) throws IOException
Registers the file located by this path with a watch service.This implementation will call
Path.register(WatchService, WatchEvent.Kind[], WatchEvent.Modifier...)with an empty array of modifiers.- Specified by:
registerin interfacePath- Specified by:
registerin interfaceWatchable- Throws:
IOException
-
iterator
public Iterator<Path> iterator()
Returns an iterator over the name elements of this path.This implementation returns an iterator that uses
Path.getNameCount()to determine whether or not there are more elements, andgetName(int)to return the elements.
-
-