@Immutable public class Fqn extends Object implements Comparable<Fqn>, 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 Fqn
s 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 String |
SEPARATOR
Separator between FQN elements.
|
protected 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(Object obj)
Returns true if obj is a Fqn with the same elements.
|
static Fqn |
fromElements(Object... elements)
Retrieves an Fqn that represents the array of elements passed in.
|
static Fqn |
fromList(List<?> names)
Retrieves an Fqn that represents the list of elements passed in.
|
static Fqn |
fromRelativeElements(Fqn base,
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,
List<?> relativeElements)
Retrieves an Fqn that represents the List
|
static Fqn |
fromString(String stringRepresentation)
Returns a new Fqn from a string, where the elements are deliminated by one or more separator (
SEPARATOR )
characters.Example use: |
Object |
get(int n) |
Fqn |
getAncestor(int generation)
Obtains an ancestor of the current Fqn.
|
Object |
getLastElement() |
String |
getLastElementAsString()
If this is the root, returns
SEPARATOR . |
Fqn |
getParent()
Returns the parent of this Fqn.
|
protected String |
getStringRepresentation(Object[] elements) |
Fqn |
getSubFqn(int startIndex,
int endIndex)
Obtains a sub-Fqn from the given Fqn.
|
boolean |
hasElement(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.
|
List<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() |
String |
toString()
|
public static final String SEPARATOR
public static final Fqn ROOT
protected String stringRepresentation
public static Fqn fromList(List<?> names)
names
- list of elements that comprise the Fqnpublic static Fqn fromElements(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, List<?> relativeElements)
base
- base FqnrelativeElements
- relative Listpublic static Fqn fromRelativeElements(Fqn base, Object... relativeElements)
base
- base FqnrelativeElements
- relative elementspublic static Fqn fromString(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 Object get(int n)
n
- index of the element to returnpublic Object getLastElement()
getLastElementAsString()
public boolean hasElement(Object element)
element
- element to findpublic boolean equals(Object obj)
public int hashCode()
public String toString()
public 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()
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 String getLastElementAsString()
SEPARATOR
.public List<Object> peekElements()
public int compareTo(Fqn fqn)
compareTo
in interface Comparable<Fqn>
Copyright © 2018 JBoss, a division of Red Hat. All rights reserved.