public abstract static class Children.Keys<T> extends Children.Array
method
that should for each
key create an array of nodes that represents the key.
This class is preferable to Children.Array
because
Typical usage:
Children.Keys.createNodes(T)
to create some nodes
(usually exactly one) per key.
Children.addNotify()
to compute a set of keys
and set it using Children.Keys.setKeys(Collection)
.
The collection may be ordered.
Children.removeNotify()
to just call
setKeys
on Collections.EMPTY_SET
.
setKeys
with the new set of keys. Children.Keys
will
be smart and calculate exactly what it needs to do effficiently.
Children.Keys.refreshKey(T)
. Usually this is not necessary.
Related documentation
Children.Array, Children.Keys<T>, Children.Map<T>, Children.SortedArray, Children.SortedMap<T>
nodes
Modifier | Constructor and Description |
---|---|
|
Keys() |
protected |
Keys(boolean lazy)
Constructor for optional "lazy behavoir" (tries to avoid
computation of nodes if possible).
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(Node[] arr)
Deprecated.
Do not use! Just call
Children.Keys.setKeys(Collection) with a larger set. |
Object |
clone()
Special handling for clonning.
|
protected abstract Node[] |
createNodes(T key)
Create nodes for a given key.
|
protected void |
destroyNodes(Node[] arr)
Called when the nodes have been removed from the children.
|
protected void |
refreshKey(T key)
Refresh the child nodes for a given key.
|
boolean |
remove(Node[] arr)
Deprecated.
Do not use! Just call
Children.Keys.setKeys(Collection) with a smaller set. |
protected void |
setBefore(boolean b)
Set whether new nodes should be added to the beginning or end of sublists for a given key.
|
protected void |
setKeys(Collection<? extends T> keysSet)
Set new keys for this children object.
|
protected void |
setKeys(T[] keys)
Set keys for this list.
|
initCollection, refresh
addNotify, create, createLazy, findChild, getNode, getNodeAt, getNodes, getNodes, getNodesCount, getNodesCount, isInitialized, nodes, removeNotify, snapshot
public Keys()
protected Keys(boolean lazy)
There are certain requirements for usage of lazy mode:
It is forbidden to create more than 1 node in Children.Keys.createNodes(T)
for key. In optimal case there should be 1:1 pairing between key and Node,
but it is also possible to have 1:0 pairing - create no node (return null).
In such case after detection that there is no Node for key,
the key is automatically removed and change (removal of
"dummy" Node) is fired.
lazy
- whether to introduce lazy behaviorpublic Object clone()
clone
in class Children.Array
@Deprecated public boolean add(Node[] arr)
Children.Keys.setKeys(Collection)
with a larger set.Children
Children.Keys.setKeys(java.util.Collection<? extends T>)
instead.
The parent node of these nodes
is changed to the parent node of this list. Each node can be added
only once. If there is some reason a node cannot be added, for example
if the node expects only a special type of subnodes, the method should
do nothing and return false
to signal that the addition has not been successful.
This method should be implemented by subclasses to filter some nodes, etc.
add
in class Children.Array
arr
- set of nodes to add to the listtrue
if successfully added@Deprecated public boolean remove(Node[] arr)
Children.Keys.setKeys(Collection)
with a smaller set.Children
remove
in class Children.Array
arr
- nodes to be removedtrue
if the nodes could be removedprotected final void refreshKey(T key)
key
- the key to refreshprotected final void setKeys(Collection<? extends T> keysSet)
keysSet
- the keys for the nodes (collection of any objects)protected final void setKeys(T[] keys)
keys
- the keys for the nodesChildren.Keys.setKeys(Collection)
protected final void setBefore(boolean b)
b
- true
if the children should be added beforeprotected abstract Node[] createNodes(T key)
key
- the keyprotected void destroyNodes(Node[] arr)
Current implementation notifies all listeners on the nodes that nodes have been deleted.
arr
- array of deleted nodes