DOM nodes can be mutable (
DomFragment) or immutable (
DomText). Mutable nodes can be frozen, which causes all mutating methods to throw and improves thread-safety. DOM nodes can be thus in three states: immutable, mutable, and frozen. Immutable state cannot be changed. Transition from mutable to frozen state is performed by
freeze(). Transition from frozen to mutable state is performed by
clone() or appropriate copy constructor.
DOM content has value semantics. It can be copied, compared for equality, and hashed. Elements and fragments can be assigned.
HTML representation of the node can be obtained by using
DomFormatter. For debugging purposes, it is also available from
toString(). All text stored recursively in the DOM node can be obtained by calling
DOM content is safe to read concurrently by multiple threads. Write operations cannot be concurrent with reads or other writes.
|Modifier and Type||Method and Description|
Creates deep clone of this node.
Compares this node with another DOM node for equality.
Protects this node from further modification.
Computes deep hash code of the node.
Gets concatenated text content of this node.
Gets serialized HTML code for this node for debugging purposes.
public abstract DomContent clone()
this. For frozen and mutable nodes, this method returns mutable deep clone that is completely independent of this node.
public boolean equals(Object obj)
public int hashCode()
public abstract DomContent freeze()
IllegalStateExceptionwhen executed on frozen node. Freezing is recursive. Frozen nodes therefore cannot contain mutable nodes. If this node is immutable by nature (i.e.
DomText) or already frozen, this method has no effect.
Freezing is particularly useful in caches that provide the same DOM tree to multiple threads. While unfrozen DOM trees can be safely shared, this relies on threads voluntarily abstaining from modifications. Caches can protect consistency of data they return by freezing the returned DOM tree, which will effectively enable a runtime check causing any mutating methods to throw. If some thread runs buggy code that tries to modify the DOM tree obtained from shared cache, the buggy code will throw an exception while the cached DOM tree is left intact.
Besides marking the node as frozen, freezing modifies internal data structures to save memory. All internal arrays are compacted to their minimum required size.
Freezing is carefully implemented in such a way that multiple threads can safely attempt to freeze the same node at the same time. Freezing is also safe to run concurrently with reads. This is an exception to the general prohibition of concurrent modifications. This exception was added to ensure that downstream cache can freeze its output even though it incorporates unfrozen subtree obtained from upstream cache. The nested DOM tree from upstream cache is frozen as a byproduct of freezing parent DOM tree in the downstream cache. Since freezing doesn't change anything observable about the DOM tree except for blocking writes, freezing is also safe for the upstream cache.
@DraftApi(value="perhaps add space around block elements and some other elements (br), perhaps normalize whitespace") public abstract String text()
public String toString()
DomFormatterto reliably produce HTML.
Copyright © 2015–2021 Robert Važan. All rights reserved.