Class Location
java.lang.Object
com.polarion.subterra.base.location.Location
- All Implemented Interfaces:
ILocation
,Serializable
Sole implementation of
ILocation
.- Author:
- Stepan Roh, Polarion Software
- See Also:
-
Field Summary
Fields inherited from interface com.polarion.subterra.base.location.ILocation
COMPONENT_DELIM, COMPONENT_DELIM_CHAR
-
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 asILocation.containsComponentSequence(List)
but sequence defined as String (e.f.boolean
containsComponentSequence
(List sequence) Shortcut forfindComponentSequence(sequence) != -1
boolean
Whether this location has repository name.static ILocation
deserializeLocation
(String strLocation) Converts the string representation produced byILocation.serialize()
back into object.deserializeLocations
(String strLocs) boolean
int
findComponentSequence
(String sequence) Same asILocation.findComponentSequence(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'sILocation.getComponents()
.getAbsoluteLocation
(ILocation root) Compute absolute location from root location and this location and return new location.static ILocation
Canonicalize given 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.static ILocation
getLocation
(String locPath) Return location for given location path.static ILocation
getLocation
(String repoName, String locPath, String revisionName) Returns location for given parameters.Return location path.static ILocation
getLocationWithRepository
(String repoName, String locPath) Return location for given repository name and location path.static ILocation
getLocationWithRepositoryAndRevision
(String repoName, String locPath, String revision) Return location for given repository name, location path and revision.static ILocation
getLocationWithRevision
(String locPath, String revision) Return location for given location path and revision.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).int
hashCode()
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).parseSequence
(String sequence) 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
.static String
serialize
(Collection<ILocation> locs) 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 asILocation.startsWithComponentSequence(List)
but sequence defined as String (e.f.boolean
startsWithComponentSequence
(List sequence) Shortcut forfindComponentSequence(sequence) == 0
toString()
-
Method Details
-
getLocationWithRepositoryAndRevision
public static ILocation getLocationWithRepositoryAndRevision(String repoName, String locPath, String revision) Return location for given repository name, location path and revision.- Parameters:
repoName
- repository namelocPath
- location pathrevision
- revision- Returns:
- new location
- Throws:
IllegalArgumentException
- if given location path is relativeIllegalArgumentException
- if given repository name isnull
IllegalArgumentException
- if given location path isnull
IllegalArgumentException
- if given revision isnull
-
getLocationWithRevision
Return location for given location path and revision.- Parameters:
locPath
- location pathrevision
- revision- Returns:
- new location
- Throws:
IllegalArgumentException
- if given location path isnull
IllegalArgumentException
- if given revision isnull
-
getLocationWithRepository
Return location for given repository name and location path.- Parameters:
repoName
- repository namelocPath
- location path- Returns:
- new location
- Throws:
IllegalArgumentException
- if given location path is relativeIllegalArgumentException
- if given repository name isnull
IllegalArgumentException
- if given location path isnull
-
getLocation
Return location for given location path.- Parameters:
locPath
- location path- Returns:
- new location
- Throws:
IllegalArgumentException
- if given location path isnull
-
getLocation
Returns location for given parameters. Unlike factory methods with specialized names, this implementation does allownull
repoName
andrevisionName
.- Parameters:
repoName
-locPath
-revisionName
-- Returns:
- new location
-
containsRepositoryName
public boolean containsRepositoryName()Description copied from interface:ILocation
Whether this location has repository name.- Specified by:
containsRepositoryName
in interfaceILocation
- Returns:
true
if this location contains repository name
-
isRelative
public boolean isRelative()Description copied from interface:ILocation
Whether this location is relative (locations with repository names are always absolute).- Specified by:
isRelative
in interfaceILocation
- Returns:
true
if this location is relative
-
getAbsoluteLocation
Description copied from interface:ILocation
Compute absolute location from root location and this location and return new location.- Specified by:
getAbsoluteLocation
in interfaceILocation
- Parameters:
root
- root absolute location- Returns:
- new location or this location if it is already absolute
-
getRelativeLocation
Description copied from interface:ILocation
Relativize this location against given root (which may be relative) and return new location.- Specified by:
getRelativeLocation
in interfaceILocation
- Parameters:
root
- root location- Returns:
- new location
-
hasRootLocation
Description copied from interface:ILocation
Whether given location is root of this location.Positive answer allows
ILocation.getRelativeLocation(ILocation)
to succeed.- Specified by:
hasRootLocation
in interfaceILocation
- Parameters:
root
- root location- Returns:
true
if given location is root of this location
-
getComponentCount
public int getComponentCount()- Specified by:
getComponentCount
in interfaceILocation
- Returns:
- Number of components in this location, or path depth.
-
getLastComponent
Description copied from interface:ILocation
Return last component of this location.Same as
getComponent(getComponentCount()-1)
- Specified by:
getLastComponent
in interfaceILocation
- Returns:
- last component name or
null
for empty location - See Also:
-
getLastComponentExtension
Description copied from interface:ILocation
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. ifILocation.getLastComponent()
returns null).- Specified by:
getLastComponentExtension
in interfaceILocation
-
getLastComponentWithoutExtension
Description copied from interface:ILocation
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. ifILocation.getLastComponent()
returns null).- Specified by:
getLastComponentWithoutExtension
in interfaceILocation
-
getFirstComponent
Description copied from interface:ILocation
Returns the first coponent of this location.Same as
getComponent(0)
- Specified by:
getFirstComponent
in interfaceILocation
- Returns:
- first component name or
null
for empty location - See Also:
-
getComponent
Description copied from interface:ILocation
Returnsn-th
component of the location. The n can range from 0 (first component) togetComponentCount()-1
(lastComponent).- Specified by:
getComponent
in interfaceILocation
- Returns:
- The given component or
null
if such component does not exist in this location. - See Also:
-
getComponents
Description copied from interface:ILocation
The resulting list is unmodifiable.- Specified by:
getComponents
in interfaceILocation
- Returns:
- The list of string component names, as if returned by
ILocation.getComponent(int)
, the list lenght is the same asILocation.getComponentCount()
.
-
findComponentSequence
Description copied from interface:ILocation
Searches this path components for the given sequence and if found, returns the position of the first component from the sequence in this location'sILocation.getComponents()
.- Specified by:
findComponentSequence
in interfaceILocation
- Parameters:
sequence
- List ofString
- Returns:
- Position of first component from sequence or -1 if not found.
-
findComponentSequence
Description copied from interface:ILocation
Same asILocation.findComponentSequence(List)
but sequence defined as String (e.g. "/some/sequence") the leading and trailing slashes are ignored.- Specified by:
findComponentSequence
in interfaceILocation
- Returns:
- Position of first component from sequence or -1 if not found.
-
containsComponentSequence
Description copied from interface:ILocation
Shortcut forfindComponentSequence(sequence) != -1
- Specified by:
containsComponentSequence
in interfaceILocation
- Parameters:
sequence
- List ofString
- Returns:
true
if this location contains the specified sequence- See Also:
-
containsComponentSequence
Description copied from interface:ILocation
Same asILocation.containsComponentSequence(List)
but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.- Specified by:
containsComponentSequence
in interfaceILocation
- Returns:
true
if this location contains the specified sequence
-
containsComponent
- Specified by:
containsComponent
in interfaceILocation
-
startsWithComponentSequence
Description copied from interface:ILocation
Shortcut forfindComponentSequence(sequence) == 0
- Specified by:
startsWithComponentSequence
in interfaceILocation
- Returns:
true
if this location strts with the specified sequence- See Also:
-
startsWithComponentSequence
Description copied from interface:ILocation
Same asILocation.startsWithComponentSequence(List)
but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.- Specified by:
startsWithComponentSequence
in interfaceILocation
- Returns:
true
if this location strts with the specified sequence
-
parseSequence
-
removeFirstComponents
Description copied from interface:ILocation
Removes the firstn
components from the location path.- Specified by:
removeFirstComponents
in interfaceILocation
- Returns:
- Returns
this
ifn == 0
or relative location, obtained fromthis
by removingn
components.
-
setComponent
Description copied from interface:ILocation
Creates new location, which is same as this one, but hasnewComponent
on thenth
place.- Specified by:
setComponent
in interfaceILocation
- Parameters:
n
- Component number, 0..getComponentCount() (inclusive, exclusive)newComponent
- the new content of the component to be replaced- Returns:
- the component with replaced component
-
addOneComponentTowards
Description copied from interface:ILocation
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/
- Specified by:
addOneComponentTowards
in interfaceILocation
- Parameters:
path
- Such thatthis.getLocationPath()
is parent of the given path.- Returns:
- New locations, such that
new_location.getParentLocation().equals(this)
.
-
append
Description copied from interface:ILocation
Append given location path to this location and return new location. -
append
Description copied from interface:ILocation
Append given location to this location and return new location. Revision of given location is ignored. -
getRepositoryName
Description copied from interface:ILocation
Return repository name (if any).- Specified by:
getRepositoryName
in interfaceILocation
- Returns:
- repository name or
null
-
setRepositoryName
Description copied from interface:ILocation
Returns new location with specified repository name.- Specified by:
setRepositoryName
in interfaceILocation
- Returns:
- new location
-
removeRepositoryName
Description copied from interface:ILocation
Remove repository name (if any) from this location and return new location.- Specified by:
removeRepositoryName
in interfaceILocation
- Returns:
- new location
-
getLocationPath
Description copied from interface:ILocation
Return location path.- Specified by:
getLocationPath
in interfaceILocation
- Returns:
- location path
-
getParentLocation
Description copied from interface:ILocation
Return parent location (location without last component).- Specified by:
getParentLocation
in interfaceILocation
- Returns:
- new location or
null
if there is no parent
-
equals
-
hashCode
public int hashCode() -
toString
-
getRevision
Description copied from interface:ILocation
Return revision (if any).- Specified by:
getRevision
in interfaceILocation
- Returns:
- revision or
null
-
removeRevision
Description copied from interface:ILocation
Remove revision from this location and return new location.- Specified by:
removeRevision
in interfaceILocation
- Returns:
- new location
-
setRevision
Description copied from interface:ILocation
Set revision of this location and return new location.- Specified by:
setRevision
in interfaceILocation
- Parameters:
revision
- revision- Returns:
- new location
-
replaceLocationPath
Description copied from interface:ILocation
Replace current location path with given location path and return new location.- Specified by:
replaceLocationPath
in interfaceILocation
- Parameters:
locPath
- location path to replace with- Returns:
- new location
-
hasRevision
public boolean hasRevision()Description copied from interface:ILocation
Whether this location has revision.- Specified by:
hasRevision
in interfaceILocation
- Returns:
true
if this location has revision
-
deserializeLocation
Converts the string representation produced byILocation.serialize()
back into object.- Parameters:
strLocation
- TheString
representation.- Returns:
- Parsed
ILocation
- Throws:
IllegalArgumentException
- If the string is not valid location.
-
deserializeLocations
- Since:
- 3.5.2
-
serialize
- Since:
- 3.5.2
-
serialize
Description copied from interface:ILocation
Converts the location intoString
. The exact format of the resulting string is not defined. UsedeserializeLocation(String)
to convert the resulting string back to object.The resulting
String
should be human readable. -
getCanonicalLocation
Canonicalize given location.Location path component "." is removed, ".." is removed together with its predecessor.
- Parameters:
loc
- location to canonicalize- Returns:
- canonicalized location (not
null
) - Throws:
IllegalArgumentException
- if loc is null
-