public final class PathVirtual extends Object implements Comparable<PathVirtual>
A virtual path represents a path in the virtual filesystem.
Virtual paths are always absolute.
The concrete syntax of virtual paths is given by the following EBNF grammar
(where name
indicates a string representing a valid name):
path = "/" , [ name , ("/" , name)* ] ;
A virtual path is conceptually a list of names, with the empty list representing the root directory.
Name.isValid(String)
Modifier and Type | Field and Description |
---|---|
static PathVirtual |
ROOT
A virtual path representing the root directory.
|
Modifier and Type | Method and Description |
---|---|
PathVirtual |
append(PathVirtual p)
Append all elements of
p to the current path, returning a
new path. |
PathVirtual |
appendName(String name)
Append the name
name to the current path, returning a new
path. |
int |
compareTo(PathVirtual o)
The ordering relation for virtual paths.
|
boolean |
equals(Object obj) |
com.io7m.jfunctional.OptionType<String> |
getBaseName()
Retrieve the last element of this path.
|
int |
hashCode() |
boolean |
isAncestorOf(PathVirtual p)
Determine whether the current path is an ancestor of
p . |
boolean |
isParentOf(PathVirtual p)
Determine whether the current path is the parent of
p . |
boolean |
isRoot() |
int |
length() |
static PathVirtual |
ofNames(List<String> names)
Produce a virtual path from the list of names.
|
static PathVirtual |
ofString(String path)
Parse the given
path according to the EBNF grammar given at
the start of this file, and produce a virtual path. |
static PathVirtual |
ofStringLax(String path)
Normalize
path by stripping trailing slashes and eliminating
multiple consecutive slashes, and then pass the result to
ofString(String) . |
PathVirtual |
subtract(PathVirtual other)
"Subtract" the path
other from the current path. |
String |
toString() |
public static final PathVirtual ROOT
A virtual path representing the root directory.
public static PathVirtual ofNames(List<String> names) throws FilesystemError
Produce a virtual path from the list of names. The list is assumed to be
in the correct order. That is, the path /usr/bin/ps
would be
represented by the list of names "usr" "bin" "ps"
, in that
order.
names
- The list of namesFilesystemError
- If any of the given names are not validName.isValid(String)
public static PathVirtual ofString(String path) throws FilesystemError
Parse the given path
according to the EBNF grammar given at
the start of this file, and produce a virtual path.
path
- The path to be parsedFilesystemError
- If the given path does not conform to the given grammar (such
as being empty, not absolute, or containing a name that is not
valid).Name.isValid(String)
public static PathVirtual ofStringLax(String path) throws FilesystemError
Normalize path
by stripping trailing slashes and eliminating
multiple consecutive slashes, and then pass the result to
ofString(String)
.
path
- The path to be parsedFilesystemError
- If the path is not validpublic PathVirtual append(PathVirtual p)
Append all elements of p
to the current path, returning a
new path.
p
- The other pathpublic PathVirtual appendName(String name) throws FilesystemError
Append the name name
to the current path, returning a new
path.
name
- The name to appendname
appendedFilesystemError
- If the given name is not validName.isValid(String)
public int compareTo(PathVirtual o)
The ordering relation for virtual paths.
p0.size() < p1.size()
, then p0 < p1
p0.size() > p1.size()
, then p0 > p1
p0.size() == p1.size()
, then:
∃i. p0[i] < p1[i] → p0 < p1
∃i. p0[i] > p1[i] → p0 > p1
p0 == p1
.compareTo
in interface Comparable<PathVirtual>
o
- The other pathpublic com.io7m.jfunctional.OptionType<String> getBaseName()
None
iff this path is empty.public boolean isAncestorOf(PathVirtual p)
Determine whether the current path is an ancestor of p
.
p0
is an ancestor of p1
iff:
p0 != p1 /\ ∃ p : PathVirtual. p0.append(p) == p1
p
- The path that may be an ancestor of the current pathtrue
if the current path is an ancestor of
p
.public boolean isParentOf(PathVirtual p)
Determine whether the current path is the parent of p
.
p0
is the parent of p1
iff:
∃ n : String. p0.appendName(n) == p1
p
- The path that may be an ancestor of the current pathtrue
if the current path is the parent of
p
.public boolean isRoot()
true
if this path is the root path.public int length()
public PathVirtual subtract(PathVirtual other)
"Subtract" the path other
from the current path.
The subtraction of p1
from p0
is defined as
removing the first p1.length
elements of p0
, if
p0
is an ancestor of or is equal to p1
.
other
- The other pathother
subtracted.Copyright © 2015 <code@io7m.com> http://io7m.com