Class AbstractNode<N extends AbstractNode<N>>

    • Constructor Detail

      • AbstractNode

        public AbstractNode()
    • Method Detail

      • mapWithType

        protected FieldMap mapWithType()
      • isSupported

        public final boolean isSupported()
        Description copied from interface: Element
        Indicates 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 return false for this value.
        Specified by:
        isSupported in interface Element
        Returns:
        true for fully supported elements; false for immutable placeholders
      • hashCode

        public final int hashCode()
        Hashes the node's class together with nodeHashCode(). Implementations that define their own private fields should override nodeHashCode() to include their information in the hashed value.
        Overrides:
        hashCode in class Object
        See Also:
        nodeHashCode()
      • toString

        public final String toString()
        Generates a toString() that is suitable for debugging or logging.

        Note that this is not the same as the plain-text rendering of the node, which is less informative and in many cases will be entirely empty.

        Overrides:
        toString in class Object
        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:
        toPlainText in interface Node
      • nodeHashCode

        protected int nodeHashCode()
        Allows nodes that have their own fields to augment the hashCode implementation 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, and toString for ordinary Java classes, subclasses of AbstractNode should maintain consistent implementations of nodeHashCode, nodeEquals, and appendNodeFields.

        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 the equals implementation with tests for their own field values.

        Implementations need not check for identity, null, or a different node class; those are already covered by the equals(Object) implementation that is expected to be this method's only consumer.

        Just as with the relationship between hashCode, equals, and toString for ordinary Java classes, subclasses of AbstractNode should maintain consistent implementations of nodeHashCode, nodeEquals, and appendNodeFields.

        Returns:
        true if all additional field values that belong to a particular type of content node test as equal; false if differences are found
        See Also:
        nodeHashCode(), appendNodeFields(ToStringHelper)
      • appendNodeFields

        protected void appendNodeFields​(AbstractNode.ToStringHelper buf)
        Allows nodes that have their own fields to augment the toString() implementation with their own field values.

        Each field's value should be provided by calling AbstractNode.ToStringHelper.appendField(String, Object). The value may be null, 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, and toString for ordinary Java classes, subclasses of AbstractNode should maintain consistent implementations of nodeHashCode, nodeEquals, and appendNodeFields.

        Parameters:
        buf - where the field values should be written
        See Also:
        nodeHashCode(), nodeEquals(AbstractNode)
      • 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
        Parameters:
        sb - where to write the result
      • self

        protected final N self()
      • doubleEq

        protected static boolean doubleEq​(double a,
                                          double b)
      • numberEq

        protected static boolean numberEq​(@Nullable
                                          Number a,
                                          @Nullable
                                          Number b)
      • doubleHash

        protected static int doubleHash​(double value)
      • numberHash

        protected static int numberHash​(@Nullable
                                        Number value)