org.entityfs.el
Class RelativeLocation

java.lang.Object
  extended by org.entityfs.el.AbstractLocation<RelativeLocation>
      extended by org.entityfs.el.RelativeLocation
All Implemented Interfaces:
Serializable, Comparable<RelativeLocation>, EntityLocation<RelativeLocation>

public class RelativeLocation
extends AbstractLocation<RelativeLocation>
implements Serializable, Comparable<RelativeLocation>

Objects of this class describe one entity's location relative to a directory, i.e. a relative path.

Instances of this class are immutable.

Since:
1.0
Author:
Karl Gustafsson
See Also:
Serialized Form

Field Summary
static RelativeLocation CURRENT_DIRECTORY
          This is a constant representing the current directory.
static RelativeLocation PARENT_DIRECTORY
          This is a constant representing the parent directory.
 
Fields inherited from interface org.entityfs.el.EntityLocation
CURRENT_DIRECTORY_STRING, EXTENSION_SEPARATOR, PARENT_DIRECTORY_STRING, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
RelativeLocation(String relpath)
          Create a new relative entity location from a normalized version of the given path.
 
Method Summary
 int compareTo(RelativeLocation el)
           
 RelativeLocation getChildLocation(String name)
          Get the location of the named child entity relative to this location.
 String getLocation()
          Get a string representation of the entity location.
 RelativeLocation getLocation(RelativeLocation loc)
          Get the location of this entity location combined with the given relative location, represented by the same entity location type as this entity location.
 RelativeLocation getParentLocation()
          Get the parent location of this entity location.
 String toString()
           
 
Methods inherited from class org.entityfs.el.AbstractLocation
equals, getBaseName, getExtension, getName, getPathSegmentStack, hashCode, isRootDir
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

CURRENT_DIRECTORY

public static final RelativeLocation CURRENT_DIRECTORY
This is a constant representing the current directory.


PARENT_DIRECTORY

public static final RelativeLocation PARENT_DIRECTORY
This is a constant representing the parent directory.

Constructor Detail

RelativeLocation

public RelativeLocation(String relpath)
                 throws IllegalArgumentException
Create a new relative entity location from a normalized version of the given path.

Parameters:
relpath - The string representation of the path to construct the object from.
Throws:
IllegalArgumentException - If the path is not a valid relative path.
Method Detail

getLocation

public String getLocation()
Description copied from interface: EntityLocation
Get a string representation of the entity location.

This always holds: new ELT(s).equals(new ELT(new ELT(s).getLocation())) == true for all valid entity location strings s and concrete entity location classes ELT.

Specified by:
getLocation in interface EntityLocation<RelativeLocation>
Returns:
The string representation of the entity location.

getParentLocation

public RelativeLocation getParentLocation()
Description copied from interface: EntityLocation
Get the parent location of this entity location.

Specified by:
getParentLocation in interface EntityLocation<RelativeLocation>
Returns:
This entity location's parent location.

getChildLocation

public RelativeLocation getChildLocation(String name)
Description copied from interface: EntityLocation
Get the location of the named child entity relative to this location.

Specified by:
getChildLocation in interface EntityLocation<RelativeLocation>
Parameters:
name - The child entity name.
Returns:
The child entity's location represented with the same entity location type as this entity location.

getLocation

public RelativeLocation getLocation(RelativeLocation loc)
Description copied from interface: EntityLocation
Get the location of this entity location combined with the given relative location, represented by the same entity location type as this entity location. (In other words: when invoked on an absolute entity location, this returns an absolute entity location. When invoked on a relative entity location, this returns a relative location.)

Specified by:
getLocation in interface EntityLocation<RelativeLocation>
Parameters:
loc - The location relative to this entity location.
Returns:
The resulting entity location.

compareTo

public int compareTo(RelativeLocation el)
Specified by:
compareTo in interface Comparable<RelativeLocation>

toString

public String toString()
Overrides:
toString in class AbstractLocation<RelativeLocation>