@Immutable public class Fqn extends java.lang.Object implements java.lang.Comparable<Fqn>, java.io.Serializable
Node in a TreeCache.
This name can be absolute (i.e., relative from the root node - ROOT), or relative to any node in the cache.
Reading the documentation on each API call that makes use of Fqns will tell you whether the API expects a
relative or absolute Fqn.
For instance, using this class to fetch a particular node might look like this. (Here data on "Joe" is kept under
the "Smith" surname node, under the "people" tree.)
FqnAlternatively, the same Fqn could be constructed using a Listabc = Fqn.fromString("/people/Smith/Joe/"); Node joesmith = Cache.getRoot().getChild(abc);
| Modifier and Type | Class and Description |
|---|---|
static class |
Fqn.Externalizer |
| Modifier and Type | Field and Description |
|---|---|
static Fqn |
ROOT
Immutable root Fqn.
|
static java.lang.String |
SEPARATOR
Separator between FQN elements.
|
protected java.lang.String |
stringRepresentation
A cached string representation of this Fqn, used by toString to it isn't calculated again every time.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
calculateHashCode()
Calculates a hash code by summing the hash code of all elements.
|
int |
compareTo(Fqn fqn)
Compares this Fqn to another
|
boolean |
equals(java.lang.Object obj)
Returns true if obj is a Fqn with the same elements.
|
static Fqn |
fromElements(java.lang.Object... elements)
Retrieves an Fqn that represents the array of elements passed in.
|
static Fqn |
fromList(java.util.List<?> names)
Retrieves an Fqn that represents the list of elements passed in.
|
static Fqn |
fromRelativeElements(Fqn base,
java.lang.Object... relativeElements)
Retrieves an Fqn that represents the array of elements passed in, relative to the base Fqn.
|
static Fqn |
fromRelativeFqn(Fqn base,
Fqn relative)
Retrieves an Fqn that represents the absolute Fqn of the relative Fqn passed in.
|
static Fqn |
fromRelativeList(Fqn base,
java.util.List<?> relativeElements)
Retrieves an Fqn that represents the List
|
static Fqn |
fromString(java.lang.String stringRepresentation)
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 n) |
Fqn |
getAncestor(int generation)
Obtains an ancestor of the current Fqn.
|
java.lang.Object |
getLastElement() |
java.lang.String |
getLastElementAsString()
If this is the root, returns
SEPARATOR. |
Fqn |
getParent()
Returns the parent of this Fqn.
|
protected java.lang.String |
getStringRepresentation(java.lang.Object[] elements) |
Fqn |
getSubFqn(int startIndex,
int endIndex)
Obtains a sub-Fqn from the given Fqn.
|
boolean |
hasElement(java.lang.Object 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 |
isDirectChildOf(Fqn parentFqn)
Returns true if this Fqn is a direct child of a given Fqn.
|
boolean |
isRoot()
Returns true if this is a root Fqn.
|
java.util.List<java.lang.Object> |
peekElements()
Peeks into the elements that build up this Fqn.
|
Fqn |
replaceAncestor(Fqn oldAncestor,
Fqn newAncestor)
Creates a new Fqn whose ancestor has been replaced with the new ancestor passed in.
|
static Fqn |
root() |
int |
size() |
java.lang.String |
toString()
|
public static final java.lang.String SEPARATOR
public static final Fqn ROOT
protected java.lang.String stringRepresentation
public static Fqn fromList(java.util.List<?> names)
names - list of elements that comprise the Fqnpublic static Fqn fromElements(java.lang.Object... elements)
elements - array of elements that comprise the Fqnpublic static Fqn fromRelativeFqn(Fqn base, Fqn relative)
base - base Fqnrelative - relative Fqnpublic static Fqn fromRelativeList(Fqn base, java.util.List<?> relativeElements)
base - base FqnrelativeElements - relative Listpublic static Fqn fromRelativeElements(Fqn base, java.lang.Object... relativeElements)
base - base FqnrelativeElements - relative elementspublic static Fqn fromString(java.lang.String stringRepresentation)
SEPARATOR)
characters.
Fqn.fromString("/a/b/c/");
Fqn.fromElements("a", "b", "c");
stringRepresentation - String representation of the Fqnpublic Fqn getAncestor(int generation)
elements.subList(0, generation) such that
if generation == Fqn.size() then the return value is the Fqn itself (current generation), and if
generation == Fqn.size() - 1 then the return value is the same as Fqn.getParent()
i.e., just one generation behind the current generation. generation == 0 would return Fqn.ROOT.generation - the generation of the ancestor to retrievepublic Fqn getSubFqn(int startIndex, int endIndex)
elements.subList(startIndex, endIndex)startIndex - starting indexendIndex - end indexpublic int size()
public java.lang.Object get(int n)
n - index of the element to returnpublic java.lang.Object getLastElement()
getLastElementAsString()public boolean hasElement(java.lang.Object element)
element - element to findpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
SEPARATOR and joining each subsequent
element with a SEPARATOR. If this is the root Fqn, returns SEPARATOR. Example:
new Fqn(new Object[] { "a", "b", "c" }).toString(); // "/a/b/c"
Fqn.ROOT.toString(); // "/"
toString in class java.lang.Objectpublic boolean isChildOf(Fqn parentFqn)
Fqnf1 = Fqn.fromString("/a/b"); Fqn f2 = Fqn.fromString("/a/b/c"); assertTrue(f1.isChildOf(f2)); assertFalse(f1.isChildOf(f1)); assertFalse(f2.isChildOf(f1));
parentFqn - candidate parent to test againstpublic boolean isDirectChildOf(Fqn parentFqn)
parentFqn - parentFqn to compare withpublic boolean isChildOrEquals(Fqn parentFqn)
Fqnf1 = Fqn.fromString("/a/b"); Fqn f2 = Fqn.fromString("/a/b/c"); assertTrue(f1.isChildOrEquals(f2)); assertTrue(f1.isChildOrEquals(f1)); assertFalse(f2.isChildOrEquals(f1));
parentFqn - candidate parent to test againstprotected int calculateHashCode()
protected java.lang.String getStringRepresentation(java.lang.Object[] elements)
public Fqn getParent()
ROOT. Examples:
Fqnf1 = Fqn.fromString("/a"); Fqn f2 = Fqn.fromString("/a/b"); assertEquals(f1, f2.getParent()); assertEquals(Fqn.ROOT, f1.getParent().getParent()); assertEquals(Fqn.ROOT, Fqn.ROOT.getParent());
public static Fqn root()
public boolean isRoot()
public java.lang.String getLastElementAsString()
SEPARATOR.public java.util.List<java.lang.Object> peekElements()
public int compareTo(Fqn fqn)
compareTo in interface java.lang.Comparable<Fqn>