public class NavuList extends NavuNode implements Iterable<NavuListEntry>
NavuList
is a representation of the YANG list node.
A NavuList
holds a map of list entries,
NavuListEntry
, each associated with a key, ConfKey
, thus
each child is indexed by its key and the individual entry is retrieved
by the NavuList.elem(ConfKey)
method.
The elem
method declares that it returns
a NavuContainer
but its underlying subtype is actually a
NavuListEntry
.
NavuList
also supports keyless lists (lists without keys).
If the YANG list is keyless, an individual child is retrieved
through its "pseudo-key" which must always be of the type ConfInt64
.
NavuList keyLessList = ...; ConfKey pseudo = new ConfKey(new ConfInt64(10)); NavuContainer entry10 = keyLessList.elem(pseudo); assert(entry10.isListInstance()); assert(entry10.getInfo().isListEntry()); NavuListEntry navuListEntry10 = (NavuListEntry) entry10;
When accessing individual elements through elem
,
NavuList
will only make one single exists
call (over MAAPI or CDB depending on the context) to check the
existence of the key, thus making the operation cheap.
The set of children, or the list elements, are retrieved through
NavuList.children()
, NavuList.elements()
or by retrieving
an iterator NavuList.iterator()
.
NavuList serverList = ...; for (NavuNode childEntry : serverList.children()) { // Do something with each child instance }
NavuList
also implements the Iterable
interface
which means that the child elements can be retrieved implicitly.
NavuList serverList = ...; for (NavuNode childEntry : serverList) { // Do something with each child instance }
NavuList
loads its children on demand but
when invoking the methods children
,
elements
, encodeXML
, entrySet
,
isEmpty
, keySet
, select
it must trigger a load of all its keys from the
datastore. Use these methods with caution when the list is big.
Consider using the iterator
instead wherever possible.
Modifier and Type | Class and Description |
---|---|
static class |
NavuList.WhereTo |
Modifier and Type | Method and Description |
---|---|
Collection<NavuNode> |
children()
Returns all elements contained by the list node.
|
boolean |
containsNode(ConfKey key)
Returns true if and only if this
NavuList
contains a NavuListEntry where
NavuListEntry.getKey() equals the specified
key. |
boolean |
containsNode(NavuContainer node)
Returns true if this NavuList maps a
ConfKey to the specified NavuContainer.
|
boolean |
containsNode(String keyStr)
Returns true if this NavuList contains a mapping
for the specified string representation of a key.
|
boolean |
containsNode(String[] keyArr)
Returns true if this NavuList contains a mapping
for the specified string representation of a key.
|
NavuContainer |
create(ConfKey key)
Create and return a new list element in this
NavuList . |
NavuContainer |
create(ConfObject key)
Convenience variant of
NavuList.create(ConfKey) accepting a
ConfObject as the (single element) key. |
NavuContainer |
create(String keyStr)
Convenience variant of
NavuList.create(ConfKey) accepting a
string as the (single element) key. |
NavuContainer |
create(String[] keyArr)
Convenience variant of
NavuList.create(ConfKey) accepting a
string array as the key. |
void |
delete(ConfKey key)
Deletes an element from the list.
|
void |
delete(String keyStr)
Deletes an element from the list.
|
void |
delete(String[] keyArr)
Deletes an element from the list.
|
void |
deleteAll()
Deletes all element from the list.
|
NavuListEntry |
elem(ConfKey key)
Returns a list element according to the given key.
|
NavuContainer |
elem(String keyStr)
Returns a list element according to the given key.
|
NavuContainer |
elem(String[] keyArr)
Returns a list element according to the given array of keys.
|
Collection<NavuContainer> |
elements()
Returns a shallow copy of all elements contained by the list node.
|
List<ConfXMLParam> |
encodeValues()
Encodes the sub-tree including the current
NavuNode
as the topmost NavuNode as a ConfXMLParam array. |
List<ConfXMLParam> |
encodeXML()
Encodes the sub-tree including the current
NavuNode
as the topmost NavuNode as a ConfXMLParam array. |
Set<Map.Entry<ConfKey,NavuListEntry>> |
entrySet()
Returns a set of entries with element key and element.
|
boolean |
equals(Object o)
Compares the specified object with this
NavuList
for equality. |
boolean |
exists()
Tests for the existence of the List node in the instance tree.
|
DiffIterateOperFlag |
getChangeFlag()
Returns the latest change that this
NavuNode has
been a subject to by a transaction. |
NavuNode |
getParent()
Returns the parent of the node.
|
NavuContainer |
insert(ConfKey key,
boolean createBackpointer)
Inserts an element into a list using Maapi.insert().
|
boolean |
isEmpty()
Checks if there are any elements in the list.
|
boolean |
isNodeNavuLocal() |
Iterator<NavuListEntry> |
iterator()
Retrieve a iterator over the elements in this
NavuList
(in proper sequence). |
Set<ConfKey> |
keySet()
Returns a Set containing all of the keys for this list.
|
void |
move(ConfKey key,
NavuList.WhereTo whereTo,
ConfKey to)
Move a list element to a new position in the list.
|
void |
move(String keyStr,
NavuList.WhereTo whereTo,
String toStr)
Move a list element to a new position in the list.
|
void |
reset()
When navigating through NAVU to a certain list, the list values are
cached as they are read.
|
NavuContainer |
safeCreate(ConfKey key)
Variant of
NavuList.create(ConfKey) that succeeds even if the
key already exists. |
NavuContainer |
safeCreate(ConfObject key)
Variant of
NavuList.create(ConfObject) that succeeds even if
the key already exists. |
NavuContainer |
safeCreate(String keyStr)
Variant of
NavuList.create(String) that succeeds even if the
key already exists. |
NavuContainer |
safeCreate(String[] keyArr)
Variant of
NavuList.create(String[]) that succeeds even if the
key already exists. |
Collection<NavuNode> |
select(ConfObject[] kp) |
Collection<NavuNode> |
select(List<String> path) |
Collection<NavuNode> |
select(String path) |
void |
set(String xml)
Deprecated.
|
NavuNode |
setChange(List<ConfObject> path,
DiffIterateOperFlag op,
ConfValue oldValue,
NavuContext delContext) |
void |
setMaxListSize(int maxSize)
Sets the maxSize of the internal HashMap of list elements.
|
NavuContainer |
sharedCreate(ConfKey key)
Variant of
NavuList.create(ConfKey) that succeeds even if the
key already exists, and also maintains a reference counter
on the object. |
NavuContainer |
sharedCreate(ConfObject key)
Variant of
NavuList.create(ConfObject) that succeeds even if the
key already exists, and also maintains a reference counter
on the object. |
NavuContainer |
sharedCreate(String keyStr)
Variant of
NavuList.create(String) that succeeds even if the
key already exists, and also maintains a reference counter
on the object. |
NavuContainer |
sharedCreate(String[] keyArr)
Variant of
NavuList.create(String[]) that succeeds even if the
key already exists, and also maintains a reference counter
on the object. |
int |
size()
Returns the number of list elements contained by the list node.
|
String |
toString() |
void |
valueUpdateInd(NavuNode child) |
container, container, container, container, context, getCdbSession, getChange, getChanges, getChanges, getChanges, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getRootNS, getValues, getValues, getXml, hashCode, leaf, leaf, leaf, leaf, leafList, leafList, leafList, leafList, list, list, list, list, namespace, prepareXMLCall, setValues, setValues, sharedSetValues, sharedSetValues, startCdbSession, stopCdbSession, xPathSelect, xPathSelectIterate
forEach, spliterator
public boolean containsNode(ConfKey key) throws NavuException
NavuList
contains a NavuListEntry
where
NavuListEntry.getKey()
equals
the specified
key.key
- whose presence in this NavuList
is to be
testedNavuException
public boolean containsNode(NavuContainer node)
node
- NavuContainer whose presence in this
NavuList is to be testedpublic boolean containsNode(String keyStr) throws NavuException
keyStr
- a string representation of a key whose presence in this
NavuList is to be testedNavuException
public boolean containsNode(String[] keyArr) throws NavuException
This is a convenience method for lists with multiple element key.
keyArr
- elements of the specified key contains string
representation of a key whose presence in this
NavuList is to be testedNavuException
public NavuContainer create(ConfKey key) throws NavuException
NavuList
.
We have 3 different variants of create
.
create()
This method will fail with a
NavuException
with the error code set to
ErrorCode.ERR_ALREADY_EXISTS
if the key already exists.
safeCreate()
Similar to create()
with the sole difference that is silently succeeds even if the
key already exists.
sharedCreate()
This method is useful when
creating structures from FASTMAP code, i.e., code that implements
the com.tailf.nsmux.NcsResourceFacingService interface.
The sharedCreate()
method maintains a reference counter on
the created object. Furthermore, a backpointer attribute will be
created on the created object indicating which service(s) created the
object.
All of the create()
methods are overloaded with
convenience methods accepting keys of different types.
key
- the key with which the newly created list entry is to be
associatedNavuException
public NavuContainer create(ConfObject key) throws NavuException
NavuList.create(ConfKey)
accepting a
ConfObject
as the (single element) key.key
- the key with which the newly created list entry is to be
associatedNavuException
public NavuContainer create(String keyStr) throws NavuException
Convenience variant of NavuList.create(ConfKey)
accepting a
string as the (single element) key.
If the string is surrounded by curly braces, e.g. "{test}", they will be removed. If this is not desired, another variant of create() should be used.
The YANG type of the list key does not necessarily have to be a string. The key string will be encoded as the proper YANG type according to the schema.
keyStr
- the key with which the newly created list entry is to be
associatedNavuException
public NavuContainer create(String[] keyArr) throws NavuException
NavuList.create(ConfKey)
accepting a
string array as the key. Typically useful for multiple element keys.keyArr
- the string array from which to create the key that the
newly created list entry is to be associated withNavuException
public NavuContainer safeCreate(ConfKey key) throws NavuException
NavuList.create(ConfKey)
that succeeds even if the
key already exists.key
- the key with which the newly created list entry is to be
associatedkey
NavuException
public NavuContainer safeCreate(ConfObject key) throws NavuException
NavuList.create(ConfObject)
that succeeds even if
the key already exists.key
- the key with which the newly created list entry is to be
associatedkey
NavuException
public NavuContainer safeCreate(String keyStr) throws NavuException
NavuList.create(String)
that succeeds even if the
key already exists.keyStr
- the string representation of the key value with which the
newly created list entry is to be associatedkey
NavuException
public NavuContainer safeCreate(String[] keyArr) throws NavuException
NavuList.create(String[])
that succeeds even if the
key already exists.keyArr
- the string array from which to create the key that the
newly created list entry is to be associated withkeyArr
NavuException
public NavuContainer sharedCreate(ConfKey key) throws NavuException
NavuList.create(ConfKey)
that succeeds even if the
key already exists, and also maintains a reference counter
on the object.key
- the key with which the newly created list entry is to be
associatedkey
NavuException
public NavuContainer sharedCreate(ConfObject key) throws NavuException
NavuList.create(ConfObject)
that succeeds even if the
key already exists, and also maintains a reference counter
on the object.key
- the key with which the newly created list entry is to be
associatedkey
NavuException
public NavuContainer sharedCreate(String keyStr) throws NavuException
NavuList.create(String)
that succeeds even if the
key already exists, and also maintains a reference counter
on the object.keyStr
- the string representation of the key value with which
the newly created list entry is to be associatedkey
NavuException
public NavuContainer sharedCreate(String[] keyArr) throws NavuException
NavuList.create(String[])
that succeeds even if the
key already exists, and also maintains a reference counter
on the object.keyArr
- the string array from which to create the key that the
newly created list entry is to be associated withkeyArr
NavuException
public void delete(ConfKey key) throws NavuException
key
- the key of the element to deleteNavuException
public void deleteAll() throws NavuException
NavuException
public void delete(String keyStr) throws NavuException
This is a convenience method for lists with single element key. If the string is enclosed in curly braces like {test}, the curly braces are stripped. If this not desired another overloaded method should be used.
keyStr
- string representation of a single element keyNavuException
public void delete(String[] keyArr) throws NavuException
keyArr
- string array representation of a multiple element keyNavuException
public NavuContainer insert(ConfKey key, boolean createBackpointer) throws NavuException
NavuException
public NavuListEntry elem(ConfKey key) throws NavuException
key
- a key identifying the list elementNavuException
public NavuContainer elem(String keyStr) throws NavuException
This is a convenience method for lists with single element key. If the string is enclosed in curly braces like {test}, the curly braces are stripped. If this not desired another overloaded method should be used.
keyStr
- string representation on single element keyNavuException
public NavuContainer elem(String[] keyArr) throws NavuException
This is a convenience method for lists with multiple element keys.
keyArr
- string array representation of a multiple element keyNavuException
public Collection<NavuContainer> elements() throws NavuException
The elements contained by this list node are not cloned
NavuException
public Collection<NavuNode> children() throws NavuException
children
in class NavuNode
NavuException
- if the elements could not be retrievedpublic List<ConfXMLParam> encodeXML() throws NavuException
NavuNode
NavuNode
as the topmost NavuNode
as a ConfXMLParam
array.
The returned ConfXMLParam
array contains no values except
for list keys. The leaf elements are encoded as ConfXMLParamLeaf
.
Therefore, the returning array can be used as a the input parameter
to NavuNode.getValues(ConfXMLParam[])
on the current node's parent.
NavuNode node = ...; ConfXMLParam[] cxa = node.encodeXML().toArray(new ConfXMLParam[0]); // cxa contains a structure that does not contain values except for // keys in list elements NavuNode parent = node.getParent(); ConfXMLParam[] cxb = parent.getValues(cxa); // cxb contains the same sub-tree with all the values
encodeXML
in class NavuNode
ConfXMLParam
objects corresponding to the
sub-tree of this node, with no values except list keys.NavuException
ConfXMLParam
,
ConfXMLParamValue
public List<ConfXMLParam> encodeValues() throws NavuException
NavuNode
NavuNode
as the topmost NavuNode
as a ConfXMLParam
array.
As opposed to NavuNode.encodeXML()
, the returned ConfXMLParam
array does contain values in the form of ConfXMLParamValue
encodeValues
in class NavuNode
ConfXMLParam
objects corresponding to the
sub-tree of this node, including all values.NavuException
ConfXMLParam
,
ConfXMLParamValue
public Set<Map.Entry<ConfKey,NavuListEntry>> entrySet() throws NavuException
NavuException
public boolean isEmpty() throws NavuException
NavuException
public Set<ConfKey> keySet() throws NavuException
NavuException
public void reset()
public Collection<NavuNode> select(List<String> path) throws NavuException
select
in class NavuNode
path
- a list of regular expression.NavuException
public Collection<NavuNode> select(String path) throws NavuException
select
in class NavuNode
path
- a "/" separated regular expression.NavuException
public int size() throws NavuException
NavuException
public void setMaxListSize(int maxSize)
maxSize
- max size of the list (default 0 unlimited)public void valueUpdateInd(NavuNode child) throws NavuException
valueUpdateInd
in class NavuNode
NavuException
public NavuNode setChange(List<ConfObject> path, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) throws NavuException
setChange
in class NavuNode
NavuException
public DiffIterateOperFlag getChangeFlag()
NavuNode
NavuNode
has
been a subject to by a transaction.getChangeFlag
in class NavuNode
DiffIterateOperFlag
public NavuNode getParent()
NavuNode
public Collection<NavuNode> select(ConfObject[] kp) throws NavuException
select
in class NavuNode
NavuException
public boolean isNodeNavuLocal()
@Deprecated public void set(String xml) throws NavuException
NavuNode.setValues(String)
method instead.xml
- XML structure corresponding values that will be setNavuException
public void move(String keyStr, NavuList.WhereTo whereTo, String toStr) throws NavuException
The destination
can be at the beginning, the end or in a relation to another element.
Elements are referenced by their string representation.
See: NavuList.move(ConfKey key, WhereTo whereTo, ConfKey to)
This is a convenience method for lists with single element
key. If the string is enclosed in curly braces like {test},
the curly braces are stripped. If this not desired another
overlaid method should be used
keyStr
- Move keyStr according to whereTowhereTo
- How the move should be performed. Move keyStr
WhereTo.FIRST or WhereTo.LAST or move keyStr
WhereTo.BEFORE or WhereTo.AFTER the element toStr.toStr
- If the value of whereTo is WhereTo.FIRST or WhereTo.LAST
this argument ignoredNavuException
public void move(ConfKey key, NavuList.WhereTo whereTo, ConfKey to) throws NavuException
The destination
can be at the beginning, the end or in a relation to another element.
See: NavuList.move(String keyStr, WhereTo whereTo, String toStr)
key
- Move key according to whereTowhereTo
- How the move should be performed. Move key
WhereTo.FIRST or WhereTo.LAST or move key
WhereTo.BEFORE or WhereTo.AFTER the element to.to
- If the value of whereTo is WhereTo.FIRST or WhereTo.LAST
this argument ignoredNavuException
public Iterator<NavuListEntry> iterator()
NavuList
(in proper sequence).iterator
in interface Iterable<NavuListEntry>
public boolean exists() throws NavuException
A list node can be contained inside a presence container.
If the container is not created the
exists
will return false. Similary if a
list node is contained within a case in choice that is
not selected exists
should return false.
exists
in class NavuNode
NavuList
instance in the instance treeNavuException
- on failure