eu.cdevreeze.yaidom.queryapi

UpdatableElemLike

trait UpdatableElemLike[N, E <: N with UpdatableElemLike[N, E]] extends IsNavigable[E] with UpdatableElemApi[N, E]

API and implementation trait for functionally updatable elements. This trait extends trait eu.cdevreeze.yaidom.queryapi.IsNavigable, adding knowledge about child nodes in general, and about the correspondence between child path entries and child indexes.

More precisely, this trait adds the following abstract methods to the abstract methods required by its super-trait: children, withChildren and childNodeIndex. Based on these abstract methods (and the super-trait), this trait offers a rich API for functionally updating elements.

The purely abstract API offered by this trait is eu.cdevreeze.yaidom.queryapi.UpdatableElemApi. See the documentation of that trait for examples of usage, and for a more formal treatment.

N

The node supertype of the element subtype

E

The captured element subtype

Self Type
E
Linear Supertypes
UpdatableElemApi[N, E], IsNavigable[E], IsNavigableApi[E], AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. UpdatableElemLike
  2. UpdatableElemApi
  3. IsNavigable
  4. IsNavigableApi
  5. AnyRef
  6. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def childNodeIndex(childPathEntry: Entry): Int

    Returns the child node index of the child element at the given path entry, if any, and -1 otherwise.

    Returns the child node index of the child element at the given path entry, if any, and -1 otherwise. The faster this method is, the better.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  2. abstract def children: IndexedSeq[N]

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  3. abstract def findChildElemByPathEntry(entry: Entry): Option[E]

    Finds the child element with the given Path.Entry (where this element is the root), if any, wrapped in an Option.

    Finds the child element with the given Path.Entry (where this element is the root), if any, wrapped in an Option.

    Typically this method must be very efficient, in order for methods like findElemOrSelfByPath to be efficient.

    Definition Classes
    IsNavigableIsNavigableApi
  4. abstract def withChildren(newChildren: IndexedSeq[N]): E

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi

