Class HTMLFragment

java.lang.Object
com.amalgamasimulation.desktop.html.HTMLFragment
All Implemented Interfaces:
HTMLConvertable

public class HTMLFragment extends Object implements HTMLConvertable
Represents a container for multiple HTML components that can be converted to HTML. Supports hierarchical numbering for headers and allows building complex HTML structures through composition. Maintains internal numbering state for consistent section numbering across nested fragments.
Author:
Alexey Glazyrin
  • Constructor Details

    • HTMLFragment

      public HTMLFragment()
      Creates an empty HTML fragment.
    • HTMLFragment

      public HTMLFragment(List<? extends HTMLConvertable> children)
      Creates a fragment from a list of HTML components.
      Parameters:
      children - list of components to include in the fragment
  • Method Details

    • of

      public static HTMLFragment of(HTMLConvertable... children)
      Creates a fragment from variable arguments of HTML components.
      Parameters:
      children - array of components to include in the fragment
      Returns:
      new HTMLFragment containing specified components
    • withNumbering

      public HTMLFragment withNumbering(boolean withNumbering)
      Enables or disables automatic hierarchical numbering for headers.
      Parameters:
      withNumbering - true to enable section numbering, false to disable
      Returns:
      this fragment for method chaining
    • append

      public HTMLFragment append(HTMLConvertable child)
      Appends a new HTML component to the fragment.
      Parameters:
      child - component to add
      Returns:
      this fragment for method chaining
    • toHTML

      public String toHTML(Set<String> outStrings)
      Description copied from interface: HTMLConvertable
      Converts the object to an HTML string.
      Specified by:
      toHTML in interface HTMLConvertable
      Parameters:
      outStrings - set of unique strings of text content
      Returns:
    • copy

      public HTMLFragment copy(Map<String,String> stringsSubstitutionMap)
      Description copied from interface: HTMLConvertable
      Creates a deep copy of this HTMLConvertable element, preserving the element's structure while substituting text content using the provided translation mapping.
      Specified by:
      copy in interface HTMLConvertable
      Parameters:
      stringsSubstitutionMap - a map where keys are original text strings (as collected by HTMLConvertable.toHTML(Set)) and values are their translations. During copying, any encountered text content present in this map will be replaced with its translated version.
      Returns:
      a new independent copy of this HTMLConvertable instance with translated content