Interface TomlPrimitive

All Superinterfaces:
TomlValue

@NonExtendable public interface TomlPrimitive extends TomlValue
Represents a TOML primitive (not a table or array)
See Also:
  • Method Details

    • of

      @Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(String value)
      Creates a primitive of type STRING wrapping the given string value
      Throws:
      NullPointerException - Value is null
    • of

      @Contract("_ -> new") @NotNull static @NotNull TomlPrimitive of(boolean value)
      Provides a primitive of type BOOLEAN wrapping the given boolean value
    • of

      @Contract("_ -> new") @NotNull static @NotNull TomlPrimitive of(long value)
      Creates a primitive of type INTEGER wrapping the given long value
    • of

      @Contract("_ -> new") @NotNull static @NotNull TomlPrimitive of(int value)
      Creates a primitive of type INTEGER wrapping the given integer value after a widening conversion to Long
    • of

      @NotNull static @NotNull TomlPrimitive of(double value)
      Creates a primitive of type FLOAT wrapping the given double value
    • of

      @NotNull static @NotNull TomlPrimitive of(float value)
      Creates a primitive of type FLOAT wrapping the given float value after a widening conversion to Double
    • of

      @Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(OffsetDateTime value) throws TomlValueException
      Creates a primitive of type OFFSET_DATE_TIME wrapping the given OffsetDateTime
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
    • of

      @Contract("null, _ -> fail; !null, _ -> new") @NotNull static @NotNull TomlPrimitive of(LocalDateTime value, @Nullable @Nullable ZoneOffset offset) throws TomlValueException
      Creates a primitive of type LOCAL_DATE_TIME wrapping the given LocalDateTime
      Parameters:
      offset - Offset to use when coercing this value to an OffsetDateTime. If null, ZoneOffset.UTC is used. This does not change the value of the resulting primitive.
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
    • of

      @Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(LocalDateTime value) throws TomlValueException
      Creates a primitive of type LOCAL_DATE_TIME wrapping the given LocalDateTime
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
      See Also:
    • of

      @Contract("null, _ -> fail; !null, _ -> new") @NotNull static @NotNull TomlPrimitive of(LocalDate value, @Nullable @Nullable ZoneOffset offset) throws TomlValueException
      Creates a primitive of type LOCAL_DATE wrapping the given LocalDate
      Parameters:
      offset - Offset to use when coercing this value to an OffsetDateTime. If null, ZoneOffset.UTC is used. This does not change the value of the resulting primitive.
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
    • of

      @Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(LocalDate value) throws TomlValueException
      Creates a primitive of type LOCAL_DATE wrapping the given LocalDate
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
      See Also:
    • of

      @Contract("null, _ -> fail; !null, _ -> new") @NotNull static @NotNull TomlPrimitive of(LocalTime value, @Nullable @Nullable ZoneOffset offset)
      Creates a primitive of type LOCAL_TIME wrapping the given LocalTime
      Parameters:
      offset - Offset to use when coercing this value to an OffsetDateTime. If null, ZoneOffset.UTC is used. This does not change the value of the resulting primitive.
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
    • of

      @Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(LocalTime value)
      Creates a primitive of type LOCAL_TIME wrapping the given LocalTime
      Throws:
      NullPointerException - Value is null
      TomlValueException - Provided date has a year outside the range 0 to 9999
      See Also:
    • copyOf

      @Contract("_ -> new") @AvailableSince("0.6.4") @NotNull static @NotNull TomlPrimitive copyOf(@NotNull @NotNull TomlPrimitive other)
      Creates a new TomlPrimitive with the same value and comments as the provided primitive
    • parseFloat

      @AvailableSince("1.3.0") @Contract("null -> fail; _ -> new") @NotNull static @NotNull TomlPrimitive parseFloat(@Pattern("^([-+]?(?:inf|nan))|([-+]?)([1-9]\\d*)(?:\\.(\\d+))?(?:e([-+]?\\d+))?$") String string) throws IllegalArgumentException
      Parses a float string into a TomlPrimitive with type FLOAT. The format accepted by this method is that which is defined by the TOML language specification.
      Throws:
      NullPointerException - Provided string is null
      IllegalArgumentException - Provided string is not a valid float
    • type

      @NotNull @NotNull TomlPrimitiveType type()
      The actual type of this primitive
      See Also:
    • value

      @NotNull @NotNull Serializable value()
      The (boxed) value of this primitive. Will be one of String, Boolean, Long, Double, OffsetDateTime, LocalDateTime, LocalDate or LocalTime.
      See Also:
    • isString

      default boolean isString()
      Checks if the type of this primitive is equal to TomlPrimitiveType.STRING, meaning that the output of asString() is identical to the value of this primitive.
    • asString

      @NotNull @NotNull String asString()
      Coerces the value of this primitive to a string.
    • isBoolean

      default boolean isBoolean()
      Checks if the type of this primitive is equal to TomlPrimitiveType.BOOLEAN, meaning that the output of asBoolean() is equal to the value of this primitive.
    • asBoolean

      boolean asBoolean()

      Coerces the value of this primitive to a boolean.

      • Boolean primitives will return their stored value
      • String primitives equal to "false" will return false, otherwise true
      • Date-Time primitives will return true
      • Integer and Float primitives that are arithmetically equal to 0 will return false, otherwise true
    • isInteger

      default boolean isInteger()
      Checks if the type of this primitive is equal to TomlPrimitiveType.INTEGER, meaning that the output of asLong() is equal to the value of this primitive.
    • asInteger

      default int asInteger() throws ArithmeticException
      Coerces the value of this primitive to an integer.
      • Integer primitives will return their stored value
      • String primitives will attempt to parse their value as a long, throwing NumberFormatException if not possible
      • Date-Time primitives will return their value after coercion to OffsetDateTime as epoch millis
      • Boolean primitives will return 1 if true and 0 if false
      Throws:
      ArithmeticException - The intrinsic or coerced value of this primitive (as a long) cannot be losslessly converted to an integer
      See Also:
    • asLong

      long asLong()
      Coerces the value of this primitive to a long.
      • Integer primitives will return their stored value
      • String primitives will attempt to parse their value as a long, throwing NumberFormatException if not possible
      • Date-Time primitives will return their value after coercion to OffsetDateTime as epoch millis
      • Boolean primitives will return 1 if true and 0 if false
      See Also:
    • isFloat

      default boolean isFloat()
      Checks if the type of this primitive is equal to TomlPrimitiveType.FLOAT, meaning that the output of asDouble() is equal to the value of this primitive.
    • asFloat

      default float asFloat()
      Coerces the value of this primitive to a float. Output is identical to that of asDouble() after narrowing conversion to float.
      See Also:
    • asDouble

      double asDouble()
      Coerces the value of this primitive to a double. If this is a float primitive, returns the stored value. Otherwise, returns the closest double value to that of asLong().
      See Also:
    • isOffsetDateTime

      default boolean isOffsetDateTime()
      Checks if the type of this primitive is equal to TomlPrimitiveType.OFFSET_DATE_TIME, meaning that the output of asOffsetDateTime() is identical to the value of this primitive.
    • asInstant

      @NotNull default @NotNull Instant asInstant()
      Returns a Instant that represents the same moment in time as the output of asOffsetDateTime().
    • asDate

      @NotNull default @NotNull Date asDate()
      Returns a Date that represents the same moment in time as the output of asOffsetDateTime().
    • asOffsetDateTime

      @NotNull default @NotNull OffsetDateTime asOffsetDateTime()
      Coerces the value of this primitive to an OffsetDateTime.
      • For Offset Date-Time primitives, returns the stored value
      • For Local Date-Time primitives, pairs the stored value with the configured offset
      • For Local Date primitives, evaluates the stored date at the 0th hour and configured offset
      • For Local Time primitives, evaluates the stored time at the 0th date and configured offset
      • For Integer primitives, interprets the stored value as epoch millis
      • For all other values, throws UnsupportedOperationException
    • isLocalDateTime

      default boolean isLocalDateTime()
      Checks if the type of this primitive is equal to TomlPrimitiveType.LOCAL_DATE_TIME, meaning that the output of asLocalDateTime() is identical to the value of this primitive.
    • asLocalDateTime

      @NotNull default @NotNull LocalDateTime asLocalDateTime()
      Coerces the value of this primitive to a LocalDateTime.
      • For Offset Date-Time primitives, returns the stored value after discarding the offset
      • For Local Date-Time primitives, returns the stored value
      • For Local Date primitives, evaluates the stored date at the 0th hour
      • For Local Time primitives, evaluates the stored time at the 0th date
      • For Integer primitives, interprets the stored value as epoch millis
      • For all other values, throws UnsupportedOperationException
    • isLocalDate

      default boolean isLocalDate()
      Checks if the type of this primitive is equal to TomlPrimitiveType.LOCAL_DATE, meaning that the output of asLocalDate() is identical to the value of this primitive.
    • asLocalDate

      @NotNull default @NotNull LocalDate asLocalDate()
      Coerces the value of this primitive to a LocalDate.
      • For Offset Date-Time primitives, returns the stored value after discarding the time and offset
      • For Local Date-Time primitives, returns the stored value after discarding the time
      • For Local Date primitives, returns the stored date
      • For Local Time primitives, returns the 0th date
      • For all other values, throws UnsupportedOperationException
    • isLocalTime

      default boolean isLocalTime()
      Checks if the type of this primitive is equal to TomlPrimitiveType.LOCAL_TIME, meaning that the output of asLocalTime() is identical to the value of this primitive.
    • asLocalTime

      @NotNull default @NotNull LocalTime asLocalTime()
      Coerces the value of this primitive to a LocalTime.
      • For Offset Date-Time primitives, returns the stored value after discarding the date and offset
      • For Local Date-Time primitives, returns the stored value after discarding the date
      • For Local Date primitives, returns the 0th hour
      • For Local Time primitives, returns the stored value
      • For all other values, throws UnsupportedOperationException