Concrete Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

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

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

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

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def findElemOrSelfByPath(path: Path): Option[E]

    Finds the element with the given Path (where this element is the root), if any, wrapped in an Option.

    Finds the element with the given Path (where this element is the root), if any, wrapped in an Option.

    That is, returns:

    findReverseAncestryOrSelfByPath(path).map(_.last)

    Note that for each non-empty Path, we have:

    findElemOrSelfByPath(path) == findChildElemByPathEntry(path.firstEntry) flatMap (e => e.findElemOrSelfByPath(path.withoutFirstEntry))
    Definition Classes
    IsNavigableIsNavigableApi
  12. final def findReverseAncestryOrSelfByPath(path: Path): Option[IndexedSeq[E]]

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option.

    Finds the reversed ancestry-or-self of the element with the given Path (where this element is the root), wrapped in an Option. None is returned if no element can be found at the given Path.

    Hence, the resulting element collection, if any, starts with this element and ends with the element at the given Path, relative to this element.

    This method comes in handy for (efficiently) computing base URIs, where the (reverse) ancestry-or-self is needed as input.

    Definition Classes
    IsNavigableIsNavigableApi
  13. final def getChildElemByPathEntry(entry: Entry): E

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Returns (the equivalent of) findChildElemByPathEntry(entry).get

    Definition Classes
    IsNavigableIsNavigableApi
  14. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  15. final def getElemOrSelfByPath(path: Path): E

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Returns (the equivalent of) findElemOrSelfByPath(path).get

    Definition Classes
    IsNavigableIsNavigableApi
  16. final def getReverseAncestryOrSelfByPath(path: Path): IndexedSeq[E]

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Returns (the equivalent of) findReverseAncestryOrSelfByPath(path).get

    Definition Classes
    IsNavigableIsNavigableApi
  17. def hashCode(): Int

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

    Definition Classes
    Any
  19. final def minusChild(index: Int): E

    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.size.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  20. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  21. final def notify(): Unit

    Definition Classes
    AnyRef
  22. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  23. final def plusChild(child: N): E

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  24. final def plusChild(index: Int, child: N): E

    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.size, adds the element at the end. If index > children.size, throws an exception.

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  25. final def plusChildOption(childOption: Option[N]): E

    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(childOption.get) if the given optional child element is non-empty.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  26. final def plusChildOption(index: Int, childOption: Option[N]): E

    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(index, childOption.get) if the given optional child element is non-empty.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  27. final def plusChildren(childSeq: IndexedSeq[N]): E

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  28. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  29. def toString(): String

    Definition Classes
    AnyRef → Any
  30. final def updated(path: Path, newElem: E): E

    Returns updated(path) { e => newElem }

    Returns updated(path) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  31. final def updated(path: Path)(f: (E) ⇒ E): E

    Method that "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).

    Method that "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).

    The method throws an exception if no element is found with the given path.

    It can be defined (recursively) as follows:

    if (path == Path.Root) f(self)
    else updated(path.firstEntry) { e => e.updated(path.withoutFirstEntry)(f) }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  32. final def updated(pathEntry: Entry)(f: (E) ⇒ E): E

    Core method that "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).

    Core method that "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).

    The method throws an exception if no element is found with the given path entry.

    It can be defined as follows:

    val idx = self.childNodeIndex(pathEntry)
    self.withUpdatedChildren(idx, f(children(idx).asInstanceOf[E]))
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  33. final def updatedAtPathEntries(pathEntries: Set[Entry])(f: (E, Entry) ⇒ E): E

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).

    It can be defined as follows (ignoring exceptions):

    val newChildren = pathEntries.toSeq.map(entry => (entry -> childNodeIndex(entry))).sortBy(_._2).reverse.foldLeft(children) {
      case (acc, (pathEntry, idx)) =>
        acc.updated(idx, f(acc(idx).asInstanceOf[E], pathEntry))
    }
    withChildren(newChildren)
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  34. final def updatedAtPaths(paths: Set[Path])(f: (E, Path) ⇒ E): E

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant-or-self elements with the given paths (compared to this element as root).

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant-or-self elements with the given paths (compared to this element as root).

    It can be defined (recursively) as follows (ignoring exceptions):

    def updatedAtPaths(paths: Set[Path])(f: (E, Path) => E): E = {
    val pathsByPathEntries = paths.filter(path => !path.isRoot).groupBy(path => path.firstEntry)
    val resultWithoutSelf = self.updatedAtPathEntries(pathsByPathEntries.keySet) { (che, pathEntry) =>
      val newChe = che.updatedAtPaths(paths.map(_.withoutFirstEntry)) { (elem, relativePath) =>
        f(elem, relativePath.prepend(pathEntry))
      }
      newChe
    }
    if (paths.contains(Path.Root)) f(resultWithoutSelf, Path.Root) else resultWithoutSelf
    }

    For simple elements, it is also equivalent to:

    val pathsReversed = indexed.Elem(this).findAllElemsOrSelf.map(_.path).filter(p => paths.contains(p)).reverse
    pathsReversed.foldLeft(self) { case (acc, path) => acc.updated(path) { e => f(e, path) } }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  35. final def updatedWithNodeSeq(path: Path, newNodes: IndexedSeq[N]): E

    Returns updatedWithNodeSeq(path) { e => newNodes }

    Returns updatedWithNodeSeq(path) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  36. final def updatedWithNodeSeq(path: Path)(f: (E) ⇒ IndexedSeq[N]): E

    "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:

    // First define function g as follows:
    
    def g(e: Elem): Elem = {
      if (path == Path.Root) e
      else {
        e.withPatchedChildren(
          e.childNodeIndex(path.lastEntry),
          f(e.findChildElemByPathEntry(path.lastEntry).get),
          1)
      }
    }
    
    // Then the function updatedWithNodeSeq(path)(f) could be defined as:
    
    updated(path.parentPathOption.getOrElse(Path.Root))(g)

    After all, this is just a functional update that replaces the parent element, if it exists.

    The method throws an exception if no element is found with the given path.

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  37. final def updatedWithNodeSeqAtPathEntries(pathEntries: Set[Entry])(f: (E, Entry) ⇒ IndexedSeq[N]): E

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all child elements with the given path entries (compared to this element as root).

    It can be defined as follows (ignoring exceptions):

    val indexesByPathEntries = pathEntries.toSeq.map(entry => (entry -> childNodeIndex(entry))).sortBy(_._2).reverse
    val newChildGroups =
      indexesByPathEntries.foldLeft(self.children.map(n => immutable.IndexedSeq(n))) {
        case (acc, (pathEntry, idx)) =>
          acc.updated(idx, f(acc(idx).head.asInstanceOf[E], pathEntry))
      }
    withChildren(newChildGroups.flatten)
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  38. final def updatedWithNodeSeqAtPaths(paths: Set[Path])(f: (E, Path) ⇒ IndexedSeq[N]): E

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant elements with the given paths (compared to this element as root), but ignoring the root path.

    Method that "functionally updates" the tree with this element as root element, by applying the passed function to all descendant elements with the given paths (compared to this element as root), but ignoring the root path.

    It can be defined as follows (ignoring exceptions):

    val pathsByParentPaths = paths.filter(path => !path.isRoot).groupBy(path => path.parentPath)
    self.updatedAtPaths(pathsByParentPaths.keySet) { (elem, path) =>
      val childPathEntries = pathsByParentPaths(path).map(_.lastEntry)
      elem.updatedWithNodeSeqAtPathEntries(childPathEntries) { (che, pathEntry) =>
        f(che, path.append(pathEntry))
      }
    }
    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  39. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  42. final def withChildSeqs(newChildSeqs: IndexedSeq[IndexedSeq[N]]): E

    Shorthand for withChildren(newChildSeqs.flatten)

    Shorthand for withChildren(newChildSeqs.flatten)

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  43. final def withPatchedChildren(from: Int, newChildren: IndexedSeq[N], replace: Int): E

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  44. final def withUpdatedChildren(index: Int, newChild: N): E

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

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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi

Inherited from UpdatableElemApi[N, E]

Inherited from IsNavigable[E]

Inherited from IsNavigableApi[E]

Inherited from AnyRef

Inherited from Any

Ungrouped