Interface ILocation
- All Known Implementing Classes:
Location
Location
.
The notion of repository is in domain of the user of this interface. It may be anything from server URL to inner file directory id. There are no restrictions on repository names. Repository names are case-sensitive.
Resource location inside the repository is represented by
location path. Location path is broken down to location components
which are concatenated with slash ('/'; COMPONENT_DELIM
and COMPONENT_DELIM_CHAR
).
Component can't contain slash ('/') or backslash ('\').
Absolute location path starts with slash.
Location paths are case-sensitive.
If the path contain more slashes in row, then they are automatically
replaced by one slash (e.g. "my//folder"
becomes "my/folder"
)
during ILocation
creation.
Trailing slashes are stripped from location paths as early as possible.
Location may optionally contain revision which is an arbitrary string.
Implementations of this class must be immutable.
- Author:
- Stepan Roh, Polarion Software
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddOneComponentTowards
(String path) Returns the location for which it holds:new_location.getParentLocation().equals(this)
The extra segment is taken from the given path.Append given location to this location and return new location.Append given location path to this location and return new location.boolean
containsComponent
(String component) boolean
containsComponentSequence
(String sequence) Same ascontainsComponentSequence(List)
but sequence defined as String (e.f.boolean
containsComponentSequence
(List sequence) Shortcut forfindComponentSequence(sequence) != -1
boolean
Whether this location has repository name.int
findComponentSequence
(String sequence) Same asfindComponentSequence(List)
but sequence defined as String (e.g.int
findComponentSequence
(List sequence) Searches this path components for the given sequence and if found, returns the position of the first component from the sequence in this location'sgetComponents()
.getAbsoluteLocation
(ILocation root) Compute absolute location from root location and this location and return new location.getComponent
(int n) Returnsn-th
component of the location.int
The resulting list is unmodifiable.Returns the first coponent of this location.Return last component of this location.Returns the extension of the last component of this location, i.e.Returns the last component of this location without the extension, i.e.Return location path.Return parent location (location without last component).getRelativeLocation
(ILocation root) Relativize this location against given root (which may be relative) and return new location.Return repository name (if any).Return revision (if any).boolean
Whether this location has revision.boolean
hasRootLocation
(ILocation root) Whether given location is root of this location.boolean
Whether this location is relative (locations with repository names are always absolute).removeFirstComponents
(int n) Removes the firstn
components from the location path.Remove repository name (if any) from this location and return new location.Remove revision from this location and return new location.replaceLocationPath
(String locPath) Replace current location path with given location path and return new location.Converts the location intoString
.setComponent
(int n, String newComponent) Creates new location, which is same as this one, but hasnewComponent
on thenth
place.setRepositoryName
(String repositoryName) Returns new location with specified repository name.setRevision
(String revision) Set revision of this location and return new location.boolean
startsWithComponentSequence
(String sequence) Same asstartsWithComponentSequence(List)
but sequence defined as String (e.f.boolean
startsWithComponentSequence
(List sequence) Shortcut forfindComponentSequence(sequence) == 0
-
Field Details
-
COMPONENT_DELIM
Location component delimiter (asString
).- See Also:
-
COMPONENT_DELIM_CHAR
static final char COMPONENT_DELIM_CHARLocation component delimiter (aschar
).- See Also:
-
-
Method Details
-
containsRepositoryName
boolean containsRepositoryName()Whether this location has repository name.- Returns:
true
if this location contains repository name
-
isRelative
boolean isRelative()Whether this location is relative (locations with repository names are always absolute).- Returns:
true
if this location is relative
-
getAbsoluteLocation
Compute absolute location from root location and this location and return new location.- Parameters:
root
- root absolute location- Returns:
- new location or this location if it is already absolute
- Throws:
IllegalArgumentException
- if root isnull
IllegalArgumentException
- if given root is not absoluteIllegalArgumentException
- if repositories differ
-
getRelativeLocation
Relativize this location against given root (which may be relative) and return new location.- Parameters:
root
- root location- Returns:
- new location
- Throws:
IllegalArgumentException
- if root isnull
IllegalArgumentException
- if given root is not root of this locationIllegalArgumentException
- if repositories differ
-
hasRootLocation
Whether given location is root of this location.Positive answer allows
getRelativeLocation(ILocation)
to succeed.- Parameters:
root
- root location- Returns:
true
if given location is root of this location- Throws:
IllegalArgumentException
- if root isnull
-
getComponentCount
int getComponentCount()- Returns:
- Number of components in this location, or path depth.
-
getLastComponent
String getLastComponent()Return last component of this location.Same as
getComponent(getComponentCount()-1)
- Returns:
- last component name or
null
for empty location - See Also:
-
getLastComponentExtension
Returns the extension of the last component of this location, i.e. the suffix of the last component starting with the last '.'. Returns an empty string if there is no '.' in the last component. Returns null if this location is empty (i.e. ifgetLastComponent()
returns null).- Since:
- 3.17.0
-
getLastComponentWithoutExtension
Returns the last component of this location without the extension, i.e. the prefix of the last component before the last '.'. Returns the entire last component if there is no '.' in it. Returns null if this location is empty (i.e. ifgetLastComponent()
returns null).- Since:
- 3.17.0
-
getFirstComponent
String getFirstComponent()Returns the first coponent of this location.Same as
getComponent(0)
- Returns:
- first component name or
null
for empty location - See Also:
-
getComponent
Returnsn-th
component of the location. The n can range from 0 (first component) togetComponentCount()-1
(lastComponent).- Returns:
- The given component or
null
if such component does not exist in this location. - See Also:
-
getComponents
List getComponents()The resulting list is unmodifiable.- Returns:
- The list of string component names, as if returned by
getComponent(int)
, the list lenght is the same asgetComponentCount()
.
-
findComponentSequence
Searches this path components for the given sequence and if found, returns the position of the first component from the sequence in this location'sgetComponents()
.- Parameters:
sequence
- List ofString
- Returns:
- Position of first component from sequence or -1 if not found.
-
findComponentSequence
Same asfindComponentSequence(List)
but sequence defined as String (e.g. "/some/sequence") the leading and trailing slashes are ignored.- Parameters:
sequence
-- Returns:
- Position of first component from sequence or -1 if not found.
-
containsComponentSequence
Shortcut forfindComponentSequence(sequence) != -1
- Parameters:
sequence
- List ofString
- Returns:
true
if this location contains the specified sequence- See Also:
-
containsComponentSequence
Same ascontainsComponentSequence(List)
but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.- Parameters:
sequence
-- Returns:
true
if this location contains the specified sequence
-
containsComponent
-
startsWithComponentSequence
Shortcut forfindComponentSequence(sequence) == 0
- Parameters:
sequence
-- Returns:
true
if this location strts with the specified sequence- See Also:
-
startsWithComponentSequence
Same asstartsWithComponentSequence(List)
but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.- Parameters:
sequence
-- Returns:
true
if this location strts with the specified sequence
-
removeFirstComponents
Removes the firstn
components from the location path.- Parameters:
n
-- Returns:
- Returns
this
ifn == 0
or relative location, obtained fromthis
by removingn
components. - Throws:
IllegalArgumentException
- Ifn > getComponentCount()
.
-
setComponent
Creates new location, which is same as this one, but hasnewComponent
on thenth
place.- Parameters:
n
- Component number, 0..getComponentCount() (inclusive, exclusive)newComponent
- the new content of the component to be replaced- Returns:
- the component with replaced component
- Throws:
IllegalArgumentException
- ifn
is greater or equal to the component count or negative.IllegalArgumentException
- ifnewComponent
is null or it contains "/" (component separator) character.
-
addOneComponentTowards
Returns the location for which it holds:new_location.getParentLocation().equals(this)
The extra segment is taken from the given path.Example:
this: [REPO]/some/ path: /some/longer/path/to/go result: [REPO]/some/longer/
- Parameters:
path
- Such thatthis.getLocationPath()
is parent of the given path.- Returns:
- New locations, such that
new_location.getParentLocation().equals(this)
. - Throws:
IllegalArgumentException
- if no such exists;
-
append
Append given location path to this location and return new location.- Parameters:
locPath
- location path to append- Returns:
- new location
- Throws:
IllegalArgumentException
- if locPath isnull
IllegalArgumentException
- if given location path is not relative
-
append
Append given location to this location and return new location. Revision of given location is ignored.- Parameters:
loc
- string location to append- Returns:
- new location
- Throws:
IllegalArgumentException
- if loc isnull
IllegalArgumentException
- if given location is not relative
-
getRepositoryName
String getRepositoryName()Return repository name (if any).- Returns:
- repository name or
null
-
setRepositoryName
Returns new location with specified repository name.- Returns:
- new location
- Since:
- 3.17.1
-
removeRepositoryName
ILocation removeRepositoryName()Remove repository name (if any) from this location and return new location.- Returns:
- new location
-
getLocationPath
String getLocationPath()Return location path.- Returns:
- location path
-
getParentLocation
ILocation getParentLocation()Return parent location (location without last component).- Returns:
- new location or
null
if there is no parent
-
getRevision
String getRevision()Return revision (if any).- Returns:
- revision or
null
-
removeRevision
ILocation removeRevision()Remove revision from this location and return new location.- Returns:
- new location
-
setRevision
Set revision of this location and return new location.- Parameters:
revision
- revision- Returns:
- new location
- Throws:
IllegalArgumentException
- if revision isnull
-
replaceLocationPath
Replace current location path with given location path and return new location.- Parameters:
locPath
- location path to replace with- Returns:
- new location
- Throws:
IllegalArgumentException
- if locPath isnull
-
hasRevision
boolean hasRevision()Whether this location has revision.- Returns:
true
if this location has revision
-
serialize
String serialize()Converts the location intoString
. The exact format of the resulting string is not defined. UseLocation.deserializeLocation(String)
to convert the resulting string back to object.The resulting
String
should be human readable.- Returns:
- the serialized form of this location
-