Class Json5Element

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.String comment
      Associated comment on this element.
    • Constructor Summary

      Constructors 
      Constructor Description
      Json5Element()  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      abstract Json5Element deepCopy()
      Returns a deep copy of this element.
      boolean equals​(java.lang.Object o)  
      java.math.BigDecimal getAsBigDecimal()
      Convenience method to get this element as a BigDecimal.
      java.math.BigInteger getAsBigInteger()
      Convenience method to get this element as a BigInteger.
      java.lang.String getAsBinaryString()
      Convenience method to get this element as a primitive binary number (radix base 2) value.
      boolean getAsBoolean()
      Convenience method to get this element as a boolean value.
      byte getAsByte()
      Convenience method to get this element as a primitive byte value.
      double getAsDouble()
      Convenience method to get this element as a primitive double value.
      float getAsFloat()
      Convenience method to get this element as a primitive float value.
      java.lang.String getAsHexString()
      Convenience method to get this element as a primitive hex number (radix base 16) value.
      java.time.Instant getAsInstant()
      Convenience method to get this element as a Instant value.
      int getAsInt()
      Convenience method to get this element as a primitive integer value.
      Json5Array getAsJson5Array()
      Convenience method to get this element as a Json5Array.
      Json5Null getAsJson5Null()
      Convenience method to get this element as a Json5Null.
      Json5Object getAsJson5Object()
      Convenience method to get this element as a Json5Object.
      Json5Primitive getAsJson5Primitive()
      Convenience method to get this element as a Json5Primitive.
      long getAsLong()
      Convenience method to get this element as a primitive long value.
      java.lang.Number getAsNumber()
      Convenience method to get this element as a Number.
      java.lang.String getAsOctalString()
      Convenience method to get this element as a primitive octal number (radix base 8) value.
      RadixNumber getAsRadixNumber()
      Convenience method to get this element as a RadixNumber.
      short getAsShort()
      Convenience method to get this element as a primitive short value.
      java.lang.String getAsString()
      Convenience method to get this element as a string value.
      java.lang.String getComment()
      Returns the associated comment on this element.
      boolean hasComment()
      Provides a check for verifying if this element has an associated comment.
      int hashCode()  
      boolean isJson5Array()
      Provides a check for verifying if this element is a Json5 array or not.
      boolean isJson5Null()
      Provides a check for verifying if this element represents a null value or not.
      boolean isJson5Object()
      Provides a check for verifying if this element is a Json5 object or not.
      boolean isJson5Primitive()
      Provides a check for verifying if this element is a primitive or not.
      void setComment​(java.lang.String comment)
      Updates the associated comment on this element.
      java.lang.String toString()
      Converts this element to a Json5 string.
      java.lang.String toString​(Json5Options options)
      Converts this element to a Json5 string using the provided configuration options for formatting.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • comment

        protected java.lang.String comment
        Associated comment on this element. Can be null to omit. Supports multi-line comments by using the break-line control character \n.
    • Constructor Detail

      • Json5Element

        public Json5Element()
    • Method Detail

      • hasComment

        public boolean hasComment()
        Provides a check for verifying if this element has an associated comment.
        Returns:
        true if this element has an associated comment, false otherwise.
      • getComment

        public java.lang.String getComment()
        Returns the associated comment on this element. Can be null if not set.
        Returns:
        optional comment string
      • setComment

        public void setComment​(java.lang.String comment)
        Updates the associated comment on this element. Supports multi-line comments with break-line control character.
        Parameters:
        comment - Comment to set. Can be null to omit.
      • deepCopy

        public abstract Json5Element deepCopy()
        Returns a deep copy of this element.
        Returns:
        Deep copy
      • isJson5Array

        public boolean isJson5Array()
        Provides a check for verifying if this element is a Json5 array or not.
        Returns:
        true if this element is of type Json5Array, false otherwise.
      • isJson5Object

        public boolean isJson5Object()
        Provides a check for verifying if this element is a Json5 object or not.
        Returns:
        true if this element is of type Json5Object, false otherwise.
      • isJson5Primitive

        public boolean isJson5Primitive()
        Provides a check for verifying if this element is a primitive or not.
        Returns:
        true if this element is of type Json5Primitive, false otherwise.
      • isJson5Null

        public boolean isJson5Null()
        Provides a check for verifying if this element represents a null value or not.
        Returns:
        true if this element is of type Json5Null, false otherwise.
      • getAsJson5Object

        public Json5Object getAsJson5Object()
        Convenience method to get this element as a Json5Object. If this element is of some other type, an IllegalStateException will result. Hence it is best to use this method after ensuring that this element is of the desired type by calling isJson5Object() first.
        Returns:
        this element as a Json5Object.
        Throws:
        java.lang.IllegalStateException - if this element is of another type.
      • getAsJson5Array

        public Json5Array getAsJson5Array()
        Convenience method to get this element as a Json5Array. If this element is of some other type, an IllegalStateException will result. Hence it is best to use this method after ensuring that this element is of the desired type by calling isJson5Array() first.
        Returns:
        this element as a Json5Array.
        Throws:
        java.lang.IllegalStateException - if this element is of another type.
      • getAsJson5Primitive

        public Json5Primitive getAsJson5Primitive()
        Convenience method to get this element as a Json5Primitive. If this element is of some other type, an IllegalStateException will result. Hence it is best to use this method after ensuring that this element is of the desired type by calling isJson5Primitive() first.
        Returns:
        this element as a Json5Primitive.
        Throws:
        java.lang.IllegalStateException - if this element is of another type.
      • getAsJson5Null

        public Json5Null getAsJson5Null()
        Convenience method to get this element as a Json5Null. If this element is of some other type, an IllegalStateException will result. Hence it is best to use this method after ensuring that this element is of the desired type by calling isJson5Null() first.
        Returns:
        this element as a Json5Null.
        Throws:
        java.lang.IllegalStateException - if this element is of another type.
      • getAsBoolean

        public boolean getAsBoolean()
        Convenience method to get this element as a boolean value.
        Returns:
        this element as a primitive boolean value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsInstant

        public java.time.Instant getAsInstant()
        Convenience method to get this element as a Instant value.
        Returns:
        this element as a primitive Instant value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsNumber

        public java.lang.Number getAsNumber()
        Convenience method to get this element as a Number.
        Returns:
        this element as a Number.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array, or cannot be converted to a number.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsRadixNumber

        public RadixNumber getAsRadixNumber()
        Convenience method to get this element as a RadixNumber.
        Returns:
        this element as a RadixNumber.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array, or cannot be converted to a radix number.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsString

        public java.lang.String getAsString()
        Convenience method to get this element as a string value.
        Returns:
        this element as a string value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsDouble

        public double getAsDouble()
        Convenience method to get this element as a primitive double value.
        Returns:
        this element as a primitive double value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid double.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsFloat

        public float getAsFloat()
        Convenience method to get this element as a primitive float value.
        Returns:
        this element as a primitive float value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid float.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsLong

        public long getAsLong()
        Convenience method to get this element as a primitive long value.
        Returns:
        this element as a primitive long value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid long.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsInt

        public int getAsInt()
        Convenience method to get this element as a primitive integer value.
        Returns:
        this element as a primitive integer value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid integer.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsByte

        public byte getAsByte()
        Convenience method to get this element as a primitive byte value.
        Returns:
        this element as a primitive byte value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid byte.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsBigDecimal

        public java.math.BigDecimal getAsBigDecimal()
        Convenience method to get this element as a BigDecimal.
        Returns:
        this element as a BigDecimal.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if this element is not a valid BigDecimal.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsBigInteger

        public java.math.BigInteger getAsBigInteger()
        Convenience method to get this element as a BigInteger.
        Returns:
        this element as a BigInteger.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if this element is not a valid BigInteger.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsShort

        public short getAsShort()
        Convenience method to get this element as a primitive short value.
        Returns:
        this element as a primitive short value.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid short.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsBinaryString

        public java.lang.String getAsBinaryString()
        Convenience method to get this element as a primitive binary number (radix base 2) value.

        This is an extension that is not compliant to the official Json5 spec.

        Returns:
        this element as a primitive binary number value string.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid short.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsOctalString

        public java.lang.String getAsOctalString()
        Convenience method to get this element as a primitive octal number (radix base 8) value.

        This is an extension that is not compliant to the official Json5 spec.

        Returns:
        this element as a primitive octal number value string.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid short.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • getAsHexString

        public java.lang.String getAsHexString()
        Convenience method to get this element as a primitive hex number (radix base 16) value.
        Returns:
        this element as a primitive hex number value string.
        Throws:
        java.lang.UnsupportedOperationException - if this element is not a Json5Primitive or Json5Array.
        java.lang.NumberFormatException - if the value contained is not a valid short.
        java.lang.IllegalStateException - if this element is of the type Json5Array but contains more than a single element.
      • toString

        public java.lang.String toString​(Json5Options options)
        Converts this element to a Json5 string using the provided configuration options for formatting.
        Parameters:
        options - Configuration options.
        Returns:
        Json5 string representation of this element.
      • toString

        public java.lang.String toString()
        Converts this element to a Json5 string.

        For example:

         Json5Object object = new Json5Object();
         object.add("a", new Json5Null());
         Json5Array array = new Json5Array();
         array.add(1);
         object.add("b", array);
        
         String json = object.toString();
         // json: {"a":null,"b":[1]}
         

        To get the contained String value (without enclosing " and without escaping), use getAsString() instead:

         Json5Primitive Json5Primitive = new Json5Primitive("with \" quote");
         String json = Json5Primitive.toString();
         // json: "with \" quote"
         String value = Json5Primitive.getAsString();
         // value: with " quote
         
        Overrides:
        toString in class java.lang.Object
        See Also:
        toString(Json5Options)
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object