Class DomFragment

  • All Implemented Interfaces:
    Cloneable

    @NoTests
    public final class DomFragment
    extends DomContainer
    Fragment of PushMode DOM tree. Fragment can have children just like 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 Detail

      • DomFragment

        public DomFragment()
        Creates an empty DOM fragment.
      • DomFragment

        public DomFragment​(DomFragment other)
        Creates deep mutable copy of the DOM fragment. Calling this constructor is equivalent to calling clone().
        Parameters:
        other - fragment to copy
        See Also:
        clone()
    • Method Detail

      • assign

        public DomFragment assign​(DomFragment other)
        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:
        clone(), DomFragment(DomFragment)
      • equals

        public boolean equals​(Object object)
        Compares content of two fragments. If the supplied object is not DomFragment, this method returns false. Equality is unaffected by whether the fragments are frozen or not. Children of both fragments are compared recursively by calling their DomContent.equals(Object) methods.
        Overrides:
        equals in class DomContainer
        Parameters:
        object - object to compare this fragment with
        Returns:
        true if the two fragments are equal, false otherwise
      • 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:
        hashCode in class DomContainer
        Returns:
        fragment's hash code