Class WikiTextParentNode

java.lang.Object
com.lucaskjaerozhang.wikitext_parser.ast.base.WikiTextNode
com.lucaskjaerozhang.wikitext_parser.ast.base.WikiTextParentNode
All Implemented Interfaces:
WikiTextElement
Direct Known Subclasses:
Article, Bold, CategoryList, CategoryList.Category, ExternalLink, IndentedBlock, Italic, ListItem, Section, WikiLink, WikiTextList, XMLContainerElement

public abstract class WikiTextParentNode extends WikiTextNode
A node that has child nodes. This abstract class contains the logic for serializing the node into XML.
  • Constructor Details

    • WikiTextParentNode

      protected WikiTextParentNode(List<WikiTextNode> children)
      Constructs the node
      Parameters:
      children - The child nodes
  • Method Details

    • getCategories

      public Set<String> getCategories()
      Description copied from interface: WikiTextElement
      Category links are leaf nodes but we want to include them as attributes of an article. This gives us three cases to consider:
      1. Leaf nodes that are category links. We want to pass these up to the parent nodes. This is handled in Category objects.
      2. Other leaf nodes. These aren't categories and should return nothing. This is the default case in the WikiTextNode interface.
      3. Parent nodes. These aren't categories by themselves, and should return the union of the categories of their children. This is handled in WikiTextParent nodes
      Returns:
      A set of categories as strings.
    • getFieldValuesFromChildren

      public static Set<String> getFieldValuesFromChildren(List<WikiTextNode> children, Function<? super WikiTextNode,Set<String>> getter)
      There is data that flow up to the root from leaf nodes. In this case we can think of it as the union of the child node data.
      Parameters:
      children - The child elements to get data from.
      getter - The function that gets the data
      Returns:
      All data from the child elements.
    • rebuildWithContext

      public WikiTextNode rebuildWithContext(TreeConstructionContext context)
      Overrides:
      rebuildWithContext in class WikiTextNode