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
(Map<String, Object> data) Constructs a data object, which holds the specified map data. -
Method Summary
Modifier and TypeMethodDescriptionReturns theDataObject
value held by the specified key.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.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.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.
-
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 map data.- Parameters:
data
- the data which is stored
-
-
Method Details
-
isSingleValue
Returns whether this data object holds a single value and not a map.- 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
-
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:
-
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
-