Class NavuLeafList

All Implemented Interfaces:
Iterable<ConfValue>

public class NavuLeafList extends NavuLeaf implements Iterable<ConfValue>
NavuLeafList is a representation of the YANG leaf-list.

When accessing individual elements trough containsNode, NavuLeafList 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 leaf-list entries can be retrieved through elements() or by retrieving an iterator iterator(). The difference between the two is that elements() will make a single call to retrieve all the leaf-list elements, while iterator() will try to fetch leaf-list elements one by one using getNext() calls whenever possible.

 NavuNode parent = ...;
 NavuLeafList someLeafList = parent.leafList(someNamespace._someLeafList);

 for (ConfValue value : someLeafList) {
     // Here the elements will be fetched one by one
 }

 for (ConfValue value : someLeafList.elements()) {
     // Here the elements will be fetched using a single call
     // and stored in memory for the duration of the iteration
 }
 
  • Method Details

    • containsNode

      public boolean containsNode(ConfValue elem) throws NavuException
      Returns true if and only if this NavuLeafList contains this element.
      Parameters:
      elem - whose presence in this NavuLeafList is to be tested
      Returns:
      true if this NavuLeafList contains the element
      Throws:
      NavuException
    • containsNode

      public boolean containsNode(String elemStr) throws NavuException
      Returns true if and only if this NavuLeafList contains this element.
      Parameters:
      elemStr - string representation of the element whose presence in this NavuLeafList is to be tested
      Returns:
      true if this NavuLeafList contains the element
      Throws:
      NavuException
    • create

      public void create(ConfValue elem) throws NavuException
      Creates leaf-list entry.

      We have 3 different variants of create.

      1. create() This method creates the leaf-list entry. If such entry already exists tt will fail with a NavuException with the error code set to ErrorCode.ERR_ALREADY_EXISTS.

      2. safeCreate() similar to create() with the sole difference that is silently succeeds even if the leaf-list entry already exists.

      3. sharedCreate() This method is useful when creating element in FASTMAP code, i.e code that implements a FASTMAP service. The sharedCreate() method maintains a reference counter on the created object. Furthermore, and attribute "backpointer" will be created on the created leaf-list entry indicating which "service" created the object

      Parameters:
      elem - the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur, or such entry already exists
    • create

      public void create(String elemStr) throws NavuException
      Creates leaf-list entry.

      We have 3 different variants of create.

      1. create() This method creates the leaf-list entry. If such entry already exists tt will fail with a NavuException with the error code set to ErrorCode.ERR_ALREADY_EXISTS.

      2. safeCreate() similar to create() with the sole difference that is silently succeeds even if the leaf-list entry already exists.

      3. sharedCreate() This method is useful when creating element in FASTMAP code, i.e code that implements a FASTMAP service. The sharedCreate() method maintains a reference counter on the created object. Furthermore, and attribute "backpointer" will be created on the created leaf-list entry indicating which "service" created the object

      Parameters:
      elemStr - the string representation of the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur, or such entry already exists.
    • safeCreate

      public void safeCreate(ConfValue elem) throws NavuException
      The variant of create that succeeds even if the object already exists.
      Parameters:
      elem - the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur.
    • safeCreate

      public void safeCreate(String elemStr) throws NavuException
      The variant of create that succeeds even if the object already exists.
      Parameters:
      elemStr - the string representation of the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur.
    • sharedCreate

      public void sharedCreate(ConfValue elem) throws NavuException
      The variant of create that succeeds even if the object already exists, and also maintains a reference counter on the object. When the FASTMAP algorithm applies to objects created with sharedCreate the object is not removed, but rather the reference counter is decremented.
      Parameters:
      elem - the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur.
    • sharedCreate

      public void sharedCreate(String elemStr) throws NavuException
      The variant of create that succeeds even if the object already exists, and also maintains a reference counter on the object. When The FASTMAP algorithm applies to objects created with sharedCreate the object is not removed, but rather the reference counter is decremented.
      Parameters:
      elemStr - the string representation of the leaf-list entry to be created
      Throws:
      NavuException - if any MAAPI operations fail during the create or IOException if socket errors would occur.
    • delete

      public void delete(ConfValue elem) throws NavuException
      Deletes an entry from the leaf-list.
      Parameters:
      elem - the element to delete.
      Throws:
      NavuException - If the method fails to delete the element.
    • delete

      public void delete(String elemStr) throws NavuException
      Deletes an entry from the leaf-list.
      Parameters:
      elemStr - string representation of the element to delete.
      Throws:
      NavuException - If the method fails to delete the element.
    • elements

      public Collection<ConfValue> elements() throws NavuException
      Returns a copy of elements contained by the leaf-list node.
      Returns:
      a copy of the collection of list elements.
      Throws:
      NavuException - if the elements could not be retrieved.
    • isEmpty

      public boolean isEmpty() throws NavuException
      Checks if there are any elements in the leaf-list.
      Returns:
      true if there no list entries, false otherwise,
      Throws:
      NavuException
    • size

      public int size() throws NavuException
      Returns the number of leaf-list elements contained by the leaf-list.
      Returns:
      the number of elements.
      Throws:
      NavuException
    • move

      public void move(String elemStr, NavuLeafList.WhereTo whereTo, String toStr) throws NavuException
      Move a leaf-list element to a new position.

      The destination can be at the beginning, the end or in a relation to another element. Elements are referenced by their string representation. See also: move(ConfValue key, WhereTo whereTo, ConfValue to)

      Parameters:
      elemStr - Move elemStr according to whereTo
      whereTo - How the move should be performed. Move elemStr WhereTo.FIRST or WhereTo.LAST or move elemStr WhereTo.BEFORE or WhereTo.AFTER the element toStr.
      toStr - If the value of whereTo is WhereTo.FIRST or WhereTo.LAST this argument ignored
      Throws:
      NavuException
    • move

      public void move(ConfValue elem, NavuLeafList.WhereTo whereTo, ConfValue to) throws NavuException
      Move a leaf-list element to a new position.

      The destination can be at the beginning, the end or in a relation to another element.

      Parameters:
      elem - Move elem according to whereTo
      whereTo - How the move should be performed. Move elem WhereTo.FIRST or WhereTo.LAST or move elem WhereTo.BEFORE or WhereTo.AFTER the element to.
      to - If the value of whereTo is WhereTo.FIRST or WhereTo.LAST this argument ignored
      Throws:
      NavuException
    • iterator

      public Iterator<ConfValue> iterator()
      Retrieve a iterator over the elements in this NavuLeafList (in proper sequence).
      Specified by:
      iterator in interface Iterable<ConfValue>