java.lang.Object
com.aoapps.net.Path
- All Implemented Interfaces:
DtoFactory<Path>,Internable<Path>,Serializable,Comparable<Path>
public final class Path
extends Object
implements Comparable<Path>, Serializable, DtoFactory<Path>, Internable<Path>
Represents a full path. Paths must:
- Be non-null
- Be non-empty
- Start with a
/ - Not contain any null characters
- Not contain any /../ or /./ path elements
- Not end with /.. or /.
- Not contain any // in the path
Note, this concept of path is minimally restrictive and only represents a well-formed path. The path may not be valid for some contexts, such as the path part of a URL. This does not implement RFC 3986.
TODO: Should we disallow any number path element that is all dots, such as "...." and not just "." and ".."?
TODO: This matches UnixPath in aoserv-client with the exception of allowing trailing slash.
Remove this redundancy?
- Author:
- AO Industries, Inc.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionintbooleangetDto()inthashCode()intern()Interns this path much in the same fashion asString.intern().prefix(int len) Gets a prefix path of the given length.subPath(int beginIndex, int endIndex) Gets a sub path of the given beginning and end.suffix(int beginIndex) Gets a suffix path starting at the given index.toString()static ValidationResultstatic Path
-
Field Details
-
SEPARATOR_CHAR
public static final char SEPARATOR_CHARThe path separator as a char'/'.- See Also:
-
SEPARATOR_STRING
The path separator as a single-character String"/". -
ROOT
The root path"/". This is implemented as a singleton as is safe for direct object equality check "==".
-
-
Method Details
-
validate
-
valueOf
- Parameters:
path- whennull, returnsnull- Throws:
ValidationException
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareToin interfaceComparable<Path>
-
toString
-
intern
Interns this path much in the same fashion asString.intern().- Specified by:
internin interfaceInternable<Path>- See Also:
-
getDto
- Specified by:
getDtoin interfaceDtoFactory<Path>
-
subPath
public Path subPath(int beginIndex, int endIndex) throws IllegalArgumentException, IndexOutOfBoundsException Gets a sub path of the given beginning and end.- Parameters:
beginIndex- Must align with aSEPARATOR_CHAR.endIndex- One-past the last character to include. Must be greater thanbeginIndex.- Throws:
IllegalArgumentExceptionIndexOutOfBoundsException- See Also:
-
prefix
Gets a prefix path of the given length.Implementation Note:
CallssubPath(0, len)- Parameters:
len- Must be greater than0.- Throws:
IllegalArgumentExceptionIndexOutOfBoundsException- See Also:
-
suffix
Gets a suffix path starting at the given index.Implementation Note:
CallssubPath(beginIndex, path.length())- Parameters:
beginIndex- Must align with aSEPARATOR_CHAR.- Throws:
IllegalArgumentExceptionIndexOutOfBoundsException- See Also:
-
