Class Location

java.lang.Object
com.polarion.subterra.base.location.Location
All Implemented Interfaces:
ILocation, Serializable

public final class Location extends Object implements ILocation, Serializable
Sole implementation of ILocation.
Author:
Stepan Roh, Polarion Software
See Also:
  • 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 name
      locPath - location path
      revision - revision
      Returns:
      new location
      Throws:
      IllegalArgumentException - if given location path is relative
      IllegalArgumentException - if given repository name is null
      IllegalArgumentException - if given location path is null
      IllegalArgumentException - if given revision is null
    • getLocationWithRevision

      public static ILocation getLocationWithRevision(String locPath, String revision)
      Return location for given location path and revision.
      Parameters:
      locPath - location path
      revision - revision
      Returns:
      new location
      Throws:
      IllegalArgumentException - if given location path is null
      IllegalArgumentException - if given revision is null
    • getLocationWithRepository

      public static ILocation getLocationWithRepository(String repoName, String locPath)
      Return location for given repository name and location path.
      Parameters:
      repoName - repository name
      locPath - location path
      Returns:
      new location
      Throws:
      IllegalArgumentException - if given location path is relative
      IllegalArgumentException - if given repository name is null
      IllegalArgumentException - if given location path is null
    • getLocation

      public static ILocation getLocation(String locPath)
      Return location for given location path.
      Parameters:
      locPath - location path
      Returns:
      new location
      Throws:
      IllegalArgumentException - if given location path is null
    • getLocation

      public static ILocation getLocation(String repoName, String locPath, String revisionName)
      Returns location for given parameters. Unlike factory methods with specialized names, this implementation does allow null repoName and revisionName.
      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 interface ILocation
      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 interface ILocation
      Returns:
      true if this location is relative
    • getAbsoluteLocation

      public ILocation getAbsoluteLocation(ILocation root)
      Description copied from interface: ILocation
      Compute absolute location from root location and this location and return new location.
      Specified by:
      getAbsoluteLocation in interface ILocation
      Parameters:
      root - root absolute location
      Returns:
      new location or this location if it is already absolute
    • getRelativeLocation

      public ILocation getRelativeLocation(ILocation root)
      Description copied from interface: ILocation
      Relativize this location against given root (which may be relative) and return new location.
      Specified by:
      getRelativeLocation in interface ILocation
      Parameters:
      root - root location
      Returns:
      new location
    • hasRootLocation

      public boolean hasRootLocation(ILocation root)
      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 interface ILocation
      Parameters:
      root - root location
      Returns:
      true if given location is root of this location
    • getComponentCount

      public int getComponentCount()
      Specified by:
      getComponentCount in interface ILocation
      Returns:
      Number of components in this location, or path depth.
    • getLastComponent

      public String getLastComponent()
      Description copied from interface: ILocation
      Return last component of this location.

      Same as getComponent(getComponentCount()-1)

      Specified by:
      getLastComponent in interface ILocation
      Returns:
      last component name or null for empty location
      See Also:
    • getLastComponentExtension

      @Nullable public String 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. if ILocation.getLastComponent() returns null).
      Specified by:
      getLastComponentExtension in interface ILocation
    • getLastComponentWithoutExtension

      @Nullable public String 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. if ILocation.getLastComponent() returns null).
      Specified by:
      getLastComponentWithoutExtension in interface ILocation
    • getFirstComponent

      public String getFirstComponent()
      Description copied from interface: ILocation
      Returns the first coponent of this location.

      Same as getComponent(0)

      Specified by:
      getFirstComponent in interface ILocation
      Returns:
      first component name or null for empty location
      See Also:
    • getComponent

      public String getComponent(int n)
      Description copied from interface: ILocation
      Returns n-th component of the location. The n can range from 0 (first component) to getComponentCount()-1 (lastComponent).
      Specified by:
      getComponent in interface ILocation
      Returns:
      The given component or null if such component does not exist in this location.
      See Also:
    • getComponents

      public List getComponents()
      Description copied from interface: ILocation
      The resulting list is unmodifiable.
      Specified by:
      getComponents in interface ILocation
      Returns:
      The list of string component names, as if returned by ILocation.getComponent(int), the list lenght is the same as ILocation.getComponentCount().
    • findComponentSequence

      public int findComponentSequence(List sequence)
      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's ILocation.getComponents().
      Specified by:
      findComponentSequence in interface ILocation
      Parameters:
      sequence - List of String
      Returns:
      Position of first component from sequence or -1 if not found.
    • findComponentSequence

      public int findComponentSequence(String sequence)
      Description copied from interface: ILocation
      Same as ILocation.findComponentSequence(List) but sequence defined as String (e.g. "/some/sequence") the leading and trailing slashes are ignored.
      Specified by:
      findComponentSequence in interface ILocation
      Returns:
      Position of first component from sequence or -1 if not found.
    • containsComponentSequence

      public boolean containsComponentSequence(List sequence)
      Description copied from interface: ILocation
      Shortcut for findComponentSequence(sequence) != -1
      Specified by:
      containsComponentSequence in interface ILocation
      Parameters:
      sequence - List of String
      Returns:
      true if this location contains the specified sequence
      See Also:
    • containsComponentSequence

      public boolean containsComponentSequence(String sequence)
      Description copied from interface: ILocation
      Same as ILocation.containsComponentSequence(List) but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.
      Specified by:
      containsComponentSequence in interface ILocation
      Returns:
      true if this location contains the specified sequence
    • containsComponent

      public boolean containsComponent(String component)
      Specified by:
      containsComponent in interface ILocation
    • startsWithComponentSequence

      public boolean startsWithComponentSequence(List sequence)
      Description copied from interface: ILocation
      Shortcut for findComponentSequence(sequence) == 0
      Specified by:
      startsWithComponentSequence in interface ILocation
      Returns:
      true if this location strts with the specified sequence
      See Also:
    • startsWithComponentSequence

      public boolean startsWithComponentSequence(String sequence)
      Description copied from interface: ILocation
      Same as ILocation.startsWithComponentSequence(List) but sequence defined as String (e.f. "/some/sequence") the leading and trailing / have no meaning.
      Specified by:
      startsWithComponentSequence in interface ILocation
      Returns:
      true if this location strts with the specified sequence
    • parseSequence

      public static List parseSequence(String sequence)
    • removeFirstComponents

      public ILocation removeFirstComponents(int n)
      Description copied from interface: ILocation
      Removes the first n components from the location path.
      Specified by:
      removeFirstComponents in interface ILocation
      Returns:
      Returns this if n == 0 or relative location, obtained from this by removing n components.
    • setComponent

      public ILocation setComponent(int n, String newComponent)
      Description copied from interface: ILocation
      Creates new location, which is same as this one, but has newComponent on the nth place.
      Specified by:
      setComponent in interface ILocation
      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

      public ILocation addOneComponentTowards(String path)
      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 interface ILocation
      Parameters:
      path - Such that this.getLocationPath() is parent of the given path.
      Returns:
      New locations, such that new_location.getParentLocation().equals(this).
    • append

      public ILocation append(String locPath)
      Description copied from interface: ILocation
      Append given location path to this location and return new location.
      Specified by:
      append in interface ILocation
      Parameters:
      locPath - location path to append
      Returns:
      new location
    • append

      public ILocation append(ILocation loc)
      Description copied from interface: ILocation
      Append given location to this location and return new location. Revision of given location is ignored.
      Specified by:
      append in interface ILocation
      Parameters:
      loc - string location to append
      Returns:
      new location
    • getRepositoryName

      public String getRepositoryName()
      Description copied from interface: ILocation
      Return repository name (if any).
      Specified by:
      getRepositoryName in interface ILocation
      Returns:
      repository name or null
    • setRepositoryName

      @NotNull public ILocation setRepositoryName(@Nullable String repositoryName)
      Description copied from interface: ILocation
      Returns new location with specified repository name.
      Specified by:
      setRepositoryName in interface ILocation
      Returns:
      new location
    • removeRepositoryName

      public ILocation removeRepositoryName()
      Description copied from interface: ILocation
      Remove repository name (if any) from this location and return new location.
      Specified by:
      removeRepositoryName in interface ILocation
      Returns:
      new location
    • getLocationPath

      public String getLocationPath()
      Description copied from interface: ILocation
      Return location path.
      Specified by:
      getLocationPath in interface ILocation
      Returns:
      location path
    • getParentLocation

      public ILocation getParentLocation()
      Description copied from interface: ILocation
      Return parent location (location without last component).
      Specified by:
      getParentLocation in interface ILocation
      Returns:
      new location or null if there is no parent
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getRevision

      public String getRevision()
      Description copied from interface: ILocation
      Return revision (if any).
      Specified by:
      getRevision in interface ILocation
      Returns:
      revision or null
    • removeRevision

      public ILocation removeRevision()
      Description copied from interface: ILocation
      Remove revision from this location and return new location.
      Specified by:
      removeRevision in interface ILocation
      Returns:
      new location
    • setRevision

      public ILocation setRevision(String revision)
      Description copied from interface: ILocation
      Set revision of this location and return new location.
      Specified by:
      setRevision in interface ILocation
      Parameters:
      revision - revision
      Returns:
      new location
    • replaceLocationPath

      public ILocation replaceLocationPath(String locPath)
      Description copied from interface: ILocation
      Replace current location path with given location path and return new location.
      Specified by:
      replaceLocationPath in interface ILocation
      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 interface ILocation
      Returns:
      true if this location has revision
    • deserializeLocation

      public static ILocation deserializeLocation(String strLocation)
      Converts the string representation produced by ILocation.serialize() back into object.
      Parameters:
      strLocation - The String representation.
      Returns:
      Parsed ILocation
      Throws:
      IllegalArgumentException - If the string is not valid location.
    • deserializeLocations

      public static List<ILocation> deserializeLocations(String strLocs)
      Since:
      3.5.2
    • serialize

      public static String serialize(Collection<ILocation> locs)
      Since:
      3.5.2
    • serialize

      public String serialize()
      Description copied from interface: ILocation
      Converts the location into String. The exact format of the resulting string is not defined. Use deserializeLocation(String) to convert the resulting string back to object.

      The resulting String should be human readable.

      Specified by:
      serialize in interface ILocation
      Returns:
      the serialized form of this location
    • getCanonicalLocation

      public static ILocation getCanonicalLocation(ILocation loc)
      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