- All Implemented Interfaces:
-
Cloneable
DomElement, but it has no attributes nor other element properties. It's a thin extension of DomContainer.
Fragment can be added to any DomContainer, including another DomFragment. When added, the fragment is automatically inlined. Fragment thus cannot appear as a child of DomElement or another DomFragment.
It is recommended that application methods take and return DomContent instead of DomElement, which enables methods to pass around any combination of elements and plain text as DomFragment, including an empty fragment, instead of just a single DomElement.
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty DOM fragment.DomFragment(DomFragment other) Creates deep mutable copy of the DOM fragment. -
Method Summary
Modifier and TypeMethodDescriptionadd(DomContent child) Adds new child node to this fragment.Adds literal text to this fragment Consecutive text nodes will be concatenated.<C extends DomContent>
DomFragmentadd(Collection<C> children) Adds all nodes in aCollectionto this fragment.<C extends DomContent>
DomFragmentAdds all nodes in aStreamto this fragment.assign(DomFragment other) Replaces contents of this fragment with contents of another fragment.clone()Creates mutable deep clone of thisDomFragment.booleanCompares content of two fragments.freeze()Protects this fragment from further modification.inthashCode()Computes hash code of this fragment.static DomFragmentjoin(DomContent separator, Iterable<? extends DomContent> items) static DomFragmentjoin(String separator, Iterable<? extends DomContent> items) Methods inherited from class com.machinezoo.pushmode.dom.DomContainer
children, descendants, element, elements, elements, rawChildCount, rawChildren, rawChildren, rawFreeze, textMethods inherited from class com.machinezoo.pushmode.dom.DomContent
toString
-
Constructor Details
-
Method Details
-
clone
Creates mutable deep clone of thisDomFragment. All child nodes are cloned recursively. The clone is completely independent of this fragment.- Specified by:
-
clonein classDomContainer - Returns:
- deep mutable clone
- See Also:
-
assign
Replaces contents of this fragment with contents of another fragment. Since fragment is merely a list of child nodes, these child nodes are copied from the source fragment into this fragment. Previous content of this fragment is discarded.Most of the DOM API consists of builder-like API to construct DOM trees. When DOM tree must be modified, it is recommended to completely rebuild it, perhaps using bits of the old tree in the process, and return the new tree. However, it is sometimes not possible to change the returned pointer and in those cases the fragment must be actually modified. Application should build new fragment as usual and then use this method to replace contents of the original fragment.
- Parameters:
-
other- source fragment to be assigned to this fragment - Returns:
-
this - Throws:
-
IllegalStateException- if this fragment is frozen - See Also:
-
equals
Compares content of two fragments. If the supplied object is notDomFragment, this method returns false. Equality is unaffected by whether the fragments are frozen or not. Children of both fragments are compared recursively by calling theirDomContent.equals(Object)methods.- Overrides:
-
equalsin classDomContainer - Parameters:
-
object- object to compare this fragment with - Returns:
-
trueif the two fragments are equal,falseotherwise
-
hashCode
public int hashCode()Computes hash code of this fragment. It is computed by combining hash codes of all children. Hash code is unaffected by whether the fragment is frozen or not.- Overrides:
-
hashCodein classDomContainer - Returns:
- fragment's hash code
-
add
Adds new child node to this fragment. Fragments will be inlined,nulls ignored, and text concatenated.- Overrides:
-
addin classDomContainer - Parameters:
-
child- node to add (ignored ifnull) - Returns:
-
this - Throws:
-
IllegalStateException- if this element or fragment is frozen - See Also:
-
add
Adds all nodes in aCollectionto this fragment. Fragments will be inlined,nulls ignored, and text concatenated.- Overrides:
-
addin classDomContainer - Type Parameters:
-
C- item type - Parameters:
-
children- collection of child nodes to add (ignored ifnull) - Returns:
-
this - Throws:
-
IllegalStateException- if this element or fragment is frozen - See Also:
-
add
Adds all nodes in aStreamto this fragment. Fragments will be inlined,nulls ignored, and text concatenated.- Overrides:
-
addin classDomContainer - Type Parameters:
-
C- item type - Parameters:
-
children-Streamof child nodes to add (ignored ifnull) - Returns:
-
this - Throws:
-
IllegalStateException- if this element or fragment is frozen - See Also:
-
add
Adds literal text to this fragment Consecutive text nodes will be concatenated.- Overrides:
-
addin classDomContainer - Parameters:
-
text- text to add (ignored ifnullor empty) - Returns:
-
this - Throws:
-
IllegalStateException- if this element or fragment is frozen - See Also:
-
freeze
Protects this fragment from further modification. For more information, use cases, and thread safety, seeDomContent.freeze().- Overrides:
-
freezein classDomContainer - Returns:
-
this - See Also:
-
join
@NoDocs @DraftApi("separate overloads for Collection and Stream") public static DomFragment join(DomContent separator, Iterable<? extends DomContent> items) -
join
@NoDocs @DraftApi("separate overloads for Collection and Stream") public static DomFragment join(String separator, Iterable<? extends DomContent> items)
-