- 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 thePath
interface to minimize the effort required to implement this interface.- Author:
- Rob Spoor
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractPath()
Creates a new path.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
endsWith(String other)
Tests if this path ends with aPath
, constructed by converting the given path string.Path
getFileName()
Returns the name of the file or directory denoted by this path as aPath
object.Path
getName(int index)
Returns a name element of this path as aPath
object.Iterator<Path>
iterator()
Returns an iterator over the name elements of this path.WatchKey
register(WatchService watcher, WatchEvent.Kind<?>... events)
Registers the file located by this path with a watch service.Path
resolve(String other)
Converts a given path string to aPath
and resolves it against thisPath
.Path
resolveSibling(String other)
Converts a given path string to aPath
and resolves it against this path'sparent
path.Path
resolveSibling(Path other)
Resolves the given path against this path'sparent
path.boolean
startsWith(String other)
Tests if this path starts with aPath
, constructed by converting the given path string.File
toFile()
Returns aFile
object 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 aPath
object.This implementation returns
getName(i)
, wherei
is equal toPath.getNameCount()
- 1
. IfgetNameCount()
returns0
this method returnsnull
.- Specified by:
getFileName
in interfacePath
-
getName
public Path getName(int index)
Returns a name element of this path as aPath
object.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
FileSystem
toconvert
the given string into aPath
, then callsPath.startsWith(Path)
.- Specified by:
startsWith
in 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
FileSystem
toconvert
the given string into aPath
, then callsPath.endsWith(Path)
.
-
resolve
public Path resolve(String other)
Converts a given path string to aPath
and resolves it against thisPath
.This implementation uses this path's
FileSystem
toconvert
the given string into aPath
, then callsPath.resolve(Path)
.
-
resolveSibling
public Path resolveSibling(String other)
Converts a given path string to aPath
and resolves it against this path'sparent
path.This implementation uses this path's
FileSystem
toconvert
the given string into aPath
, then callsresolveSibling(Path)
.- Specified by:
resolveSibling
in interfacePath
-
resolveSibling
public Path resolveSibling(Path other)
Resolves the given path against this path'sparent
path.This implementation returns
getParent().
resolve(other)
, orother
if this path has no parent.- Specified by:
resolveSibling
in interfacePath
-
toFile
public File toFile()
Returns aFile
object representing this path.This implementation will always throw an
UnsupportedOperationException
as 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:
register
in interfacePath
- Specified by:
register
in 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.
-
-