Package io.roastedroot.zerofs
Class ZeroFsPath
- java.lang.Object
-
- io.roastedroot.zerofs.ZeroFsPath
-
- All Implemented Interfaces:
java.lang.Comparable<java.nio.file.Path>,java.lang.Iterable<java.nio.file.Path>,java.nio.file.Path,java.nio.file.Watchable
final class ZeroFsPath extends java.lang.Object implements java.nio.file.PathZeroFs implementation ofPath. Creation of newPathobjects is delegated to the file system'sPathService.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Name>namesprivate PathServicepathServiceprivate Nameroot
-
Constructor Summary
Constructors Constructor Description ZeroFsPath(PathService pathService, Name root, Name... names)ZeroFsPath(PathService pathService, Name root, java.util.List<Name> names)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.util.List<java.nio.file.Path>asList()private ZeroFsPathcheckPath(java.nio.file.Path other)intcompareTo(java.nio.file.Path other)booleanendsWith(java.lang.String other)booleanendsWith(java.nio.file.Path other)booleanequals(java.lang.Object obj)ZeroFsPathgetFileName()java.nio.file.FileSystemgetFileSystem()ZeroFsPathgetName(int index)intgetNameCount()ZeroFsPathgetParent()ZeroFsPathgetRoot()ZeroFsFileSystemgetZeroFsFileSystem()Equivalent togetFileSystem()but with a return type ofZeroFsFileSystem.inthashCode()booleanisAbsolute()booleanisEmptyPath()Returns whether or not this is the empty path, with no root and a single, empty string, name.private booleanisNormal()Returns whether or not this path is in a normalized form.java.util.Iterator<java.nio.file.Path>iterator()Namename()Returns the file name of this path.java.util.List<Name>names()Returns the list of name elements.ZeroFsPathnormalize()java.nio.file.WatchKeyregister(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events)java.nio.file.WatchKeyregister(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers)ZeroFsPathrelativize(java.nio.file.Path other)(package private) ZeroFsPathresolve(Name name)Resolves the given name against this path.ZeroFsPathresolve(java.lang.String other)ZeroFsPathresolve(java.nio.file.Path other)ZeroFsPathresolveSibling(java.lang.String other)ZeroFsPathresolveSibling(java.nio.file.Path other)Nameroot()Returns the root name, or null if there is no root.booleanstartsWith(java.lang.String other)booleanstartsWith(java.nio.file.Path other)private static booleanstartsWith(java.util.List<?> list, java.util.List<?> other)Returns true if list starts with all elements of other in the same order.ZeroFsPathsubpath(int beginIndex, int endIndex)ZeroFsPathtoAbsolutePath()java.io.FiletoFile()ZeroFsPathtoRealPath(java.nio.file.LinkOption... options)java.lang.StringtoString()java.net.URItoUri()
-
-
-
Field Detail
-
root
private final Name root
-
names
private final java.util.List<Name> names
-
pathService
private final PathService pathService
-
-
Constructor Detail
-
ZeroFsPath
public ZeroFsPath(PathService pathService, Name root, Name... names)
-
ZeroFsPath
public ZeroFsPath(PathService pathService, Name root, java.util.List<Name> names)
-
-
Method Detail
-
root
public Name root()
Returns the root name, or null if there is no root.
-
names
public java.util.List<Name> names()
Returns the list of name elements.
-
name
public Name name()
Returns the file name of this path. UnlikegetFileName(), this may return the name of the root if this is a root path.
-
isEmptyPath
public boolean isEmptyPath()
Returns whether or not this is the empty path, with no root and a single, empty string, name.
-
getFileSystem
public java.nio.file.FileSystem getFileSystem()
- Specified by:
getFileSystemin interfacejava.nio.file.Path
-
getZeroFsFileSystem
public ZeroFsFileSystem getZeroFsFileSystem()
Equivalent togetFileSystem()but with a return type ofZeroFsFileSystem.getFileSystem()'s return type is left asFileSystemto make testing paths easier (as long as methods that access the file system in some way are not called, the file system can be a fake file system instance).
-
isAbsolute
public boolean isAbsolute()
- Specified by:
isAbsolutein interfacejava.nio.file.Path
-
getRoot
public ZeroFsPath getRoot()
- Specified by:
getRootin interfacejava.nio.file.Path
-
getFileName
public ZeroFsPath getFileName()
- Specified by:
getFileNamein interfacejava.nio.file.Path
-
getParent
public ZeroFsPath getParent()
- Specified by:
getParentin interfacejava.nio.file.Path
-
getNameCount
public int getNameCount()
- Specified by:
getNameCountin interfacejava.nio.file.Path
-
getName
public ZeroFsPath getName(int index)
- Specified by:
getNamein interfacejava.nio.file.Path
-
subpath
public ZeroFsPath subpath(int beginIndex, int endIndex)
- Specified by:
subpathin interfacejava.nio.file.Path
-
startsWith
private static boolean startsWith(java.util.List<?> list, java.util.List<?> other)Returns true if list starts with all elements of other in the same order.
-
startsWith
public boolean startsWith(java.nio.file.Path other)
- Specified by:
startsWithin interfacejava.nio.file.Path
-
startsWith
public boolean startsWith(java.lang.String other)
- Specified by:
startsWithin interfacejava.nio.file.Path
-
endsWith
public boolean endsWith(java.nio.file.Path other)
- Specified by:
endsWithin interfacejava.nio.file.Path
-
endsWith
public boolean endsWith(java.lang.String other)
- Specified by:
endsWithin interfacejava.nio.file.Path
-
normalize
public ZeroFsPath normalize()
- Specified by:
normalizein interfacejava.nio.file.Path
-
isNormal
private boolean isNormal()
Returns whether or not this path is in a normalized form. It's normal if it both contains no "." names and contains no ".." names in a location other than the start of the path.
-
resolve
ZeroFsPath resolve(Name name)
Resolves the given name against this path. The name is assumed not to be a root name.
-
resolve
public ZeroFsPath resolve(java.nio.file.Path other)
- Specified by:
resolvein interfacejava.nio.file.Path
-
resolve
public ZeroFsPath resolve(java.lang.String other)
- Specified by:
resolvein interfacejava.nio.file.Path
-
resolveSibling
public ZeroFsPath resolveSibling(java.nio.file.Path other)
- Specified by:
resolveSiblingin interfacejava.nio.file.Path
-
resolveSibling
public ZeroFsPath resolveSibling(java.lang.String other)
- Specified by:
resolveSiblingin interfacejava.nio.file.Path
-
relativize
public ZeroFsPath relativize(java.nio.file.Path other)
- Specified by:
relativizein interfacejava.nio.file.Path
-
toAbsolutePath
public ZeroFsPath toAbsolutePath()
- Specified by:
toAbsolutePathin interfacejava.nio.file.Path
-
toRealPath
public ZeroFsPath toRealPath(java.nio.file.LinkOption... options) throws java.io.IOException
- Specified by:
toRealPathin interfacejava.nio.file.Path- Throws:
java.io.IOException
-
register
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers) throws java.io.IOException- Specified by:
registerin interfacejava.nio.file.Path- Specified by:
registerin interfacejava.nio.file.Watchable- Throws:
java.io.IOException
-
register
public java.nio.file.WatchKey register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events) throws java.io.IOException- Specified by:
registerin interfacejava.nio.file.Path- Specified by:
registerin interfacejava.nio.file.Watchable- Throws:
java.io.IOException
-
toUri
public java.net.URI toUri()
- Specified by:
toUriin interfacejava.nio.file.Path
-
toFile
public java.io.File toFile()
- Specified by:
toFilein interfacejava.nio.file.Path
-
iterator
public java.util.Iterator<java.nio.file.Path> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<java.nio.file.Path>- Specified by:
iteratorin interfacejava.nio.file.Path
-
asList
private java.util.List<java.nio.file.Path> asList()
-
compareTo
public int compareTo(java.nio.file.Path other)
- Specified by:
compareToin interfacejava.lang.Comparable<java.nio.file.Path>- Specified by:
compareToin interfacejava.nio.file.Path
-
equals
public boolean equals(java.lang.Object obj)
- Specified by:
equalsin interfacejava.nio.file.Path- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfacejava.nio.file.Path- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Specified by:
toStringin interfacejava.nio.file.Path- Overrides:
toStringin classjava.lang.Object
-
checkPath
private ZeroFsPath checkPath(java.nio.file.Path other)
-
-