Interface TomlPrimitive
- All Superinterfaces:
TomlValue
Represents a TOML primitive (not a table or array)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanCoerces thevalueof this primitive to a boolean.default @NotNull DateasDate()Returns aDatethat represents the same moment in time as the output ofasOffsetDateTime().doubleasDouble()Coerces thevalueof this primitive to a double.default floatasFloat()Coerces thevalueof this primitive to a float.default @NotNull InstantReturns aInstantthat represents the same moment in time as the output ofasOffsetDateTime().default intCoerces thevalueof this primitive to an integer.default @NotNull LocalDatedefault @NotNull LocalDateTimeCoerces thevalueof this primitive to aLocalDateTime.default @NotNull LocalTimelongasLong()Coerces thevalueof this primitive to a long.default @NotNull OffsetDateTimeCoerces thevalueof this primitive to anOffsetDateTime.@NotNull StringasString()Coerces thevalueof this primitive to a string.static @NotNull TomlPrimitivecopyOf(@NotNull TomlPrimitive other) Creates a new TomlPrimitive with the same value and comments as the provided primitivedefault booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.BOOLEAN, meaning that the output ofasBoolean()is equal to thevalueof this primitive.default booleanisFloat()Checks if thetypeof this primitive is equal toTomlPrimitiveType.FLOAT, meaning that the output ofasDouble()is equal to thevalueof this primitive.default booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.INTEGER, meaning that the output ofasLong()is equal to thevalueof this primitive.default booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_DATE, meaning that the output ofasLocalDate()is identical to thevalueof this primitive.default booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_DATE_TIME, meaning that the output ofasLocalDateTime()is identical to thevalueof this primitive.default booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_TIME, meaning that the output ofasLocalTime()is identical to thevalueof this primitive.default booleanChecks if thetypeof this primitive is equal toTomlPrimitiveType.OFFSET_DATE_TIME, meaning that the output ofasOffsetDateTime()is identical to thevalueof this primitive.default booleanisString()Checks if thetypeof this primitive is equal toTomlPrimitiveType.STRING, meaning that the output ofasString()is identical to thevalueof this primitive.static @NotNull TomlPrimitiveof(boolean value) Provides a primitive of typeBOOLEANwrapping the given boolean valuestatic @NotNull TomlPrimitiveof(double value) Creates a primitive of typeFLOATwrapping the given double valuestatic @NotNull TomlPrimitiveof(float value) static @NotNull TomlPrimitiveof(int value) static @NotNull TomlPrimitiveof(long value) Creates a primitive of typeINTEGERwrapping the given long valuestatic @NotNull TomlPrimitiveCreates a primitive of typeSTRINGwrapping the given string valuestatic @NotNull TomlPrimitiveCreates a primitive of typeLOCAL_DATEwrapping the givenLocalDatestatic @NotNull TomlPrimitiveof(LocalDate value, @Nullable ZoneOffset offset) Creates a primitive of typeLOCAL_DATEwrapping the givenLocalDatestatic @NotNull TomlPrimitiveof(LocalDateTime value) Creates a primitive of typeLOCAL_DATE_TIMEwrapping the givenLocalDateTimestatic @NotNull TomlPrimitiveof(LocalDateTime value, @Nullable ZoneOffset offset) Creates a primitive of typeLOCAL_DATE_TIMEwrapping the givenLocalDateTimestatic @NotNull TomlPrimitiveCreates a primitive of typeLOCAL_TIMEwrapping the givenLocalTimestatic @NotNull TomlPrimitiveof(LocalTime value, @Nullable ZoneOffset offset) Creates a primitive of typeLOCAL_TIMEwrapping the givenLocalTimestatic @NotNull TomlPrimitiveof(OffsetDateTime value) Creates a primitive of typeOFFSET_DATE_TIMEwrapping the givenOffsetDateTimestatic @NotNull TomlPrimitiveparseFloat(String string) Parses a float string into aTomlPrimitivewith typeFLOAT.@NotNull TomlPrimitiveTypetype()The actual type of this primitive@NotNull Serializablevalue()The (boxed) value of this primitive.Methods inherited from interface io.github.wasabithumb.jtoml.value.TomlValue
asArray, asPrimitive, asTable, comments, creationTime, flags, flags, isArray, isPrimitive, isTable
-
Method Details
-
of
Creates a primitive of typeSTRINGwrapping the given string value- Throws:
NullPointerException- Value is null
-
of
Provides a primitive of typeBOOLEANwrapping the given boolean value -
of
Creates a primitive of typeINTEGERwrapping the given long value -
of
-
of
Creates a primitive of typeFLOATwrapping the given double value -
of
-
of
@Contract("null -> fail; !null -> new") @NotNull static @NotNull TomlPrimitive of(OffsetDateTime value) throws TomlValueException Creates a primitive of typeOFFSET_DATE_TIMEwrapping the givenOffsetDateTime- Throws:
NullPointerException- Value is nullTomlValueException- 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 typeLOCAL_DATE_TIMEwrapping the givenLocalDateTime- Parameters:
offset- Offset to use when coercing this value to anOffsetDateTime. If null,ZoneOffset.UTCis used. This does not change the value of the resulting primitive.- Throws:
NullPointerException- Value is nullTomlValueException- 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 typeLOCAL_DATE_TIMEwrapping the givenLocalDateTime- Throws:
NullPointerException- Value is nullTomlValueException- 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 typeLOCAL_DATEwrapping the givenLocalDate- Parameters:
offset- Offset to use when coercing this value to anOffsetDateTime. If null,ZoneOffset.UTCis used. This does not change the value of the resulting primitive.- Throws:
NullPointerException- Value is nullTomlValueException- 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 typeLOCAL_DATEwrapping the givenLocalDate- Throws:
NullPointerException- Value is nullTomlValueException- 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 typeLOCAL_TIMEwrapping the givenLocalTime- Parameters:
offset- Offset to use when coercing this value to anOffsetDateTime. If null,ZoneOffset.UTCis used. This does not change the value of the resulting primitive.- Throws:
NullPointerException- Value is nullTomlValueException- Provided date has a year outside the range 0 to 9999
-
of
Creates a primitive of typeLOCAL_TIMEwrapping the givenLocalTime- Throws:
NullPointerException- Value is nullTomlValueException- 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 aTomlPrimitivewith typeFLOAT. The format accepted by this method is that which is defined by the TOML language specification.- Throws:
NullPointerException- Provided string is nullIllegalArgumentException- Provided string is not a valid float
-
type
The actual type of this primitive- See Also:
-
value
The (boxed) value of this primitive. Will be one ofString,Boolean,Long,Double,OffsetDateTime,LocalDateTime,LocalDateorLocalTime.- See Also:
-
isString
default boolean isString()Checks if thetypeof this primitive is equal toTomlPrimitiveType.STRING, meaning that the output ofasString()is identical to thevalueof this primitive. -
asString
Coerces thevalueof this primitive to a string. -
isBoolean
default boolean isBoolean()Checks if thetypeof this primitive is equal toTomlPrimitiveType.BOOLEAN, meaning that the output ofasBoolean()is equal to thevalueof this primitive. -
asBoolean
boolean asBoolean()Coerces the
valueof 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 thetypeof this primitive is equal toTomlPrimitiveType.INTEGER, meaning that the output ofasLong()is equal to thevalueof this primitive. -
asInteger
Coerces thevalueof this primitive to an integer.- Integer primitives will return their stored value
-
String primitives will attempt to parse their value as a
long, throwing
NumberFormatExceptionif not possible -
Date-Time primitives will return their value after coercion to
OffsetDateTimeas 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 thevalueof this primitive to a long.- Integer primitives will return their stored value
-
String primitives will attempt to parse their value as a
long, throwing
NumberFormatExceptionif not possible -
Date-Time primitives will return their value after coercion to
OffsetDateTimeas epoch millis - Boolean primitives will return 1 if true and 0 if false
- See Also:
-
isFloat
default boolean isFloat()Checks if thetypeof this primitive is equal toTomlPrimitiveType.FLOAT, meaning that the output ofasDouble()is equal to thevalueof this primitive. -
asFloat
default float asFloat()Coerces thevalueof this primitive to a float. Output is identical to that ofasDouble()after narrowing conversion tofloat.- See Also:
-
asDouble
double asDouble()Coerces thevalueof this primitive to a double. If this is a float primitive, returns the stored value. Otherwise, returns the closest double value to that ofasLong().- See Also:
-
isOffsetDateTime
default boolean isOffsetDateTime()Checks if thetypeof this primitive is equal toTomlPrimitiveType.OFFSET_DATE_TIME, meaning that the output ofasOffsetDateTime()is identical to thevalueof this primitive. -
asInstant
Returns aInstantthat represents the same moment in time as the output ofasOffsetDateTime(). -
asDate
Returns aDatethat represents the same moment in time as the output ofasOffsetDateTime(). -
asOffsetDateTime
Coerces thevalueof this primitive to anOffsetDateTime.- 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 thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_DATE_TIME, meaning that the output ofasLocalDateTime()is identical to thevalueof this primitive. -
asLocalDateTime
Coerces thevalueof this primitive to aLocalDateTime.- 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 thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_DATE, meaning that the output ofasLocalDate()is identical to thevalueof this primitive. -
asLocalDate
Coerces thevalueof this primitive to aLocalDate.- 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 thetypeof this primitive is equal toTomlPrimitiveType.LOCAL_TIME, meaning that the output ofasLocalTime()is identical to thevalueof this primitive. -
asLocalTime
Coerces thevalueof this primitive to aLocalTime.- 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
-