Class ListItem

  • All Implemented Interfaces:
    Element, Node, ContentNode<ListItem,​ListItemContent>

    @Documentation(state=INCOMPLETE,
                   date="2023-07-26",
                   comment="should say \'bulletList\' and \'orderedList\' are disallowed for the first content item")
    public class ListItem
    extends AbstractContentNode<ListItem,​ListItemContent>
    Represents an item in either a bulletList or an orderedList.

    Only the nodes that implement the ListItemContent marker interface are permitted as content. Additionally, although codeBlock and paragraph nodes are permitted as content, they are not allowed to use any marks.

    Finally, although listItem nodes may contain a nested bulletList or orderedList, these are disallowed for the first content item. If there is nothing else to display before the nested list, use an empty paragraph.

    Implementation Note

    This library tries very hard to use the compiler's type system to enforce correctness wherever it can. However, since bulletList and orderedList must implement ListItemContent so that they can be added as content at all, there was no way to exclude them from satisfying the type system when adding the first content item. This must therefore be checked at runtime and will result in an exception when violated.

    Example

    Java

     ul(li("Hello world"));
     

    ADF

    
       {
         "type": "bulletList",
         "content": [
           {
             "type": "listItem",
             "content": [
               {
                 "type": "paragraph",
                 "content": [
                   {
                     "type": "text",
                     "text": "Hello world"
                   }
                 ]
               }
             ]
           }
         ]
       }
     

    Result

    • Hello world

    See Also:
    Node - listItem
    • Method Detail

      • li

        public static ListItem li()
        Returns:
        a new, empty list item. At least one content item must be added to make it valid.
      • li

        public static ListItem li​(String content)
        Returns:
        a convenient shorthand for li(p(content))
      • li

        public static ListItem li​(String... content)
        Returns:
        a convenient shorthand for li(p(content))
      • listItem

        public static ListItem listItem()
        See Also:
        li()
      • contentClass

        public Class<ListItemContent> contentClass()
        Description copied from interface: ContentNode
        Returns Class<N>, the class representing the type of items held by this node.
      • copy

        public ListItem copy()
        Description copied from interface: Element
        Returns a deep copy of this element, including copies of any nodes or marks that it contains. The copy will not necessarily be in exactly the same state as the original in some cases. For example, a text node that is used inside a codeBlock will have the ability to use marks on it disabled, but a copy made of the text node using this method will not similarly disallow marks unless it is also added to a content node with those same restrictions.

        Implementations notes:

        • Implementations should narrow the return type.
        • Implementations should return this if the element is immutable. The @Immutable annotation should be used on the class to offer additional confirmation of this intent.
        • Implementations should return parse(toMap()) if they have state.
        • While there may be cases where it is worthwhile to do something more efficient than the conversion to a map and back, this is discouraged because it would add yet another fragile piece of code that breaks when new data is added to the node. The parse and toMap methods already have to be updated in these circumstances, so it makes sense to take advantage of that.
        Returns:
        a copy of this element, or this if the element is immutable anyway
      • elementType

        public String elementType()
        Description copied from interface: Element
        The type value that identifies this element, such as "paragraph" or "strong".
      • toMap

        public Map<String,​?> toMap()
        Description copied from interface: Element
        Transforms this element to a map of String values to various basic object types suitable for direct rendering as JSON content.
        Returns:
        the map representation of this ADF element
      • appendPlainText

        public void appendPlainText​(StringBuilder sb)
        Description copied from interface: Node
        Renders this node as plain-text suitable for viewing by end users. This is equivalent to calling Node.toPlainText() and appending the result to the given buffer, except that it may be slightly more efficient, since it will write directly to the existing buffer instead of using a temporary buffer and having to make a copy of the result.
        Specified by:
        appendPlainText in interface Node
        Overrides:
        appendPlainText in class AbstractContentNode<ListItem,​ListItemContent>
        Parameters:
        sb - where to write the result