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.

    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: Any): Boolean

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

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

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

    Definition Classes
    Any
  5. def clone(): AnyRef

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

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

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

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. 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. This method must be very efficient, which depends on the efficiency of method findChildElemByPathEntry.

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

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

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

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

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

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

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

    Definition Classes
    IsNavigableIsNavigableApi
  13. def hashCode(): Int

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

    Definition Classes
    Any
  15. 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

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

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

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

    Definition Classes
    AnyRef
  19. 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
  20. 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)

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  21. 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

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  22. 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)

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

    Definition Classes
    AnyRef
  24. def toString(): String

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

    Returns updated(path) { e => newElem }

    Returns updated(path) { e => newElem }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  26. 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
  27. 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
  28. 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
  29. 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
  30. final def updatedWithNodeSeq(path: Path, newNodes: IndexedSeq[N]): E

    Returns updatedWithNodeSeq(path) { e => newNodes }

    Returns updatedWithNodeSeq(path) { e => newNodes }

    Definition Classes
    UpdatableElemLikeUpdatableElemApi
  31. 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
  32. 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
  33. 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
  34. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  37. 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
  38. 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