org.entityfs.el
Class AbsoluteLocation

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

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

Objects of this class describe absolute entity locations in a file system, i.e. an entity location that defines an entity's absolute position in the file system hierarchy. (An absolute path.)

A word of warning: Be careful with using absolute entity locations in locking file systems that are concurrently accessed by several threads. Creating an absolute entity location requires read locking all parent entities up to the file system root. Use relative entity locations as much as possible instead.

Instances of this class are immutable.

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

Field Summary
static AbsoluteLocation ROOT_DIR
          A constant representing the root directory (/).
 
Fields inherited from interface org.entityfs.el.EntityLocation
CURRENT_DIRECTORY_STRING, EXTENSION_SEPARATOR, PARENT_DIRECTORY_STRING, SEPARATOR, SEPARATOR_CHAR
 
Constructor Summary
AbsoluteLocation(String apath)
          Create a new AbsoluteLocation instance.
 
Method Summary
 int compareTo(AbsoluteLocation el)
           
 AbsoluteLocation 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.
 AbsoluteLocation 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.
 AbsoluteLocation getParentLocation()
          Get the parent location of this entity location.
 RelativeLocation getRelativeTo(AbsoluteLocation el)
           
 boolean isInPathOf(AbsoluteLocation el)
           
 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

ROOT_DIR

public static final AbsoluteLocation ROOT_DIR
A constant representing the root directory (/).

Constructor Detail

AbsoluteLocation

public AbsoluteLocation(String apath)
                 throws IllegalArgumentException,
                        InvalidEntityLocationException
Create a new AbsoluteLocation instance.

Parameters:
apath - The string representation of an absolute path in the file system. The path is normalized by this method.
Throws:
IllegalArgumentException - If apath is not a valid absolute path.
InvalidEntityLocationException - If the path is not within the file system (For instance, /..)
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<AbsoluteLocation>
Returns:
The string representation of the entity location.

isInPathOf

public boolean isInPathOf(AbsoluteLocation el)

getParentLocation

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

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

getRelativeTo

public RelativeLocation getRelativeTo(AbsoluteLocation el)

getChildLocation

public AbsoluteLocation 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<AbsoluteLocation>
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 AbsoluteLocation 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<AbsoluteLocation>
Parameters:
loc - The location relative to this entity location.
Returns:
The resulting entity location.

compareTo

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

toString

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