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(Object data, boolean immutable)
      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 to true 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 stored
      immutable - whether immutable
    • DataObject

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

      public DataObject(Map<String,Object> data, boolean immutable)
      Constructs a data object, which holds the specified map data.

      The immutable tag if set to true 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 stored
      immutable - whether immutable
  • Method Details

    • builder

      public static DataObjectBuilder builder()
      Creates a new DataObjectBuilder.
      Returns:
      new builder
    • isEmpty

      public boolean isEmpty()
      Returns whether this data object is empty.
      Returns:
      boolean value
    • isSingleValue

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

      public boolean isImmutable()
      Returns whether this data object is immutable/unmodifiable.
      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
    • getAs

      public <T> T getAs(Class<T> type)
      Returns the held value by this data object as the specified type, 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

      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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object