Class AbstractNode<N extends AbstractNode<N>>
- java.lang.Object
-
- com.atlassian.adf.model.node.AbstractNode<N>
-
- Direct Known Subclasses:
AbstractContentNode,AbstractMarkedNode,BlockCard,Date,EmbedCard,Emoji,HardBreak,InlineCard,Media.AbstractMedia,Mention,Placeholder,Rule,Status
@Internal public abstract class AbstractNode<N extends AbstractNode<N>> extends Object implements Node
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractNode.ToStringHelper
-
Constructor Summary
Constructors Constructor Description AbstractNode()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidappendNodeFields(AbstractNode.ToStringHelper buf)Allows nodes that have their own fields to augment thetoString()implementation with their own field values.voidappendPlainText(StringBuilder sb)Renders this node as plain-text suitable for viewing by end users.protected static booleandoubleEq(double a, double b)protected static intdoubleHash(double value)booleanequals(Object obj)After checking for the trivial cases ofobj == this,obj == null, orgetClass() != obj.getClass(), delegates equality testing tonodeEquals(AbstractNode).inthashCode()Hashes the node's class together withnodeHashCode().booleanisSupported()Indicates whether this element is fully supported by this library.protected FieldMapmapWithType()protected booleannodeEquals(N other)Allows nodes that have their own fields to augment theequalsimplementation with tests for their own field values.protected intnodeHashCode()Allows nodes that have their own fields to augment thehashCodeimplementation with a hash of their own field values.protected static booleannumberEq(Number a, Number b)protected static intnumberHash(Number value)protected Nself()StringtoPlainText()Renders this node as a plain-text string representation that is suitable for viewing by end users.StringtoString()Generates atoString()that is suitable for debugging or logging.-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.atlassian.adf.model.Element
elementType, toMap, validate
-
-
-
-
Method Detail
-
mapWithType
protected FieldMap mapWithType()
-
isSupported
public final boolean isSupported()
Description copied from interface:ElementIndicates whether this element is fully supported by this library. This library includes a small amount of support for preserving new, unrecognized node types during a round trip. These are represented by immutable placeholder objects that returnfalsefor this value.- Specified by:
isSupportedin interfaceElement- Returns:
truefor fully supported elements;falsefor immutable placeholders
-
hashCode
public final int hashCode()
Hashes the node's class together withnodeHashCode(). Implementations that define their own private fields should overridenodeHashCode()to include their information in the hashed value.- Overrides:
hashCodein classObject- See Also:
nodeHashCode()
-
equals
public final boolean equals(@Nullable Object obj)After checking for the trivial cases ofobj == this,obj == null, orgetClass() != obj.getClass(), delegates equality testing tonodeEquals(AbstractNode).- Overrides:
equalsin classObject- See Also:
nodeEquals(AbstractNode)
-
toString
public final String toString()
Generates atoString()that is suitable for debugging or logging.Note that this is not the same as the
plain-textrendering of the node, which is less informative and in many cases will be entirely empty.- Overrides:
toStringin classObject- See Also:
toPlainText()
-
toPlainText
public final String toPlainText()
Renders this node as a plain-text string representation that is suitable for viewing by end users.Note that this is not the same as the standard Java
Object.toString()method, which this library reserves for debugging and logging use, only.- Specified by:
toPlainTextin interfaceNode
-
nodeHashCode
protected int nodeHashCode()
Allows nodes that have their own fields to augment thehashCodeimplementation with a hash of their own field values.Implementations need not include the node's class; that is already covered by the
hashCode()implementation that is expected to be this method's only consumer.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Returns:
- the hash code of any additional field values that belong to a particular type of content node.
- See Also:
nodeEquals(AbstractNode),appendNodeFields(ToStringHelper)
-
nodeEquals
protected boolean nodeEquals(N other)
Allows nodes that have their own fields to augment theequalsimplementation with tests for their own field values.Implementations need not check for identity,
null, or a different node class; those are already covered by theequals(Object)implementation that is expected to be this method's only consumer.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Returns:
trueif all additional field values that belong to a particular type of content node test as equal;falseif differences are found- See Also:
nodeHashCode(),appendNodeFields(ToStringHelper)
-
appendNodeFields
protected void appendNodeFields(AbstractNode.ToStringHelper buf)
Allows nodes that have their own fields to augment thetoString()implementation with their own field values.Each field's value should be provided by calling
AbstractNode.ToStringHelper.appendField(String, Object). Thevaluemay benull, in which case the field is omitted, for brevity. It will handle array values gracefully, including arrays of primitive types.Just as with the relationship between
hashCode,equals, andtoStringfor ordinary Java classes, subclasses ofAbstractNodeshould maintain consistent implementations ofnodeHashCode,nodeEquals, andappendNodeFields.- Parameters:
buf- where the field values should be written- See Also:
nodeHashCode(),nodeEquals(AbstractNode)
-
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- Parameters:
sb- where to write the result
-
self
protected final N self()
-
doubleEq
protected static boolean doubleEq(double a, double b)
-
doubleHash
protected static int doubleHash(double value)
-
numberHash
protected static int numberHash(@Nullable Number value)
-
-