org.jboss.cache
Class Fqn

java.lang.Object
  extended by org.jboss.cache.Fqn
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable, java.lang.Cloneable

public class Fqn
extends java.lang.Object
implements java.lang.Cloneable, java.io.Externalizable

Fully qualified name. A list of relatives names, which can be any Object, from root to a given node. This class is immutable.

Note that

Fqn f = new Fqn("/a/b/c");

is not the same as

Fqn f = Fqn.fromString("/a/b/c");

The former will result in a single Fqn, called "/a/b/c" which hangs directly under Fqn.ROOT.

The latter will result in 3 Fqns, called "a", "b" and "c", where "c" is a child of "b", "b" is a child of "a", and "a" hangs off Fqn.ROOT.

Another way to look at it is that the "/" separarator is only parsed when it form sa part of a String passed in to Fqn.fromString() and not otherwise.

Version:
$Revision: 1.31.2.3 $
See Also:
Serialized Form

Field Summary
static Fqn ROOT
          Immutable root FQN.
static java.lang.String SEPARATOR
          Separator between FQN elements.
 
Constructor Summary
Fqn()
          Constructs a root FQN.
Fqn(Fqn base, Fqn relative)
          Constructs a FQN from a base and relative FQN.
Fqn(Fqn base, java.util.List relative)
          Constructs a FQN from a base and a list of relative names.
Fqn(Fqn base, java.lang.Object relative_name)
          Constructs a FQN from a base and relative name.
Fqn(Fqn base, java.lang.Object relative_name1, java.lang.Object relative_name2)
          Constructs a FQN from a base and two relative names.
Fqn(Fqn base, java.lang.Object relative_name1, java.lang.Object relative_name2, java.lang.Object relative_name3)
          Constructs a FQN from a base and three relative names.
Fqn(java.util.List names)
          Constructs a FQN from a list of names.
Fqn(java.lang.Object name)
          Constructs a single element Fqn.
Fqn(java.lang.Object[] names)
          Constructs a FQN from an array of names.
 
Method Summary
 java.lang.Object clone()
          Clones the FQN.
 boolean equals(java.lang.Object obj)
          Returns true if obj is a FQN with the same elements.
static Fqn fromString(java.lang.String fqn)
          Returns a new FQN from a string, where the elements are deliminated by one or more separator (SEPARATOR) characters.

Example use:
 java.lang.Object get(int index)
          Returns the Nth element in the FQN.
 Fqn getFqnChild(int index)
          Obtains a child Fqn from a sub-index.
 Fqn getFqnChild(int startIndex, int endIndex)
          Obtains a child Fqn from a sub-index.
 java.lang.Object getLast()
          Returns the last element in the FQN.
 java.lang.String getName()
          Returns a String representation of the last element that makes up this Fqn.
 Fqn getParent()
          Returns the parent of this FQN.
 boolean hasElement(java.lang.Object o)
          Returns true if the FQN contains this element.
 int hashCode()
          Returns a hash code with FQN elements.
 boolean isChildOf(Fqn parentFqn)
          Returns true if this fqn is child of parentFqn
 boolean isChildOrEquals(Fqn parentFqn)
          Returns true if this fqn is equals or the child of parentFqn.
 boolean isRoot()
          Returns true if this is a root FQN.
 java.util.List peekElements()
          Peeks into the elements that build up this Fqn.
 void readExternal(java.io.ObjectInput in)
           
 int size()
          Returns the number of elements in the FQN.
 java.lang.String toString()
          Returns this FQN as a string, prefixing the first element with a / and joining each subsequent element with a /.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

SEPARATOR

public static final java.lang.String SEPARATOR
Separator between FQN elements.

See Also:
Constant Field Values

ROOT

public static final Fqn ROOT
Immutable root FQN.

Constructor Detail

Fqn

public Fqn()
Constructs a root FQN.


Fqn

public Fqn(java.lang.Object name)
Constructs a single element Fqn. Note that if a String is passed in, separator characters SEPARATOR are not parsed. If you wish these to be parsed, use fromString(String).

See Also:
fromString(String)

Fqn

public Fqn(java.util.List names)
Constructs a FQN from a list of names.


Fqn

public Fqn(java.lang.Object[] names)
Constructs a FQN from an array of names.


Fqn

public Fqn(Fqn base,
           java.lang.Object relative_name)
Constructs a FQN from a base and relative name.


Fqn

public Fqn(Fqn base,
           Fqn relative)
Constructs a FQN from a base and relative FQN.


Fqn

public Fqn(Fqn base,
           java.util.List relative)
Constructs a FQN from a base and a list of relative names.


Fqn

public Fqn(Fqn base,
           java.lang.Object relative_name1,
           java.lang.Object relative_name2)
Constructs a FQN from a base and two relative names.


Fqn

public Fqn(Fqn base,
           java.lang.Object relative_name1,
           java.lang.Object relative_name2,
           java.lang.Object relative_name3)
Constructs a FQN from a base and three relative names.

Method Detail

fromString

public static Fqn fromString(java.lang.String fqn)
Returns a new FQN from a string, where the elements are deliminated by one or more separator (SEPARATOR) characters.

Example use:
 Fqn.fromString("/a//b/c/");
 

is equivalent to:
 new Fqn(new Object[] { "a", "b", "c" });
 

but not
 new Fqn("/a/b/c");
 

See Also:
Fqn(Object[]), Fqn(Object)

getFqnChild

public Fqn getFqnChild(int index)
Obtains a child Fqn from a sub-index.

Parameters:
index - where is the last index of child fqn
Returns:
A Fqn child object.

getFqnChild

public Fqn getFqnChild(int startIndex,
                       int endIndex)
Obtains a child Fqn from a sub-index.


size

public int size()
Returns the number of elements in the FQN. The root node contains zero.


get

public java.lang.Object get(int index)
Returns the Nth element in the FQN.


getLast

public java.lang.Object getLast()
Returns the last element in the FQN.

See Also:
getName()

hasElement

public boolean hasElement(java.lang.Object o)
Returns true if the FQN contains this element.


clone

public java.lang.Object clone()
Clones the FQN.

Overrides:
clone in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Returns true if obj is a FQN with the same elements.

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code with FQN elements.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns this FQN as a string, prefixing the first element with a / and joining each subsequent element with a /. If this is the root FQN, returns SEPARATOR. Example:
    new Fqn(new Object[] { "a", "b", "c" }).toString(); // "/a/b/c"
    Fqn.ROOT.toString(); // "/"
    

Overrides:
toString in class java.lang.Object

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Specified by:
readExternal in interface java.io.Externalizable
Throws:
java.io.IOException
java.lang.ClassNotFoundException

isChildOf

public boolean isChildOf(Fqn parentFqn)
Returns true if this fqn is child of parentFqn

Parameters:
parentFqn -
Returns:
true if the target is a child of parentFqn

isChildOrEquals

public boolean isChildOrEquals(Fqn parentFqn)
Returns true if this fqn is equals or the child of parentFqn.


getParent

public Fqn getParent()
Returns the parent of this FQN.


isRoot

public boolean isRoot()
Returns true if this is a root FQN.


getName

public java.lang.String getName()
Returns a String representation of the last element that makes up this Fqn. If this is the root, returns SEPARATOR.


peekElements

public java.util.List peekElements()
Peeks into the elements that build up this Fqn. The list returned is read-only, to maintain the immutable nature of Fqn.

Returns:
an unmodifiable list


Copyright © 1998-2005 JBoss Inc . All Rights Reserved.