Class DataObject
java.lang.Object
com.mrivanplays.annotationconfig.core.serialization.DataObject
A class, which stores read from config values or serialized values in a developer friendly way.
- Since:
- 2.0.0
- Author:
- MrIvanPlays
-
Constructor Summary
ConstructorDescriptionConstructs a empty data objectDataObject
(Object data) Constructs a data object, which holds the specified data.DataObject
(Object data, boolean immutable) Constructs a data object, which holds the specified data.DataObject
(Map<String, Object> data) Constructs a data object, which holds the specified map data.DataObject
(Map<String, Object> data, boolean immutable) Constructs a data object, which holds the specified map data. -
Method Summary
Modifier and TypeMethodDescriptionstatic DataObjectBuilder
builder()
Creates a newDataObjectBuilder
.boolean
Returns theDataObject
value held by the specified key.<T> T
Returns the held value by this data object as the specifiedtype
, if the held data is of that type.Returns the held value by this data object as aBigDecimal
Returns the held value by this data object as aBigInteger
boolean
Returns the held value by this data object as aBoolean
byte
Returns the held value by this data object as aByte
char
Returns the held value by this data object as aCharacter
double
Returns the held value by this data object as aDouble
float
Returns the held value by this data object as aFloat
int
getAsInt()
Returns the held value by this data object as aInteger
long
Returns the held value by this data object as aLong
getAsMap()
Returns the held value by this data object.getAsObject
(boolean serializeBigIntegerAndBigDecimal) Returns the held value by this data objects.short
Returns the held value by this data object as aShort
Returns the held value by this data object as aString
<T> List<T>
Returns the held value by this data object as aList
of the specified class type.boolean
Returns whether the specified key has a value in this data object.int
hashCode()
boolean
isEmpty()
Returns whether this data object is empty.boolean
Returns whether this data object is immutable/unmodifiable.boolean
Returns whether this data object holds a single value and not a map.void
Binds the specified value to the specified keyvoid
Binds the specified value to the specified keyvoid
Binds the specified value to the specified keyvoid
putAll
(String key, DataObject object) Binds the specifiedDataObject
to the specified key.Removes the value of the specified key.toString()
-
Constructor Details
-
DataObject
public DataObject()Constructs a empty data object -
DataObject
Constructs a data object, which holds the specified data. If the data is of map type, it gets converted, so it's values are accessible- Parameters:
data
- the data which is stored
-
DataObject
Constructs a data object, which holds the specified data. If the data is of map type, it gets converted, so it's values are accessible.The
immutable
tag if set totrue
will make the data held in the created data object and in the created data object delegates immutable/unmodifiable.- Parameters:
data
- the data which is storedimmutable
- whether immutable
-
DataObject
Constructs a data object, which holds the specified map data.- Parameters:
data
- the data which is stored
-
DataObject
Constructs a data object, which holds the specified map data.The
immutable
tag if set totrue
will make the data held in the created data object and in the created data object delegates immutable/unmodifiable.- Parameters:
data
- the data which is storedimmutable
- whether immutable
-
-
Method Details
-
builder
Creates a newDataObjectBuilder
.- Returns:
- new builder
-
isEmpty
Returns whether this data object is empty.- Returns:
- boolean value
-
isSingleValue
Returns whether this data object holds a single value and not a map.- Returns:
- boolean value
-
isImmutable
Returns whether this data object is immutable/unmodifiable.- Returns:
- boolean value
-
has
Returns whether the specified key has a value in this data object.- Parameters:
key
- the key you want to check for a value- Returns:
- boolean value
-
get
Returns theDataObject
value held by the specified key. If there isn't a value,null
is returned.- Parameters:
key
- the key for which you want the data- Returns:
- data object or null
-
put
Binds the specified value to the specified key- Parameters:
key
- the key you want the value to be bound tovalue
- the value you want bound
-
put
Binds the specified value to the specified key- Parameters:
key
- the key you want the value to be bound tovalue
- the value you want bound
-
put
Binds the specified value to the specified key- Parameters:
key
- the key you want the value to be bound tovalue
- the value you want bound
-
remove
Removes the value of the specified key.- Parameters:
key
- the key you want the value of removed- Returns:
- the value removed or null if no value was present
-
putAll
Binds the specifiedDataObject
to the specified key.- Parameters:
key
- the key you want the value to be bound toobject
- the value you want bound
-
getAsMap
Returns this data object as aMap
with key type ofString
and a value type ofObject
. Modifying the returned map won't have any impact on this data object.- Returns:
- data as base serialization map
-
getAsObject
Returns the held value by this data object. If it holds a map, the returned value is null.- Returns:
- held object
-
getAsObject
Returns the held value by this data objects. If it holds a map, the returned value is null.- Parameters:
serializeBigIntegerAndBigDecimal
- whether to serialize the value to a primitive if it is aBigInteger
orBigDecimal
- Returns:
- held object
-
getAs
Returns the held value by this data object as the specifiedtype
, if the held data is of that type. If it holds a map, the returned value is null.- Type Parameters:
T
- generic- Parameters:
type
- the type to transform to- Returns:
- transformed type or null if data is null
- Throws:
IllegalArgumentException
- if the held data's type is not the specified type
-
getAsString
Returns the held value by this data object as aString
- Returns:
- held string
- See Also:
-
getAsInt
Returns the held value by this data object as aInteger
- Returns:
- held int
- See Also:
-
getAsBoolean
Returns the held value by this data object as aBoolean
- Returns:
- held boolean
- See Also:
-
getAsByte
Returns the held value by this data object as aByte
- Returns:
- held byte
- See Also:
-
getAsChar
Returns the held value by this data object as aCharacter
- Returns:
- held char
- See Also:
-
getAsDouble
Returns the held value by this data object as aDouble
- Returns:
- held double
- See Also:
-
getAsFloat
Returns the held value by this data object as aFloat
- Returns:
- held float
- See Also:
-
getAsLong
Returns the held value by this data object as aLong
- Returns:
- held long
- See Also:
-
getAsShort
Returns the held value by this data object as aShort
- Returns:
- held short
- See Also:
-
getAsBigDecimal
Returns the held value by this data object as aBigDecimal
- Returns:
- held big decimal
- See Also:
-
getAsBigInteger
Returns the held value by this data object as aBigInteger
- Returns:
- held big integer
- See Also:
-
getAsList
Returns the held value by this data object as aList
ofObject
. If the held value isn't a list, this method will return null.- Returns:
- list or null
-
getList
Returns the held value by this data object as aList
of the specified class type. If the held value isn't a list, this method will return null. Any values which aren't assignable to the specified value class are skipped.- Type Parameters:
T
- type needed- Parameters:
valueClass
- the value class you want the list entries to be cast to- Returns:
- list or null
-
toString
-
equals
-
hashCode
-