Class NavuList
- All Implemented Interfaces:
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 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
children()
, elements()
or by retrieving
an iterator 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.
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionchildren()
Returns all elements contained by the list node.boolean
containsNode
(ConfKey key) Returns true if and only if thisNavuList
contains aNavuListEntry
whereNavuListEntry.getKey()
equals
the specifiedkey
.boolean
containsNode
(NavuContainer node) Returnstrue
if thisNavuList
maps aConfKey
to the specifiedNavuContainer
.boolean
containsNode
(String keyStr) Returnstrue
if thisNavuList
contains a mapping for the specified string representation of a key.boolean
containsNode
(String[] keyArr) Returnstrue
if thisNavuList
contains a mapping for the specified string representation of a key.Create and return a new list element in thisNavuList
.create
(ConfObject key) Convenience variant ofcreate(ConfKey)
accepting aConfObject
as the (single element) key.Convenience variant ofcreate(ConfKey)
accepting a string as the (single element) key.Convenience variant ofcreate(ConfKey)
accepting a string array as the key.void
Deletes an element from the list.void
Deletes an element from the list.void
Deletes an element from the list.void
Deletes all element from the list.Returns a list element according to the given key.Returns a list element according to the given key.Returns a list element according to the given array of keys.elements()
Returns a shallow copy of all elements contained by the list node.Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.entrySet()
Returns a set of entries with element key and element.boolean
Compares the specified object with thisNavuList
for equality.boolean
exists()
Tests for the existence of the List node in the instance tree.Returns the latest change that thisNavuNode
has been a subject to by a transaction.Returns the parent of the node.Inserts an element into a list using Maapi.insert().boolean
isEmpty()
Checks if there are any elements in the list.boolean
iterator()
Retrieve a iterator over the elements in thisNavuList
(in proper sequence).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.safeCreate
(ConfKey key) Variant ofcreate(ConfKey)
that succeeds even if the key already exists.safeCreate
(ConfObject key) Variant ofcreate(ConfObject)
that succeeds even if the key already exists.safeCreate
(String keyStr) Variant ofcreate(String)
that succeeds even if the key already exists.safeCreate
(String[] keyArr) Variant ofcreate(String[])
that succeeds even if the key already exists.select
(ConfObject[] kp) void
Deprecated.setChange
(List<ConfObject> path, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) void
setMaxListSize
(int maxSize) Sets the maxSize of the internal HashMap of list elements.sharedCreate
(ConfKey key) Variant ofcreate(ConfKey)
that succeeds even if the key already exists, and also maintains a reference counter on the object.sharedCreate
(ConfObject key) Variant ofcreate(ConfObject)
that succeeds even if the key already exists, and also maintains a reference counter on the object.sharedCreate
(String keyStr) Variant ofcreate(String)
that succeeds even if the key already exists, and also maintains a reference counter on the object.sharedCreate
(String[] keyArr) Variant ofcreate(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.toString()
void
valueUpdateInd
(NavuNode child) Methods inherited from class com.tailf.navu.NavuNode
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
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
containsNode
Returns true if and only if thisNavuList
contains aNavuListEntry
whereNavuListEntry.getKey()
equals
the specifiedkey
.- Parameters:
key
- whose presence in thisNavuList
is to be tested- Returns:
true
if thisNavuList
contains a entry with the specifiedkey
- Throws:
NavuException
-
containsNode
Returnstrue
if thisNavuList
contains a mapping for the specified string representation of a key.- Parameters:
keyStr
- a string representation of a key whose presence in thisNavuList
is to be tested- Returns:
true
if thisNavuList
maps a keys to the specified node- Throws:
NavuException
-
containsNode
Returnstrue
if thisNavuList
contains a mapping for the specified string representation of a key.This is a convenience method for lists with multiple element key.
- Parameters:
keyArr
- elements of the specified key contains string representation of a key whose presence in thisNavuList
is to be tested- Returns:
true
if thisNavuList
maps a the specified keys in the array- Throws:
NavuException
-
create
Create and return a new list element in thisNavuList
.We have 3 different variants of
create
.create()
This method will fail with aNavuException
with the error code set toErrorCode.ERR_ALREADY_EXISTS
if the key already exists.safeCreate()
Similar tocreate()
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. ThesharedCreate()
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.- Parameters:
key
- the key with which the newly created list entry is to be associated- Returns:
- the created list entry
- Throws:
NavuException
-
create
Convenience variant ofcreate(ConfKey)
accepting aConfObject
as the (single element) key.- Parameters:
key
- the key with which the newly created list entry is to be associated- Returns:
- the created list entry
- Throws:
NavuException
-
create
Convenience variant of
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.
- Parameters:
keyStr
- the key with which the newly created list entry is to be associated- Returns:
- the created list entry
- Throws:
NavuException
-
create
Convenience variant ofcreate(ConfKey)
accepting a string array as the key. Typically useful for multiple element keys.- Parameters:
keyArr
- the string array from which to create the key that the newly created list entry is to be associated with- Returns:
- the created list entry
- Throws:
NavuException
-
safeCreate
Variant ofcreate(ConfKey)
that succeeds even if the key already exists.- Parameters:
key
- the key with which the newly created list entry is to be associated- Returns:
- the created list entry or, if it already exists, the list entry
corresponding to the given key,
key
- Throws:
NavuException
-
safeCreate
Variant ofcreate(ConfObject)
that succeeds even if the key already exists.- Parameters:
key
- the key with which the newly created list entry is to be associated- Returns:
- the created list entry or, if it already exists, the list entry
corresponding to the given key,
key
- Throws:
NavuException
-
safeCreate
Variant ofcreate(String)
that succeeds even if the key already exists.- Parameters:
keyStr
- the string representation of the key value with which the newly created list entry is to be associated- Returns:
- the created list entry or, if it already exists, the list entry
corresponding to the given key,
key
- Throws:
NavuException
-
safeCreate
Variant ofcreate(String[])
that succeeds even if the key already exists.- Parameters:
keyArr
- the string array from which to create the key that the newly created list entry is to be associated with- Returns:
- the created list entry or, if it already exists, the list entry
corresponding to the given key,
keyArr
- Throws:
NavuException
-
delete
Deletes an element from the list.- Parameters:
key
- the key of the element to delete- Throws:
NavuException
-
deleteAll
Deletes all element from the list.- Throws:
NavuException
-
delete
Deletes an element from the list.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.
- Parameters:
keyStr
- string representation of a single element key- Throws:
NavuException
-
delete
Deletes an element from the list. This is a convenience method for lists with multiple element keys.- Parameters:
keyArr
- string array representation of a multiple element key- Throws:
NavuException
-
insert
Inserts an element into a list using Maapi.insert(). This is only applicable for lists that have the annotation tailf:indexed-view An interesting special case is when a list has also the annotation tailf:auto-compact. The createBackpointer variable should then be set to true. When we insert an entry into an auto compact list, the createBackpointer makes NCS follow all backpointers in the list and update the corresponding diffsets so that FastMap continues to work. The Key must be an integer key. In NCS this construct is sometimes used in NEDs, modelling devices that have lists that 'auto compact' sometimes ACLs can be like that, if we remove an entry in the middle, the following entries are moved up. It is only allowed to create new entries at the end of lists that are auto-compact. The first entry of the list has key one (1).- Throws:
NavuException
-
elem
Returns a list element according to the given key.- Parameters:
key
- a key identifying the list element- Returns:
- a matching element, or null if no matching element is found
- Throws:
NavuException
-
elem
Returns a list element according to the given key.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.
- Parameters:
keyStr
- string representation on single element key- Returns:
- a matching list element or null, if no matching element is found.
- Throws:
NavuException
-
elem
Returns a list element according to the given array of keys.This is a convenience method for lists with multiple element keys.
- Parameters:
keyArr
- string array representation of a multiple element key- Returns:
- a matching list element, or null if no matching element is found
- Throws:
NavuException
-
elements
Returns a shallow copy of all elements contained by the list node.The elements contained by this list node are not cloned
- Returns:
- a copy of the collection of list elements
- Throws:
NavuException
-
children
Returns all elements contained by the list node.- Overrides:
children
in classNavuNode
- Returns:
- a collection of list elements
- Throws:
NavuException
- if the elements could not be retrieved
-
encodeXML
Description copied from class:NavuNode
Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.The returned
ConfXMLParam
array contains no values except for list keys. The leaf elements are encoded asConfXMLParamLeaf
. Therefore, the returning array can be used as a the input parameter toNavuNode.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
- Specified by:
encodeXML
in classNavuNode
- Returns:
- A list of
ConfXMLParam
objects corresponding to the sub-tree of this node, with no values except list keys. - Throws:
NavuException
- See Also:
-
encodeValues
Description copied from class:NavuNode
Encodes the sub-tree including the currentNavuNode
as the topmostNavuNode
as aConfXMLParam
array.As opposed to
NavuNode.encodeXML()
, the returnedConfXMLParam
array does contain values in the form ofConfXMLParamValue
- Specified by:
encodeValues
in classNavuNode
- Returns:
- A list of
ConfXMLParam
objects corresponding to the sub-tree of this node, including all values. - Throws:
NavuException
- See Also:
-
entrySet
Returns a set of entries with element key and element.- Returns:
- a set of entries
- Throws:
NavuException
-
isEmpty
Checks if there are any elements in the list.- Returns:
- true if there are no list entries, false otherwise,
- Throws:
NavuException
-
keySet
Returns a Set containing all of the keys for this list.- Returns:
- the full set of keys for this list
- Throws:
NavuException
-
reset
public void reset()When navigating through NAVU to a certain list, the list values are cached as they are read. This method clears this cache and and indicates to Navu that the list elements should be re-read as they are retrieved. -
select
- Specified by:
select
in classNavuNode
- Parameters:
path
- a list of regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
select
- Specified by:
select
in classNavuNode
- Parameters:
path
- a "/" separated regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
size
Returns the number of list elements contained by the list node.- Returns:
- the number of elements in this list
- Throws:
NavuException
-
setMaxListSize
public void setMaxListSize(int maxSize) Sets the maxSize of the internal HashMap of list elements. If the maxSize is reached new elements will imply that the oldest element is silently removed. If set to 0 the list is unlimited. Note, this function should NOT be used if the implications are unknown or not understood.- Parameters:
maxSize
- max size of the list (default 0 unlimited)
-
toString
-
getChangeFlag
Returns the latest change that thisNavuNode
has been a subject to by a transaction.- Overrides:
getChangeFlag
in classNavuNode
- Returns:
- Flag for the latest change
- See Also:
-
getParent
Description copied from class:NavuNode
Returns the parent of the node. -
select
- Specified by:
select
in classNavuNode
- Returns:
- a collection a nodes matching a Regular Expression query
- Throws:
NavuException
-
set
Deprecated.This method is deprecated use theNavuNode.setValues(String)
method instead.- Parameters:
xml
- XML structure corresponding values that will be set- Throws:
NavuException
-
iterator
Retrieve a iterator over the elements in thisNavuList
(in proper sequence).- Specified by:
iterator
in interfaceIterable<NavuListEntry>
-
exists
Tests for the existence of the List node in the instance tree.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 selectedexists
should return false.- Specified by:
exists
in classNavuNode
- Returns:
- true/false on existence of this
NavuList
instance in the instance tree - Throws:
NavuException
- on failure
-
equals
Compares the specified object with thisNavuList
for equality. Returnstrue
if the given object is also aNavuList
and it has the sameConfPath
as thisNavuList
.
-