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
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionchildren()Returns all elements contained by the list node.booleancontainsNode(ConfKey key) Returns true if and only if thisNavuListcontains aNavuListEntrywhereNavuListEntry.getKey()equalsthe specifiedkey.booleancontainsNode(NavuContainer node) Returnstrueif thisNavuListmaps aConfKeyto the specifiedNavuContainer.booleancontainsNode(String keyStr) Returnstrueif thisNavuListcontains a mapping for the specified string representation of a key.booleancontainsNode(String[] keyArr) Returnstrueif thisNavuListcontains 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 aConfObjectas 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.voidDeletes an element from the list.voidDeletes an element from the list.voidDeletes an element from the list.voidDeletes 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 currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.Encodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.entrySet()Returns a set of entries with element key and element.booleanCompares the specified object with thisNavuListfor equality.booleanexists()Tests for the existence of the List node in the instance tree.Returns the latest change that thisNavuNodehas been a subject to by a transaction.Returns the parent of the node.inthashCode()Return the hashCode of this NavuNode.Inserts an element into a list using Maapi.insert().booleanisEmpty()Checks if there are any elements in the list.booleaniterator()Retrieve a iterator over the elements in thisNavuList(in proper sequence).keySet()Returns a Set containing all of the keys for this list.voidmove(ConfKey key, NavuList.WhereTo whereTo, ConfKey to) Move a list element to a new position in the list.voidmove(String keyStr, NavuList.WhereTo whereTo, String toStr) Move a list element to a new position in the list.voidreset()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) setChange(List<ConfObject> path, DiffIterateOperFlag op, ConfValue oldValue, NavuContext delContext) voidsetMaxListSize(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.intsize()Returns the number of list elements contained by the list node.toString()voidvalueUpdateInd(NavuNode child) Methods inherited from class com.tailf.navu.NavuNode
container, container, container, context, getChanges, getChanges, getChanges, getConfPath, getInfo, getKeyPath, getName, getNavuNode, getRootNS, getValues, getValues, leaf, leaf, leaf, leafList, leafList, leafList, list, list, list, namespace, prepareXMLCall, setValues, setValues, sharedSetValues, sharedSetValues, stopCdbSession, xPathSelect, xPathSelectIterateMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
containsNode
Returns true if and only if thisNavuListcontains aNavuListEntrywhereNavuListEntry.getKey()equalsthe specifiedkey.- Parameters:
key- whose presence in thisNavuListis to be tested- Returns:
trueif thisNavuListcontains a entry with the specifiedkey- Throws:
NavuException
-
containsNode
Returnstrueif thisNavuListcontains a mapping for the specified string representation of a key.- Parameters:
keyStr- a string representation of a key whose presence in thisNavuListis to be tested- Returns:
trueif thisNavuListmaps a keys to the specified node- Throws:
NavuException
-
containsNode
Returnstrueif thisNavuListcontains 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 thisNavuListis to be tested- Returns:
trueif thisNavuListmaps 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 aNavuExceptionwith the error code set toErrorCode.ERR_ALREADY_EXISTSif 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 aConfObjectas 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:
childrenin classNavuNode- Returns:
- a collection of list elements
- Throws:
NavuException- if the elements could not be retrieved
-
encodeXML
Description copied from class:NavuNodeEncodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.The returned
ConfXMLParamarray 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:
encodeXMLin classNavuNode- Returns:
- A list of
ConfXMLParamobjects corresponding to the sub-tree of this node, with no values except list keys. - Throws:
NavuException- See Also:
-
encodeValues
Description copied from class:NavuNodeEncodes the sub-tree including the currentNavuNodeas the topmostNavuNodeas aConfXMLParamarray.As opposed to
NavuNode.encodeXML(), the returnedConfXMLParamarray does contain values in the form ofConfXMLParamValue- Specified by:
encodeValuesin classNavuNode- Returns:
- A list of
ConfXMLParamobjects 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:
selectin classNavuNode- Parameters:
path- a list of regular expression.- Returns:
- a collection a nodes marching the query
- Throws:
NavuException
-
select
- Specified by:
selectin 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 thisNavuNodehas been a subject to by a transaction.- Overrides:
getChangeFlagin classNavuNode- Returns:
- Flag for the latest change
- See Also:
-
getParent
Description copied from class:NavuNodeReturns the parent of the node. -
select
- Specified by:
selectin classNavuNode- Returns:
- a collection a nodes matching a Regular Expression query
- Throws:
NavuException
-
iterator
Retrieve a iterator over the elements in thisNavuList(in proper sequence).- Specified by:
iteratorin 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
existswill return false. Similary if a list node is contained within a case in choice that is not selectedexistsshould return false.- Specified by:
existsin classNavuNode- Returns:
- true/false on existence of this
NavuListinstance in the instance tree - Throws:
NavuException- on failure
-
equals
Compares the specified object with thisNavuListfor equality. Returnstrueif the given object is also aNavuListand it has the sameConfPathas thisNavuList. -
hashCode
public int hashCode()Description copied from class:NavuNodeReturn the hashCode of this NavuNode. For most nodes, the hash code is based on theConfPathof the node. For module root containers there is noConfPathand instead the hash code is based on the hash code of the module schema.
-