java.lang.Object
com.mrivanplays.annotationconfig.core.serialization.DataObject

public final class DataObject extends Object
A class, which stores read from config values or serialized values in a developer friendly way.
Since:
2.0.0
Author:
MrIvanPlays
  • Constructor Details

    • DataObject

      public DataObject()
      Constructs a empty data object
    • DataObject

      public DataObject(Object data)
      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

      public DataObject(Map<String,Object> data)
      Constructs a data object, which holds the specified map data.
      Parameters:
      data - the data which is stored
  • Method Details

    • isSingleValue

      public boolean isSingleValue()
      Returns whether this data object holds a single value and not a map.
      Returns:
      boolean value
    • has

      public boolean has(String key)
      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

      public DataObject get(String key)
      Returns the DataObject 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

      public void put(String key, String value)
      Binds the specified value to the specified key
      Parameters:
      key - the key you want the value to be bound to
      value - the value you want bound
    • put

      public void put(String key, boolean value)
      Binds the specified value to the specified key
      Parameters:
      key - the key you want the value to be bound to
      value - the value you want bound
    • put

      public void put(String key, Number value)
      Binds the specified value to the specified key
      Parameters:
      key - the key you want the value to be bound to
      value - the value you want bound
    • remove

      public DataObject remove(String key)
      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

      public void putAll(String key, DataObject object)
      Binds the specified DataObject to the specified key.
      Parameters:
      key - the key you want the value to be bound to
      object - the value you want bound
    • getAsMap

      Returns this data object as a Map with key type of String and a value type of Object. Modifying the returned map won't have any impact on this data object.
      Returns:
      data as base serialization map
    • getAsObject

      public Object getAsObject()
      Returns the held value by this data object. If it holds a map, the returned value is null.
      Returns:
      held object
    • getAsString

      public String getAsString()
      Returns the held value by this data object as a String
      Returns:
      held string
      See Also:
    • getAsInt

      public int getAsInt()
      Returns the held value by this data object as a Integer
      Returns:
      held int
      See Also:
    • getAsBoolean

      public boolean getAsBoolean()
      Returns the held value by this data object as a Boolean
      Returns:
      held boolean
      See Also:
    • getAsByte

      public byte getAsByte()
      Returns the held value by this data object as a Byte
      Returns:
      held byte
      See Also:
    • getAsChar

      public char getAsChar()
      Returns the held value by this data object as a Character
      Returns:
      held char
      See Also:
    • getAsDouble

      public double getAsDouble()
      Returns the held value by this data object as a Double
      Returns:
      held double
      See Also:
    • getAsFloat

      public float getAsFloat()
      Returns the held value by this data object as a Float
      Returns:
      held float
      See Also:
    • getAsLong

      public long getAsLong()
      Returns the held value by this data object as a Long
      Returns:
      held long
      See Also:
    • getAsShort

      public short getAsShort()
      Returns the held value by this data object as a Short
      Returns:
      held short
      See Also:
    • getAsList

      public List<Object> getAsList()
      Returns the held value by this data object as a List of Object . If the held value isn't a list, this method will return null.
      Returns:
      list or null
    • getList

      public <T> List<T> getList(Class<T> valueClass)
      Returns the held value by this data object as a List 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