tp
Class LockableID

java.lang.Object
  extended by tp.LockableID
All Implemented Interfaces:
Comparable<LockableID>, Lockable

public class LockableID
extends Object
implements Comparable<LockableID>, Lockable

A generic ID that encapsulate a string. You can compose two identifiers to create a hierarchy. The internal representation is just a string. The hierarchy is represented as a standard path (i.e., '/' delimited string except the last component of the path).

For example, you can use this class to represent a reservation record by constructing a hierarchy of Customer and RID as follow.

 Customer customer;
 RID resource;
 LockableID id = new LockableID(customer,resource);
 

Please feel free to modify this class.


Constructor Summary
LockableID(Lockable item)
           
LockableID(Lockable prefix, Lockable item)
           
LockableID(Lockable prefix, String item)
           
LockableID(String id)
           
LockableID(String prefix, Lockable item)
           
 
Method Summary
 int compareTo(LockableID o)
           
 LockableID concat(Lockable other)
          Construct a composite ID using this id as prefix.
 boolean equals(Object o)
           
 String getName()
          Get the last component of this id.
 LockableID getPrefix()
          Get the prefix of this id.
 int hashCode()
           
 boolean isPrefixOf(LockableID other)
          check whether this object is prefix of the other.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LockableID

public LockableID(String id)

LockableID

public LockableID(Lockable item)

LockableID

public LockableID(String prefix,
                  Lockable item)

LockableID

public LockableID(Lockable prefix,
                  Lockable item)

LockableID

public LockableID(Lockable prefix,
                  String item)
Method Detail

concat

public LockableID concat(Lockable other)
Construct a composite ID using this id as prefix.

Parameters:
other - id to compose
Returns:
a composite ID of this '/' other

isPrefixOf

public boolean isPrefixOf(LockableID other)
check whether this object is prefix of the other.

Parameters:
other - tested id
Returns:
true if this object is prefix of the other.

getPrefix

public LockableID getPrefix()
Get the prefix of this id.

Returns:
the prefix of this id. null if this id is a root.

getName

public String getName()
Get the last component of this id.

Returns:
the last component of the path represented by this id.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

compareTo

public int compareTo(LockableID o)
Specified by:
compareTo in interface Comparable<LockableID>