Package com.google.common.jimfs
Class JimfsPath
- java.lang.Object
-
- com.google.common.jimfs.JimfsPath
-
- 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 JimfsPath extends java.lang.Object implements java.nio.file.Path
Jimfs implementation ofPath
. Creation of newPath
objects is delegated to the file system'sPathService
.
-
-
Field Summary
Fields Modifier and Type Field Description private com.google.common.collect.ImmutableList<Name>
names
private PathService
pathService
private @Nullable Name
root
-
Constructor Summary
Constructors Constructor Description JimfsPath(PathService pathService, @Nullable Name root, java.lang.Iterable<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 @Nullable JimfsPath
checkPath(java.nio.file.Path other)
int
compareTo(java.nio.file.Path other)
boolean
endsWith(java.lang.String other)
boolean
endsWith(java.nio.file.Path other)
boolean
equals(@Nullable java.lang.Object obj)
@Nullable JimfsPath
getFileName()
java.nio.file.FileSystem
getFileSystem()
JimfsFileSystem
getJimfsFileSystem()
Equivalent togetFileSystem()
but with a return type ofJimfsFileSystem
.JimfsPath
getName(int index)
int
getNameCount()
@Nullable JimfsPath
getParent()
@Nullable JimfsPath
getRoot()
int
hashCode()
boolean
isAbsolute()
boolean
isEmptyPath()
Returns whether or not this is the empty path, with no root and a single, empty string, name.private boolean
isNormal()
Returns whether or not this path is in a normalized form.java.util.Iterator<java.nio.file.Path>
iterator()
@Nullable Name
name()
Returns the file name of this path.com.google.common.collect.ImmutableList<Name>
names()
Returns the list of name elements.JimfsPath
normalize()
java.nio.file.WatchKey
register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>... events)
java.nio.file.WatchKey
register(java.nio.file.WatchService watcher, java.nio.file.WatchEvent.Kind<?>[] events, java.nio.file.WatchEvent.Modifier... modifiers)
JimfsPath
relativize(java.nio.file.Path other)
(package private) JimfsPath
resolve(Name name)
Resolves the given name against this path.JimfsPath
resolve(java.lang.String other)
JimfsPath
resolve(java.nio.file.Path other)
JimfsPath
resolveSibling(java.lang.String other)
JimfsPath
resolveSibling(java.nio.file.Path other)
@Nullable Name
root()
Returns the root name, or null if there is no root.boolean
startsWith(java.lang.String other)
boolean
startsWith(java.nio.file.Path other)
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.JimfsPath
subpath(int beginIndex, int endIndex)
JimfsPath
toAbsolutePath()
java.io.File
toFile()
JimfsPath
toRealPath(java.nio.file.LinkOption... options)
java.lang.String
toString()
java.net.URI
toUri()
-
-
-
Field Detail
-
root
private final @Nullable Name root
-
names
private final com.google.common.collect.ImmutableList<Name> names
-
pathService
private final PathService pathService
-
-
Constructor Detail
-
JimfsPath
public JimfsPath(PathService pathService, @Nullable Name root, java.lang.Iterable<Name> names)
-
-
Method Detail
-
root
public @Nullable Name root()
Returns the root name, or null if there is no root.
-
names
public com.google.common.collect.ImmutableList<Name> names()
Returns the list of name elements.
-
name
public @Nullable 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:
getFileSystem
in interfacejava.nio.file.Path
-
getJimfsFileSystem
public JimfsFileSystem getJimfsFileSystem()
Equivalent togetFileSystem()
but with a return type ofJimfsFileSystem
.getFileSystem()
's return type is left asFileSystem
to 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:
isAbsolute
in interfacejava.nio.file.Path
-
getRoot
public @Nullable JimfsPath getRoot()
- Specified by:
getRoot
in interfacejava.nio.file.Path
-
getFileName
public @Nullable JimfsPath getFileName()
- Specified by:
getFileName
in interfacejava.nio.file.Path
-
getParent
public @Nullable JimfsPath getParent()
- Specified by:
getParent
in interfacejava.nio.file.Path
-
getNameCount
public int getNameCount()
- Specified by:
getNameCount
in interfacejava.nio.file.Path
-
getName
public JimfsPath getName(int index)
- Specified by:
getName
in interfacejava.nio.file.Path
-
subpath
public JimfsPath subpath(int beginIndex, int endIndex)
- Specified by:
subpath
in 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:
startsWith
in interfacejava.nio.file.Path
-
startsWith
public boolean startsWith(java.lang.String other)
- Specified by:
startsWith
in interfacejava.nio.file.Path
-
endsWith
public boolean endsWith(java.nio.file.Path other)
- Specified by:
endsWith
in interfacejava.nio.file.Path
-
endsWith
public boolean endsWith(java.lang.String other)
- Specified by:
endsWith
in interfacejava.nio.file.Path
-
normalize
public JimfsPath normalize()
- Specified by:
normalize
in 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
JimfsPath resolve(Name name)
Resolves the given name against this path. The name is assumed not to be a root name.
-
resolve
public JimfsPath resolve(java.nio.file.Path other)
- Specified by:
resolve
in interfacejava.nio.file.Path
-
resolve
public JimfsPath resolve(java.lang.String other)
- Specified by:
resolve
in interfacejava.nio.file.Path
-
resolveSibling
public JimfsPath resolveSibling(java.nio.file.Path other)
- Specified by:
resolveSibling
in interfacejava.nio.file.Path
-
resolveSibling
public JimfsPath resolveSibling(java.lang.String other)
- Specified by:
resolveSibling
in interfacejava.nio.file.Path
-
relativize
public JimfsPath relativize(java.nio.file.Path other)
- Specified by:
relativize
in interfacejava.nio.file.Path
-
toAbsolutePath
public JimfsPath toAbsolutePath()
- Specified by:
toAbsolutePath
in interfacejava.nio.file.Path
-
toRealPath
public JimfsPath toRealPath(java.nio.file.LinkOption... options) throws java.io.IOException
- Specified by:
toRealPath
in 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:
register
in interfacejava.nio.file.Path
- Specified by:
register
in 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:
register
in interfacejava.nio.file.Path
- Specified by:
register
in interfacejava.nio.file.Watchable
- Throws:
java.io.IOException
-
toUri
public java.net.URI toUri()
- Specified by:
toUri
in interfacejava.nio.file.Path
-
toFile
public java.io.File toFile()
- Specified by:
toFile
in interfacejava.nio.file.Path
-
iterator
public java.util.Iterator<java.nio.file.Path> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<java.nio.file.Path>
- Specified by:
iterator
in 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:
compareTo
in interfacejava.lang.Comparable<java.nio.file.Path>
- Specified by:
compareTo
in interfacejava.nio.file.Path
-
equals
public boolean equals(@Nullable java.lang.Object obj)
- Specified by:
equals
in interfacejava.nio.file.Path
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Specified by:
hashCode
in interfacejava.nio.file.Path
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Specified by:
toString
in interfacejava.nio.file.Path
- Overrides:
toString
in classjava.lang.Object
-
checkPath
private @Nullable JimfsPath checkPath(java.nio.file.Path other)
-
-