@Immutable public class Fqn<E> extends Object implements Comparable<Fqn<?>>, Externalizable
Node
or sometimes a Region
in a Cache
.
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 | Field and Description |
---|---|
protected Object[] |
elements |
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 | Constructor and Description |
---|---|
|
Fqn()
Public to satisfy Externalization.
|
|
Fqn(E... names)
Deprecated.
use
fromElements(Object[]) instead. This constructor will be removed in 3.0.0. |
|
Fqn(Fqn<? extends E> base,
E... childNames)
Deprecated.
use
fromRelativeElements(Fqn, Object[]) instead. This constructor will be removed in 3.0.0. |
|
Fqn(Fqn<? extends E> base,
Fqn<? extends E> relative)
Deprecated.
use
fromRelativeFqn(Fqn, Fqn) instead. This constructor will be removed in 3.0.0. |
|
Fqn(List<? extends E> names)
Deprecated.
use
fromList(java.util.List) instead. This constructor will be removed in 3.0.0. |
protected |
Fqn(Object[] names,
boolean safe)
Deprecated.
use
fromList(java.util.List) instead. The boolean "safety" hint is calculated internally.
This constructor will be removed in 3.0.0. |
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 using
FqnComparator . |
boolean |
equals(Object obj)
Returns true if obj is a Fqn with the same elements.
|
static <T> Fqn<T> |
fromElements(T... elements)
Retrieves an Fqn that represents the array of elements passed in.
|
static Fqn<?> |
fromExternalStream(ObjectInput in)
Retrieves an Fqn read from an object input stream, typically written to using
writeExternal(java.io.ObjectOutput) . |
static <T> Fqn<T> |
fromList(List<? extends T> names)
Retrieves an Fqn that represents the list of elements passed in.
|
static <T> Fqn<T> |
fromList(List<? extends T> names,
boolean safe)
Retrieves an Fqn that represents the list of elements passed in.
|
static <T> Fqn<T> |
fromRelativeElements(Fqn<? extends T> base,
T... relativeElements)
Retrieves an Fqn that represents the array of elements passed in, relative to the base Fqn.
|
static <T> Fqn<T> |
fromRelativeFqn(Fqn<? extends T> base,
Fqn<? extends T> relative)
Retrieves an Fqn that represents the absolute Fqn of the relative Fqn passed in.
|
static <T> Fqn<T> |
fromRelativeList(Fqn<? extends T> base,
List<? extends T> relativeElements)
Retrieves an Fqn that represents the List
|
static Fqn<String> |
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<E> |
getAncestor(int generation)
Obtains an ancestor of the current Fqn.
|
Object |
getLastElement() |
String |
getLastElementAsString()
If this is the root, returns
SEPARATOR . |
Fqn<E> |
getParent()
Returns the parent of this Fqn.
|
protected String |
getStringRepresentation(List<E> elements) |
protected String |
getStringRepresentation(Object[] elements) |
Fqn<E> |
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<? super E> parentFqn)
Returns true if this Fqn is child of parentFqn.
|
boolean |
isChildOrEquals(Fqn<? super E> parentFqn)
Returns true if this Fqn is equals or the child of parentFqn.
|
boolean |
isDirectChildOf(Fqn<? super E> 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<E> |
peekElements()
Peeks into the elements that build up this Fqn.
|
void |
readExternal(ObjectInput in) |
Fqn<E> |
replaceAncestor(Fqn<E> oldAncestor,
Fqn<E> newAncestor)
Creates a new Fqn whose ancestor has been replaced with the new ancestor passed in.
|
static <T> Fqn<T> |
root() |
int |
size() |
String |
toString()
|
void |
writeExternal(ObjectOutput out) |
public static final String SEPARATOR
protected Object[] elements
public static final Fqn ROOT
protected String stringRepresentation
public Fqn()
@Deprecated public Fqn(List<? extends E> names)
fromList(java.util.List)
instead. This constructor will be removed in 3.0.0.names
- List of names@Deprecated public Fqn(E... names)
fromElements(Object[])
instead. This constructor will be removed in 3.0.0.names
- Names that comprose this Fqn@Deprecated public Fqn(Fqn<? extends E> base, Fqn<? extends E> relative)
fromRelativeFqn(Fqn, Fqn)
instead. This constructor will be removed in 3.0.0.base
- parent Fqnrelative
- Sub-Fqn relative to the parent@Deprecated public Fqn(Fqn<? extends E> base, E... childNames)
fromRelativeElements(Fqn, Object[])
instead. This constructor will be removed in 3.0.0.base
- parent FqnchildNames
- elements that denote the path to the Fqn, under the parent@Deprecated protected Fqn(Object[] names, boolean safe)
fromList(java.util.List)
instead. The boolean "safety" hint is calculated internally.
This constructor will be removed in 3.0.0.names
- List of namessafe
- whether this list is referenced externally (safe = false) or not (safe = true).public static <T> Fqn<T> fromList(List<? extends T> names)
names
- list of elements that comprise the Fqnpublic static <T> Fqn<T> fromList(List<? extends T> names, boolean safe)
names
- list of elements that comprise the Fqnsafe
- if true, the list passed in is not defensively copied but used directly. Use with care. Make
sure you know what you are doing before you pass in a true value to safe, as it can
have adverse effects on performance or correctness. The defensive copy of list elements is not just
for safety but also for performance as an appropriare List implementation is used, which works well
with Fqn operations.public static <T> Fqn<T> fromElements(T... elements)
elements
- array of elements that comprise the Fqnpublic static <T> Fqn<T> fromRelativeFqn(Fqn<? extends T> base, Fqn<? extends T> relative)
base
- base Fqnrelative
- relative Fqnpublic static <T> Fqn<T> fromRelativeList(Fqn<? extends T> base, List<? extends T> relativeElements)
base
- base FqnrelativeElements
- relative Listpublic static <T> Fqn<T> fromRelativeElements(Fqn<? extends T> base, T... relativeElements)
base
- base FqnrelativeElements
- relative elementspublic static Fqn<String> fromString(String stringRepresentation)
SEPARATOR
)
characters.Fqn.fromString("/a/b/c/");
Fqn.fromElements("a", "b", "c");
stringRepresentation
- String representation of the Fqnpublic static Fqn<?> fromExternalStream(ObjectInput in) throws IOException, ClassNotFoundException
writeExternal(java.io.ObjectOutput)
.in
- input streamIOException
- in the event of a problem reading the streamClassNotFoundException
- in the event of classes that comprise the element list of this Fqn not being foundpublic Fqn<E> 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<E> 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 void writeExternal(ObjectOutput out) throws IOException
writeExternal
in interface Externalizable
IOException
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
readExternal
in interface Externalizable
IOException
ClassNotFoundException
public boolean isChildOf(Fqn<? super E> 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<? super E> parentFqn)
parentFqn
- parentFqn to compare withpublic boolean isChildOrEquals(Fqn<? super E> 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<E> 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 final <T> Fqn<T> root()
public boolean isRoot()
public String getLastElementAsString()
SEPARATOR
.public List<E> peekElements()
public int compareTo(Fqn<?> fqn)
FqnComparator
.compareTo
in interface Comparable<Fqn<?>>
public Fqn<E> replaceAncestor(Fqn<E> oldAncestor, Fqn<E> newAncestor)
oldAncestor
- old ancestor to replacenewAncestor
- nw ancestor to replace withCopyright © 2012 JBoss, a division of Red Hat. All Rights Reserved.