java.lang.Object
net.luis.utils.io.data.json.JsonPrimitive
- All Implemented Interfaces:
JsonElement
,ValueGetter
Represents a json primitive value.
A primitive value can be a boolean, number or string.
A primitive value can be a boolean, number or string.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJsonPrimitive
(boolean value) Constructs a new json primitive with the given boolean value.JsonPrimitive
(@NotNull Number value) Constructs a new json primitive with the given number value.JsonPrimitive
(@NotNull String value) Constructs a new json primitive with the given string value. -
Method Summary
Modifier and TypeMethodDescriptionboolean
@NotNull String
Returns the value which is hold by this object as a string.int
hashCode()
toString()
@NotNull String
toString
(@Nullable JsonConfig config) Returns a string representation of this json element based on the given json config.
The json config specifies how the json element should be formatted.private static @NotNull Object
Tries to parse the given string to a boolean or number.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.luis.utils.io.data.json.JsonElement
getAsJsonArray, getAsJsonObject, getAsJsonPrimitive, isJsonArray, isJsonNull, isJsonObject, isJsonPrimitive
Methods inherited from interface net.luis.utils.util.getter.ValueGetter
getAs, getAsBoolean, getAsByte, getAsDouble, getAsFloat, getAsInteger, getAsLong, getAsNumber, getAsShort
-
Field Details
-
value
The value of this json primitive.
-
-
Constructor Details
-
JsonPrimitive
public JsonPrimitive(boolean value) Constructs a new json primitive with the given boolean value.- Parameters:
value
- The boolean value
-
JsonPrimitive
Constructs a new json primitive with the given number value.- Parameters:
value
- The number value- Throws:
NullPointerException
- If the value is null
-
JsonPrimitive
Constructs a new json primitive with the given string value.- Parameters:
value
- The string value- Throws:
NullPointerException
- If the value is null
-
-
Method Details
-
tryParse
Tries to parse the given string to a boolean or number.- Parameters:
string
- The string- Returns:
- The parsed value or the string if it could not be parsed
-
getAsString
Description copied from interface:ValueGetter
Returns the value which is hold by this object as a string.- Specified by:
getAsString
in interfaceValueGetter
- Returns:
- The value as a string
-
equals
-
hashCode
public int hashCode() -
toString
-
toString
Description copied from interface:JsonElement
Returns a string representation of this json element based on the given json config.
The json config specifies how the json element should be formatted.- Specified by:
toString
in interfaceJsonElement
- Parameters:
config
- The json config to use- Returns:
- The string representation of this json element
-