Package com.mastfrog.url
Class Path
java.lang.Object
com.mastfrog.url.Path
- All Implemented Interfaces:
URLComponent,Serializable,Iterable<PathElement>
The path portion of a URL. In particular, this class deals with normalizing
relative (..) references, and leading and trailing slashes.
- Author:
- Tim Boudreau
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAppend this component to a StringBuilder.static AbstractBuilder<PathElement,Path> builder()final PathbooleanGet a Path which does not include the first element of this path.Get a human-readable, localized name for this part of the URL.getElement(int ix) Get the individual elements of this path.Get the parent of this path.inthashCode()booleanDetermine if this path is a path to a child of the passed path.booleanisParentOf(Path path) Determine if this path is a path to a parent of the passed path.booleanDetermine if this path is probably a reference to a file (last element contains a .booleanisValid()Determine if this component is in compliance with the RFCs governing URLs and DNS.iterator()booleanReturns true if the last path element is a textual match for the passed CharSequence, considering case.booleanlastElementMatches(CharSequence s, boolean ignoreCase) Returns true if the last path element is a textual match for the passed CharSequence, ignoring case if the passed boolean flag is true.static PathMerge an array of paths togetherNormalize a path, resolving..elements.static PathParse a path in the formatelement1/element2/element3static PathCreate a new path, replacing any path elements that exactly match the passed string with new elements that match the replacement.intsize()Get the number of elements in this path.toString()String[]Create a string version of this path, prepending a leading slash if necessary.toURI()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Path
-
-
Method Details
-
parse
Parse a path in the formatelement1/element2/element3- Parameters:
path-- Returns:
-
parse
-
toURLDecodedPath
-
iterator
- Specified by:
iteratorin interfaceIterable<PathElement>
-
lastElement
-
normalize
Normalize a path, resolving..elements.- Returns:
- A path
-
replace
Create a new path, replacing any path elements that exactly match the passed string with new elements that match the replacement.- Parameters:
old- The string to look fornue- The string to replace it with- Returns:
- A path
-
elideEmptyElements
-
prepend
-
append
-
merge
Merge an array of paths together- Parameters:
paths- An array of paths- Returns:
- A merged path which appends all elements of all passed paths
-
isParentOf
Determine if this path is a path to a parent of the passed path. E.g.assert Path.parse ("com/foo").isParentOf(Path.parse("com/foo/bar")) == true;- Parameters:
path- A path- Returns:
- whether or not this path is a parent of the passed path.
-
isChildOf
Determine if this path is a path to a child of the passed path. E.g.assert Path.parse ("com/foo/bar").isChildOf(Path.parse("com/foo")) == true;- Parameters:
path- a path- Returns:
- whether or not this Path is a child of the passed Path
-
size
public int size()Get the number of elements in this path.- Returns:
-
getElements
Get the individual elements of this path.- Returns:
- An array of elements
-
getChildPath
Get a Path which does not include the first element of this path. E.g. the child path ofcom/foo/barisfoo/bar.- Returns:
- A child path
-
toStringWithLeadingSlash
Create a string version of this path, prepending a leading slash if necessary.- Returns:
- A string
-
getParentPath
Get the parent of this path. E.g. the parent ofcom/foo/bariscom/foo.- Returns:
- A path
-
lastElementMatches
Returns true if the last path element is a textual match for the passed CharSequence, considering case.- Parameters:
s- The string to match- Returns:
- True if it matches
-
lastElementMatches
Returns true if the last path element is a textual match for the passed CharSequence, ignoring case if the passed boolean flag is true.- Parameters:
s- The string to matchignoreCase- Whether or not to do a case-insensitive match- Returns:
- True if it matches
-
toString
-
builder
-
isValid
public boolean isValid()Description copied from interface:URLComponentDetermine if this component is in compliance with the RFCs governing URLs and DNS.- Specified by:
isValidin interfaceURLComponent- Returns:
- True if this component is valid.
-
getComponentName
Description copied from interface:URLComponentGet a human-readable, localized name for this part of the URL. Useful if an error message needs to be shown.- Specified by:
getComponentNamein interfaceURLComponent- Returns:
- The component name
-
isProbableFileReference
public boolean isProbableFileReference()Determine if this path is probably a reference to a file (last element contains a . character). May be used to decide whether or not to append a '/' character.- Returns:
- true if this is a probable file.
-
appendTo
Description copied from interface:URLComponentAppend this component to a StringBuilder.- Specified by:
appendToin interfaceURLComponent- Parameters:
sb- A StringBuilder
-
getElement
-
getLastElement
-
equals
-
hashCode
public int hashCode() -
toURI
-
toURIWithLeadingSlash
-
toStringArray
-