Package com.atlassian.adf.model.node
Class ListItem
- java.lang.Object
-
- com.atlassian.adf.model.node.AbstractNode<C>
-
- com.atlassian.adf.model.node.AbstractContentNode<ListItem,ListItemContent>
-
- com.atlassian.adf.model.node.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 abulletListor anorderedList.Only the nodes that implement the
ListItemContentmarker interface are permitted as content. Additionally, althoughcodeBlockandparagraphnodes are permitted as content, they are not allowed to use any marks.Finally, although
listItemnodes may contain a nestedbulletListororderedList, these are disallowed for the first content item. If there is nothing else to display before the nested list, use anempty paragraph.Implementation Note
This library tries very hard to use the compiler's type system to enforce correctness wherever it can. However, sincebulletListandorderedListmust implementListItemContentso 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 anexceptionwhen 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.atlassian.adf.model.node.AbstractNode
AbstractNode.ToStringHelper
-
-
Field Summary
-
Fields inherited from class com.atlassian.adf.model.node.AbstractContentNode
content
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappendPlainText(StringBuilder sb)Renders this node as plain-text suitable for viewing by end users.Class<ListItemContent>contentClass()ReturnsClass<N>, the class representing the type of items held by this node.protected voidcontentNodeValidate()ListItemcopy()Returns a deep copy of this element, including copies of any nodes or marks that it contains.StringelementType()Thetypevalue that identifies this element, such as"paragraph"or"strong".static ListItemli()static ListItemli(ListItemContent content)static ListItemli(ListItemContent... content)static ListItemli(Iterable<? extends ListItemContent> content)static ListItemli(String content)static ListItemli(String... content)static ListItemli(Stream<? extends ListItemContent> content)static ListItemlistItem()static ListItemlistItem(ListItemContent content)static ListItemlistItem(ListItemContent... content)static ListItemlistItem(Iterable<? extends ListItemContent> content)static ListItemlistItem(String content)static ListItemlistItem(String... content)static ListItemlistItem(Stream<? extends ListItemContent> content)Map<String,?>toMap()Transforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.protected voidvalidateContentNodeForAppend(ListItemContent node)Called on each content node before it is added to validate that the node can be accepted.-
Methods inherited from class com.atlassian.adf.model.node.AbstractContentNode
addContent, addContentIfPresent, allNodes, appendContentNodeFields, appendNodeFields, appendPlainTextContentJoinedWith, appendPlainTextInlineContent, clear, content, content, content, content, content, contentFieldMaps, contentNodeEquals, contentNodeHashCode, isEmpty, nodeEquals, nodeHashCode, parseContentItem, parseContentItems, parseOptionalContent, parseRequiredContent, parseRequiredContentAllowEmpty, removeIf, replaceContent, requireNotEmpty, transformContent, transformDescendants, trim, validate, validateContentItems
-
Methods inherited from class com.atlassian.adf.model.node.AbstractNode
doubleEq, doubleHash, equals, hashCode, isSupported, mapWithType, numberEq, numberHash, self, toPlainText, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.adf.model.node.type.ContentNode
allNodesOfType, allNodesOfTypeAsList
-
Methods inherited from interface com.atlassian.adf.model.Element
isSupported
-
Methods inherited from interface com.atlassian.adf.model.node.Node
toPlainText
-
-
-
-
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(ListItemContent content)
- Returns:
- a new list item with the given content
-
li
public static ListItem li(ListItemContent... content)
- Returns:
- a new list item with the given content
-
li
public static ListItem li(Iterable<? extends ListItemContent> content)
- Returns:
- a new list item with the given content
-
li
public static ListItem li(Stream<? extends ListItemContent> content)
- Returns:
- a new list item with the given content
-
listItem
public static ListItem listItem(String content)
- See Also:
li(String)
-
listItem
public static ListItem listItem(String... content)
- See Also:
li(String[])
-
listItem
public static ListItem listItem(ListItemContent content)
- See Also:
li(ListItemContent)
-
listItem
public static ListItem listItem(ListItemContent... content)
- See Also:
li(ListItemContent[])
-
listItem
public static ListItem listItem(Iterable<? extends ListItemContent> content)
- See Also:
li(Iterable)
-
listItem
public static ListItem listItem(Stream<? extends ListItemContent> content)
- See Also:
li(Stream)
-
contentClass
public Class<ListItemContent> contentClass()
Description copied from interface:ContentNodeReturnsClass<N>, the class representing the type of items held by this node.
-
copy
public ListItem copy()
Description copied from interface:ElementReturns 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, atextnode that is used inside acodeBlockwill 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 thisif the element is immutable. The@Immutableannotation 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
parseandtoMapmethods already have to be updated in these circumstances, so it makes sense to take advantage of that.
- Returns:
- a copy of this element, or
thisif the element is immutable anyway
-
elementType
public String elementType()
Description copied from interface:ElementThetypevalue that identifies this element, such as"paragraph"or"strong".
-
contentNodeValidate
protected void contentNodeValidate()
- Overrides:
contentNodeValidatein classAbstractContentNode<ListItem,ListItemContent>
-
toMap
public Map<String,?> toMap()
Description copied from interface:ElementTransforms this element to a map ofStringvalues to various basic object types suitable for direct rendering as JSON content.- Returns:
- the map representation of this ADF element
-
validateContentNodeForAppend
protected void validateContentNodeForAppend(ListItemContent node)
Description copied from class:AbstractContentNodeCalled on each content node before it is added to validate that the node can be accepted.- Overrides:
validateContentNodeForAppendin classAbstractContentNode<ListItem,ListItemContent>- Parameters:
node- the node that is about to be added
-
appendPlainText
public void appendPlainText(StringBuilder sb)
Description copied from interface:NodeRenders this node as plain-text suitable for viewing by end users. This is equivalent to callingNode.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:
appendPlainTextin interfaceNode- Overrides:
appendPlainTextin classAbstractContentNode<ListItem,ListItemContent>- Parameters:
sb- where to write the result
-
-