Trait/Object

eu.cdevreeze.yaidom.queryapi

ElemUpdateApi

Related Docs: object ElemUpdateApi | package queryapi

Permalink

trait ElemUpdateApi extends AnyRef

This is the element (functional) update API, as function API instead of OO API. That is, this is the function API corresponding to trait eu.cdevreeze.yaidom.queryapi.UpdatableElemApi. A few methods, like updateTopmostElemsOrSelf, are missing, though.

See trait UpdatableElemApi for more info about (functional) element updates in yaidom, and their properties.

This functional API is more widely applicable than trait UpdatableElemApi. First, it can be implemented for arbitrary element types, even non-yaidom ones. Second, implementations can easily carry state that is shared by update functions, such as a Saxon Processor in the case of a Saxon implementation of this API.

Below, for most functions that take Paths or that take functions that take Paths the Paths are relative to the first argument element, so they must not be interpreted as the Paths of the elements themselves (relative to their root elements).

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ElemUpdateApi
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract type ElemType <: NodeType

    Permalink
  2. abstract type NodeType

    Permalink

Abstract Value Members

  1. abstract def childNodeIndex(elem: ElemType, pathEntry: Entry): Int

    Permalink

    Finds the child node index of the given path entry, or -1 if not found.

    Finds the child node index of the given path entry, or -1 if not found. More precisely, returns:

    collectChildNodeIndexes(elem, Set(pathEntry)).getOrElse(pathEntry, -1)
  2. abstract def children(elem: ElemType): IndexedSeq[NodeType]

    Permalink

    Returns the child nodes of this element, in the correct order

  3. abstract def collectChildNodeIndexes(elem: ElemType, pathEntries: Set[Entry]): Map[Entry, Int]

    Permalink

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes.

    Filters the child elements with the given path entries, and returns a Map from the path entries of those filtered elements to the child node indexes. The result Map has no entries for path entries that cannot be resolved. This method should be fast, especially if the passed path entry set is small.

  4. abstract def findAllChildElemsWithPathEntries(elem: ElemType): IndexedSeq[(ElemType, Entry)]

    Permalink

    Returns all child elements paired with their path entries.

  5. abstract def minusChild(elem: ElemType, index: Int): ElemType

    Permalink

    Returns a copy in which the child at the given position (0-based) has been removed.

    Returns a copy in which the child at the given position (0-based) has been removed. Throws an exception if index >= children(elem).size.

  6. abstract def plusChild(elem: ElemType, child: NodeType): ElemType

    Permalink

    Returns a copy in which the given child has been inserted at the end

  7. abstract def plusChild(elem: ElemType, index: Int, child: NodeType): ElemType

    Permalink

    Returns a copy in which the given child has been inserted at the given position (0-based).

    Returns a copy in which the given child has been inserted at the given position (0-based). If index == children(elem).size, adds the element at the end. If index > children(elem).size, throws an exception.

    Afterwards, the resulting element indeed has the given child at position index (0-based).

  8. abstract def plusChildOption(elem: ElemType, childOption: Option[NodeType]): ElemType

    Permalink

    Returns a copy in which the given child, if any, has been inserted at the end.

    Returns a copy in which the given child, if any, has been inserted at the end. That is, returns plusChild(elem, childOption.get) if the given optional child element is non-empty.

  9. abstract def plusChildOption(elem: ElemType, index: Int, childOption: Option[NodeType]): ElemType

    Permalink

    Returns a copy in which the given child, if any, has been inserted at the given position (0-based).

    Returns a copy in which the given child, if any, has been inserted at the given position (0-based). That is, returns plusChild(elem, index, childOption.get) if the given optional child element is non-empty.

  10. abstract def plusChildren(elem: ElemType, childSeq: IndexedSeq[NodeType]): ElemType

    Permalink

    Returns a copy in which the given children have been inserted at the end

  11. abstract def updateChildElem(elem: ElemType, pathEntry: Entry, newElem: ElemType): ElemType

    Permalink

    Returns updateChildElem(elem, pathEntry) { e => newElem }

  12. abstract def updateChildElem(elem: ElemType, pathEntry: Entry)(f: (ElemType) ⇒ ElemType): ElemType

    Permalink

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    It can be defined as follows:

    updateChildElems(elem, Set(pathEntry)) { case (che, pe) => f(che) }
  13. abstract def updateChildElemWithNodeSeq(elem: ElemType, pathEntry: Entry, newNodes: IndexedSeq[NodeType]): ElemType

    Permalink

    Returns updateChildElemWithNodeSeq(elem, pathEntry) { e => newNodes }

  14. abstract def updateChildElemWithNodeSeq(elem: ElemType, pathEntry: Entry)(f: (ElemType) ⇒ IndexedSeq[NodeType]): ElemType

    Permalink

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path.Entry (compared to this element as root).

    It can be defined as follows:

    updateChildElemsWithNodeSeq(elem, Set(pathEntry)) { case (che, pe) => f(che) }
  15. abstract def updateChildElems(elem: ElemType, f: (ElemType, Entry) ⇒ Option[ElemType]): ElemType

    Permalink

    Invokes updateChildElems, passing the path entries for which the passed function is defined.

    Invokes updateChildElems, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, ElemType] =
      findAllChildElemsWithPathEntries(elem).flatMap({ case (che, pe) =>
        f(che, pe).map(newE => (pe, newE)) }).toMap
    
    updateChildElems(elem, editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, che) }
  16. abstract def updateChildElems(elem: ElemType, pathEntries: Set[Entry])(f: (ElemType, Entry) ⇒ ElemType): ElemType

    Permalink

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function.

    That is, returns the equivalent of:

    updateChildElemsWithNodeSeq(elem, pathEntries) { case (che, pe) => Vector(f(che, pe)) }

    If the set of path entries is small, this method is rather efficient.

  17. abstract def updateChildElemsWithNodeSeq(elem: ElemType, f: (ElemType, Entry) ⇒ Option[IndexedSeq[NodeType]]): ElemType

    Permalink

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined.

    Invokes updateChildElemsWithNodeSeq, passing the path entries for which the passed function is defined. It is equivalent to:

    val editsByPathEntries: Map[Path.Entry, immutable.IndexedSeq[NodeType]] =
      findAllChildElemsWithPathEntries(elem).flatMap({ case (che, pe) =>
        f(che, pe).map(newNodes => (pe, newNodes)) }).toMap
    
    updateChildElemsWithNodeSeq(elem, editsByPathEntries.keySet) { case (che, pe) =>
      editsByPathEntries.getOrElse(pe, immutable.IndexedSeq(che))
    }
  18. abstract def updateChildElemsWithNodeSeq(elem: ElemType, pathEntries: Set[Entry])(f: (ElemType, Entry) ⇒ IndexedSeq[NodeType]): ElemType

    Permalink

    Updates the child elements with the given path entries, applying the passed update function.

    Updates the child elements with the given path entries, applying the passed update function. This is the core method of the update API, and the other methods have implementations that directly or indirectly depend on this method.

    That is, returns:

    if (pathEntries.isEmpty) elem
    else {
      val indexesByPathEntries: Seq[(Path.Entry, Int)] =
        collectChildNodeIndexes(elem, pathEntries).toSeq.sortBy(_._2)
    
      // Updating in reverse order of indexes, in order not to invalidate the path entries
      val newChildren = indexesByPathEntries.reverse.foldLeft(children(elem)) {
        case (accChildNodes, (pathEntry, idx)) =>
          val che = accChildNodes(idx).asInstanceOf[ElemType]
          accChildNodes.patch(idx, f(che, pathEntry), 1)
      }
      withChildren(elem, newChildren)
    }

    If the set of path entries is small, this method is rather efficient.

  19. abstract def updateElemOrSelf(elem: ElemType, path: Path, newElem: ElemType): ElemType

    Permalink

    Returns updateElemOrSelf(elem, path) { e => newElem }

  20. abstract def updateElemOrSelf(elem: ElemType, path: Path)(f: (ElemType) ⇒ ElemType): ElemType

    Permalink

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    It can be defined as follows:

    updateElemsOrSelf(elem, Set(path)) { case (e, path) => f(e) }
  21. abstract def updateElemWithNodeSeq(elem: ElemType, path: Path, newNodes: IndexedSeq[NodeType]): ElemType

    Permalink

    Returns updateElemWithNodeSeq(elem, path) { e => newNodes }

  22. abstract def updateElemWithNodeSeq(elem: ElemType, path: Path)(f: (ElemType) ⇒ IndexedSeq[NodeType]): ElemType

    Permalink

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root).

    Functionally updates the tree with this element as root element, by applying the passed function to the element that has the given eu.cdevreeze.yaidom.core.Path (compared to this element as root). If the given path is the root path, this element itself is returned unchanged.

    This function could be defined as follows:

    updateElemsWithNodeSeq(elem, Set(path)) { case (e, path) => f(e) }
  23. abstract def updateElems(elem: ElemType, paths: Set[Path])(f: (ElemType, Path) ⇒ ElemType): ElemType

    Permalink

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElems(elem, pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        updateElemsOrSelf(che, pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

  24. abstract def updateElemsOrSelf(elem: ElemType, paths: Set[Path])(f: (ElemType, Path) ⇒ ElemType): ElemType

    Permalink

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElems(elem, pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          updateElemsOrSelf(che, pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    In other words, returns:

    val descendantUpdateResult = updateElems(elem, paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else descendantUpdateResult

    If the set of paths is small, this method is rather efficient.

  25. abstract def updateElemsOrSelfWithNodeSeq(elem: ElemType, paths: Set[Path])(f: (ElemType, Path) ⇒ IndexedSeq[NodeType]): IndexedSeq[NodeType]

    Permalink

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    Updates the descendant-or-self elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    val descendantUpdateResult =
      updateChildElemsWithNodeSeq(elem, pathsByFirstEntry.keySet) {
        case (che, pathEntry) =>
          // Recursive (but non-tail-recursive) call
          updateElemsOrSelfWithNodeSeq(
            che, pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
            case (elm, path) =>
              f(elm, path.prepend(pathEntry))
          }
      }
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    In other words, returns:

    val descendantUpdateResult = updateElemsWithNodeSeq(elem, paths)(f)
    
    if (paths.contains(Path.Empty)) f(descendantUpdateResult, Path.Empty)
    else Vector(descendantUpdateResult)

    If the set of paths is small, this method is rather efficient.

  26. abstract def updateElemsWithNodeSeq(elem: ElemType, paths: Set[Path])(f: (ElemType, Path) ⇒ IndexedSeq[NodeType]): ElemType

    Permalink

    Updates the descendant elements with the given paths, applying the passed update function.

    Updates the descendant elements with the given paths, applying the passed update function.

    That is, returns:

    val pathsByFirstEntry: Map[Path.Entry, Set[Path]] =
      paths.filterNot(_.isEmpty).groupBy(_.firstEntry)
    
    updateChildElemsWithNodeSeq(elem, pathsByFirstEntry.keySet) {
      case (che, pathEntry) =>
        updateElemsOrSelfWithNodeSeq(
          che, pathsByFirstEntry(pathEntry).map(_.withoutFirstEntry)) {
          case (elm, path) =>
            f(elm, path.prepend(pathEntry))
        }
    }

    If the set of paths is small, this method is rather efficient.

  27. abstract def withChildSeqs(elem: ElemType, newChildSeqs: IndexedSeq[IndexedSeq[NodeType]]): ElemType

    Permalink

    Shorthand for withChildren(elem, newChildSeqs.flatten)

  28. abstract def withChildren(elem: ElemType, newChildren: IndexedSeq[NodeType]): ElemType

    Permalink

    Returns an element with the same name, attributes and scope as this element, but with the given child nodes

  29. abstract def withPatchedChildren(elem: ElemType, from: Int, newChildren: IndexedSeq[NodeType], replace: Int): ElemType

    Permalink

    Shorthand for withChildren(elem, children(elem).patch(from, newChildren, replace))

  30. abstract def withUpdatedChildren(elem: ElemType, index: Int, newChild: NodeType): ElemType

    Permalink

    Shorthand for withChildren(elem, children(elem).updated(index, newChild))

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped