Interface AbstractData<K,V>

Type Parameters:
K - key
V - value
All Superinterfaces:
Datable, Iterable<Entry<K,V>>
All Known Subinterfaces:
ContentOnlyData<K,V>, DataWrapper<K,V>, SAOData<O>, SAODataWrapper<O>, SOData, SODataWrapper
All Known Implementing Classes:
SAOContentOnlyDataListImpl, SAODataListImpl, SAODataMapImpl, SAODataWrapperImpl, SODataListImpl, SODataMapImpl, SODataWrapperImpl

public interface AbstractData<K,V> extends Iterable<Entry<K,V>>, Datable
A AbstractData can store key-value pairs.

These can be parsed to a json-string using JsonParser.
  • Field Details

  • Method Details

    • add

      boolean add(@NotNull K key, @Nullable V value)
      Adds a new Entry.

      This method might not check, if a Entry with given key already exits. Depending on the implementation, this might even override existing mappings (for Example SODataMapImpl).

      Parameters:
      key - key
      value - value
      Returns:
      true if a new Entry was added, false otherwise
    • addIfNotNull

      default boolean addIfNotNull(@NotNull K key, @Nullable V value)
      Adds a new Entry if given value is not null.

      This method might not check, if a Entry with given key already exits. Depending on the implementation, this might even override existing mappings (for Example SODataMapImpl).

      Parameters:
      key - key
      value - value
      Returns:
      true if a new Entry was added, false otherwise
    • addIfOptionalExists

      default boolean addIfOptionalExists(@NotNull K key, @NotNull @NotNull OptionalValue<? extends V> optionalValue)
      Adds a new Entry with given key and OptionalValue.get() if given optionalValue exists.

      This method might not check, if a Entry with given key already exits. Depending on the implementation, this might even override existing mappings (for Example SODataMapImpl).

      Parameters:
      key - AbstractData key
      optionalValue - OptionalValue
      Returns:
      true if a new Entry was added, false otherwise
    • addOrReplace

      default V addOrReplace(@NotNull K key, @Nullable V value)
      If no Entry for given key exists, a new Entry is added.
      If an Entry with given key exists, it's value is changed to given value.
      Parameters:
      key - key
      value - value
      Returns:
      Old mapping for given key or null if there was no old mapping for given key.
    • addEntry

      void addEntry(@NotNull @NotNull Entry<K,V> entry)
      Adds a new Entry.

      This method might not check, if a Entry with given key already exits (depending on the implementation)

      Parameters:
      entry - entry to add
    • remove

      @Nullable @Nullable Entry<K,V> remove(@NotNull K key)

      Removes Entry with given key. If no such entry exists nothing happens.

      Parameters:
      key - key for the entry to remove
      Returns:
      the removed Entry or null if no entry was removed.
    • getEntry

      @Nullable @Nullable Entry<K,V> getEntry(@NotNull K key)
      Parameters:
      key - key
      Returns:
      Entry with given key or null, if no such Entry exists.
    • getOptionalValue

      @NotNull default <C> @NotNull OptionalValue<C> getOptionalValue(@NotNull K key)
      Type Parameters:
      C - type tp cast to
      Parameters:
      key - key
      Returns:
      OptionalValue
      Throws:
      ClassCastException - if the value for given key is not of type AbstractData.
    • getOptionalValueAndConvert

      @NotNull default <C, R> @NotNull OptionalValue<R> getOptionalValueAndConvert(@NotNull K key, @NotNull @NotNull Converter<C,R> converter)
      Type Parameters:
      C - type tp cast to
      R - type your converter converts to
      Parameters:
      key - key
      converter - Converter to convert from AbstractData to AbstractData.
      Returns:
      OptionalValue
      Throws:
      ClassCastException - if the value for given key is not of type AbstractData.
    • getOptionalValueAndConvertWithException

      @NotNull default <C, R, E extends Exception> @NotNull OptionalValue<R> getOptionalValueAndConvertWithException(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter) throws E
      Type Parameters:
      C - type tp cast to
      R - type your converter converts to
      E - Exception your converter may throw
      Parameters:
      key - key
      converter - Converter to convert from AbstractData to AbstractData.
      Returns:
      OptionalValue
      Throws:
      E - by your converter
      ClassCastException - if the value for given key is not of type AbstractData.
    • getContainer

      @NotNull default @NotNull Container<K,V,V> getContainer(@NotNull K key)
    • get

      @Nullable default V get(@NotNull K key, @Nullable V defaultObject, @Nullable V defaultObjectIfNull)
      Gets value for given key or
      • defaultObject, if no Entry for given key exists
      • defaultObjectIfNull, if value for given key is null
      Parameters:
      key - key
      defaultObject - AbstractData default object to return, if no Entry for given key exists.
      defaultObjectIfNull - AbstractData default object to return, if value for given key is null.
      Returns:
      value for given key or a default value as specified above.
    • getOrDefault

      @Contract("_, !null, !null -> !null") @Nullable default V getOrDefault(@NotNull K key, @Nullable V defaultObject, @Nullable V defaultObjectIfNull)
      See Also:
    • getOrDefaultBoth

      @Contract("_, !null -> !null") @Nullable default V getOrDefaultBoth(@NotNull K key, @Nullable V defaultObject)
      Parameters:
      key - key
      defaultObject - AbstractData default object to return, if no Entry for given key exists or value is null
      Returns:
      value for given key or defaultObject if no Entry for given key exists or value is null.
      See Also:
    • get

      @Nullable default V get(@NotNull K key, @Nullable V defaultObject)
      Parameters:
      key - key
      defaultObject - AbstractData default object to return, if no Entry for given key exists.
      Returns:
      value for given key or a defaultObject if no Entry with given key exists.
    • getOrDefault

      @Nullable default V getOrDefault(@NotNull K key, @Nullable V defaultObject)
      See Also:
    • get

      @Nullable default V get(@NotNull K key)
      Parameters:
      key - key
      Returns:
      value or null if no Entry for given key exists.
    • getAs

      @Contract("_, !null, !null -> !null") @Nullable default <C extends V> C getAs(@NotNull K key, @Nullable C defaultObject, @Nullable C defaultObjectIfNull)
      Type Parameters:
      C - class to which the value of the entry should be cast to
      Parameters:
      key - key
      defaultObject - default object to return if no entry with given key exists
      defaultObjectIfNull - default object to return if the value of the entry with given key is null
      Returns:
      value (cast to AbstractData) of entry with given key or null if the value of given key is null or given defaultObject is null and there is no entry for given key.
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
    • getAs

      @Nullable default <C extends V> C getAs(@NotNull K key, @Nullable C defaultObject)
      Type Parameters:
      C - class to which the value of the entry should be cast to
      Parameters:
      key - key
      defaultObject - default object to return if no entry with given key exists
      Returns:
      value (cast to AbstractData) of entry with given key or null if the value of given key is null or given defaultObject is null and there is no entry for given key.
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
    • getAs

      @Nullable default <C extends V> C getAs(@NotNull K key)
      Type Parameters:
      C - class to which the value of the entry should be cast to
      Parameters:
      key - key
      Returns:
      value (cast to AbstractData) of entry with given key or null if the value of the entry is null or if no such entry exits
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
      See Also:
    • getAndConvert

      default <C extends V, R> R getAndConvert(@NotNull K key, @NotNull @NotNull Converter<C,R> converter)
      The value returned by get(Object) with given key must be of type AbstractData or null.
      If the value returned by get(Object) with given key is null, Converter.convert(Object) with null is called!
      Type Parameters:
      C - the convertible type
      R - the result type
      Parameters:
      key - the key for the entry of type AbstractData
      converter - Converter to convert from AbstractData to AbstractData
      Returns:
      result AbstractData or null if your functions returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData
    • getAndConvert

      @Nullable @Contract("_, _, !null -> !null") default <C extends V, R> R getAndConvert(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @Nullable R defaultObject)
      The value returned by get(Object) with given key must be of type AbstractData or null.
      Type Parameters:
      C - the convertible type
      R - the result type
      Parameters:
      key - the key for the entry of type AbstractData
      converter - Converter to convert from AbstractData to AbstractData
      defaultObject - object to return if get(Object) with given key is null. (if entry or value is null)
      Returns:
      result AbstractData or null if defaultObject is null and get(Object) with given is null or if your functions returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData
      See Also:
    • getAndConvertOrDefault

      @Contract("_, _, !null, !null -> !null") @Nullable default <C extends V, R> R getAndConvertOrDefault(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @Nullable R defaultObject, @Nullable R defaultObjectIfNull)
      Type Parameters:
      C - the convertible type
      R - the result type
      Parameters:
      key - key
      converter - Converter to convert from AbstractData to AbstractData#
      defaultObject - default object to return if no entry with given key exists
      defaultObjectIfNull - default object to return if the value of the entry with given key is null
      Returns:
      result AbstractData or null if the value of the entry is null or if no entry with given key exists and your default object is null
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
    • getAndConvertOrDefaultBoth

      @Nullable @Contract("_, _, !null -> !null") default <C extends V, R> R getAndConvertOrDefaultBoth(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @Nullable R defaultObject)
      The value returned by get(Object) with given key must be of type AbstractData or null.
      Type Parameters:
      C - the convertible type
      R - the result type
      Parameters:
      key - the key for the entry of type AbstractData
      converter - Converter to convert from AbstractData to AbstractData
      defaultObject - object to return if get(Object) with given key is null. (if entry or value is null)
      Returns:
      result AbstractData or null if defaultObject is null and get(Object) with given is null or if your functions returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData
    • getAndConvertWithException

      @Nullable default <C extends V, R, E extends Exception> R getAndConvertWithException(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter) throws E
      The value returned by get(Object) with given key must be of type AbstractData or null.
      If the value returned by get(Object) with given key is null, ExceptionConverter.convert(Object) with null.
      Type Parameters:
      C - the convertible type
      R - the result type
      E - the Exception thrown by your ExceptionConverter
      Parameters:
      key - the key for the entry of type AbstractData
      converter - Converter to convert from AbstractData to AbstractData
      Returns:
      result AbstractData or null if your functions returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData
      E - if ExceptionConverter.convert(Object) throws an Exception
    • getAndConvertWithException

      @Nullable default <C extends V, R, E extends Exception> R getAndConvertWithException(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter, @Nullable R defaultObject) throws E
      The value returned by get(Object) with given key must be of type AbstractData or null.
      Type Parameters:
      C - the convertible type
      R - the result type
      E - the Exception thrown by your ExceptionConverter
      Parameters:
      key - the key for the entry of type AbstractData
      converter - Converter to convert from AbstractData to AbstractData
      defaultObject - object to return if get(Object) with given key is null
      Returns:
      result AbstractData or null if defaultObject is null and get(Object) with given is null or if your functions returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData
      E - if ExceptionConverter.convert(Object) throws an Exception
    • getNumberAsByte

      default <E extends Exception> byte getNumberAsByte(@NotNull K key, @NotNull @NotNull ValueFactory<K,Byte,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create a byte or throw a factory
      Returns:
      byte value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getNumberAsShort

      default <E extends Exception> short getNumberAsShort(@NotNull K key, @NotNull @NotNull ValueFactory<K,Short,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create a short or throw a factory
      Returns:
      short value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getNumberAsInt

      default <E extends Exception> int getNumberAsInt(@NotNull K key, @NotNull @NotNull ValueFactory<K,Integer,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create an int or throw a factory
      Returns:
      int value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getNumberAsLong

      default <E extends Exception> long getNumberAsLong(@NotNull K key, @NotNull @NotNull ValueFactory<K,Long,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create an int or throw a factory
      Returns:
      long value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getNumberAsFloat

      default <E extends Exception> float getNumberAsFloat(@NotNull K key, @NotNull @NotNull ValueFactory<K,Float,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create a float or throw a factory
      Returns:
      float value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getNumberAsDouble

      default <E extends Exception> double getNumberAsDouble(@NotNull K key, @NotNull @NotNull ValueFactory<K,Double,E> valueFactory) throws E
      Type Parameters:
      E - factory that may be thrown by your ValueFactory
      Parameters:
      key - the key for the entry which should be of type Number
      valueFactory - if get(Object) returns null, this factory is used to create a double or throw a factory
      Returns:
      double value of Number value at given key or created value by your valueFactory if get(Object) returned null.
      Throws:
      E - may be thrown by your ValueFactory
    • getList

      @Nullable default @Nullable List<Object> getList(@NotNull K key)
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      Returns:
      List of Object
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
    • getList

      @Contract("_, !null -> !null") @Nullable default @Nullable List<Object> getList(@NotNull K key, @Nullable @Nullable List<Object> defaultList)
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      Returns:
      List of Object or defaultList if get(Object) for given key returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
    • getListAndConvert

      @Nullable default <C, R> @Nullable ArrayList<R> getListAndConvert(@NotNull K key, @NotNull @NotNull Converter<C,R> converter)
      Type Parameters:
      C - type which all elements of the implementations returned by getList(Object) will be cast to
      R - result type
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      converter - to convert from value contained in the implementations to the result type
      Returns:
      ArrayList of AbstractData or null if getList(Object) with given key returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
      ClassCastException - if the elements of the implementations returned by getList(Object) with given key cannot be cast to AbstractData
    • getListAndConvertWithException

      @Nullable default <C, R, E extends Throwable> @Nullable ArrayList<R> getListAndConvertWithException(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter) throws E
      Type Parameters:
      C - type which all elements of the implementations returned by getList(Object) will be cast to
      R - result type
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      converter - to convert from value contained in the implementations to the result type
      Returns:
      ArrayList of AbstractData or null if getList(Object) with given key returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
      ClassCastException - if the elements of the implementations returned by getList(Object) with given key cannot be cast to AbstractData
      E - if the functions throws this exception
    • getListAndConvertAndFreeMemory

      @Nullable default <C, R> @Nullable ArrayList<R> getListAndConvertAndFreeMemory(@NotNull K key, @NotNull @NotNull Converter<C,R> converter)

      Each element from the implementations - returned by getList(Object) with given key - will be set to null, after it has been converted and stored in the implementations that will be returned. After every element of the former implementations has been converted, List.clear() will be called.

      Type Parameters:
      C - type which all elements of the implementations returned by getList(Object) will be cast to
      R - result type
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      converter - to convert from value contained in the implementations to the result type
      Returns:
      ArrayList of AbstractData or null if getList(Object) with given key returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
      ClassCastException - if the elements of the implementations returned by getList(Object) with given key cannot be cast to AbstractData
    • getListAndConvertWithExceptionAndFreeMemory

      @Nullable default <C, R, E extends Throwable> @Nullable ArrayList<R> getListAndConvertWithExceptionAndFreeMemory(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter) throws E

      Each element from the implementations - returned by getList(Object) with given key - will be set to null, after it has been converted and stored in the implementations that will be returned. After every element of the former implementations has been converted, List.clear() will be called.

      Type Parameters:
      C - type which all elements of the implementations returned by getList(Object) will be cast to
      R - result type
      Parameters:
      key - the key for the entry, whose value is of type List of Object
      converter - to convert from value contained in the implementations to the result type
      Returns:
      ArrayList of AbstractData or null if getList(Object) with given key returns null
      Throws:
      ClassCastException - if the value returned by get(Object) with given key is not of type List of Object
      ClassCastException - if the elements of the implementations returned by getList(Object) with given key cannot be cast to AbstractData
      E - if given converter throws an exception (ExceptionConverter.convert(Object))
    • processIfContained

      default <C extends V> boolean processIfContained(@NotNull K key, @NotNull @NotNull Consumer<C> consumer)

      If an entry with given key exists, it will be processed by given consumer and true will be returned.
      If an entry with given key does not exists, false will be returned.

      Type Parameters:
      C - type to cast to
      Parameters:
      key - the key for the entry
      consumer - consumer to process the entry, if it exists
      Returns:
      true if an entry with given key exists, false otherwise
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • convertAndProcessIfContained

      default <C extends V, R> boolean convertAndProcessIfContained(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @NotNull @NotNull Consumer<R> consumer)

      If an entry with given key exists, it will be converted by given converter, then processed by given consumer and true will be returned.
      If an entry with given key does not exists, false will be returned.

      Type Parameters:
      C - type to cast to.
      R - type to convert to.
      Parameters:
      key - the key AbstractData for the entry.
      converter - to convert from AbstractData to AbstractData.
      consumer - consumer to process the entry, if it exists.
      Returns:
      true if an entry with given key exists, false otherwise.
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • convertWithExceptionAndProcessIfContained

      default <C extends V, R, E extends Throwable> boolean convertWithExceptionAndProcessIfContained(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter, @NotNull @NotNull Consumer<R> consumer) throws E

      If an entry with given key exists, it will be converted by given converter, then processed by given consumer and true will be returned.
      If an entry with given key does not exists, false will be returned.

      Type Parameters:
      C - type to cast to.
      R - type to convert to.
      E - exception your converter can throw.
      Parameters:
      key - the key AbstractData for the entry.
      converter - to convert from AbstractData to AbstractData.
      consumer - consumer to process the entry, if it exists.
      Returns:
      true if an entry with given key exists, false otherwise.
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData.
      E - if your ExceptionConverter throws this exception.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • processListIfContained

      default boolean processListIfContained(@NotNull K key, @NotNull @NotNull Consumer<List<Object>> consumer)

      If an entry with key exists, it will be cast to a List and then processed by given consumer and true will be returned.

      Parameters:
      key - the key AbstractData for the entry.
      consumer - consumer to process the entry, if it exists.
      Returns:
      true if an entry with given key exists, false otherwise.
      Throws:
      ClassCastException - if the value of the entry with given key is not a List.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • convertAndProcessListIfContained

      default <C, R> boolean convertAndProcessListIfContained(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @NotNull @NotNull Consumer<List<R>> consumer)

      If an entry with given key exists, it will be cast to a List and every element cast to AbstractData converted to AbstractData. All elements will be added to a new List, which will then be processed by given consumer and true will be returned.

      Parameters:
      key - the key AbstractData for the entry.
      converter - Converter to convert from AbstractData to AbstractData
      consumer - consumer to process the entry, if it exists.
      Returns:
      true if an entry with given key exists, false otherwise.
      Throws:
      ClassCastException - if the value of the entry with given key is not a List or if any element inside the list is not of type AbstractData.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • convertWithExceptionAndProcessListIfContained

      default <C, R, E extends Throwable> boolean convertWithExceptionAndProcessListIfContained(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,E> converter, @NotNull @NotNull Consumer<List<R>> consumer) throws E

      If an entry with given key exists, it will be cast to a List and every element cast to AbstractData converted to AbstractData. All elements will be added to a new List, which will then be processed by given consumer and true will be returned.

      Parameters:
      key - the key AbstractData for the entry.
      converter - ExceptionConverter to convert from AbstractData to AbstractData
      consumer - consumer to process the entry, if it exists.
      Returns:
      true if an entry with given key exists, false otherwise.
      Throws:
      ClassCastException - if the value of the entry with given key is not a List or if any element inside the list is not of type AbstractData.
      E extends Throwable
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      The entry's value may still be null. To assure non-null values use processIfNotNull(Object, Consumer).
    • processIfContainedAndRequireNotNull

      default <C extends V, E extends Throwable> boolean processIfContainedAndRequireNotNull(@NotNull K key, @NotNull @NotNull Consumer<C> consumer, ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E
      • If an entry with given key exists and it's value is not null, it will be processed by given consumer and true will be returned.
      • If an entry with given key exists and it's value is null, the exception AbstractData supplied by your ExceptionSupplier will be thrown.
      • If an entry with given key does not exists, false will be returned.
      Type Parameters:
      C - type to cast to
      Parameters:
      key - the key for the entry
      consumer - consumer to process the entry, if it exists
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      Returns:
      true if an entry with given key exists, false otherwise
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
      E - if an entry with given key exists, and its value is null.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      if get(Object) returns null, Converter.convert(Object) will not be called. So it is safe for your Converter to assume not-null values.
    • convertAndProcessIfContainedAndRequireNotNull

      default <C extends V, R, E extends Throwable> boolean convertAndProcessIfContainedAndRequireNotNull(@NotNull K key, Converter<C,R> converter, @NotNull @NotNull Consumer<R> consumer, ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E
      • If an entry with given key exists and it's value is not null, it will be cast to AbstractData, converted to AbstractData and then processed by given consumer and true will be returned.
      • If an entry with given key exists and it's value is null, the exception AbstractData supplied by your ExceptionSupplier will be thrown.
      • If an entry with given key does not exists, false will be returned.
      Type Parameters:
      C - type to cast to
      Parameters:
      key - the key for the entry
      converter - Converter to convert from AbstractData to AbstractData.
      consumer - consumer to process the entry, if it exists
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      Returns:
      true if an entry with given key exists, false otherwise
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
      E - if an entry with given key exists, and its value is null.
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      if get(Object) returns null, Converter.convert(Object) will not be called. So it is safe for your Converter to assume not-null values.
    • convertWithExceptionAndProcessIfContainedAndRequireNotNull

      default <C extends V, R, E extends Throwable, F extends Throwable> boolean convertWithExceptionAndProcessIfContainedAndRequireNotNull(@NotNull K key, ExceptionConverter<C,R,F> converter, @NotNull @NotNull Consumer<R> consumer, ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E, F
      • If an entry with given key exists and it's value is not null, it will be cast to AbstractData, converted to AbstractData and then processed by given consumer and true will be returned.
      • If an entry with given key exists and it's value is null, the exception AbstractData supplied by your ExceptionSupplier will be thrown.
      • If an entry with given key does not exists, false will be returned.
      Type Parameters:
      C - type to cast to.
      E - exception supplied by your ExceptionSupplier.
      R - type to convert to.
      F - exception thrown by your ExceptionConverter.
      Parameters:
      key - the key for the entry
      converter - ExceptionConverter to convert from AbstractData to AbstractData.
      consumer - consumer to process the entry, if it exists
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      Returns:
      true if an entry with given key exists, false otherwise
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
      E - if an entry with given key exists, and its value is null.
      F - if your converter throws this exception
      Implementation Note:
      The entry will NOT be removed from this AbstractData.
      if get(Object) returns null, Converter.convert(Object) will not be called. So it is safe for your Converter to assume not-null values.
    • processIfNotNull

      default <C extends V> boolean processIfNotNull(@NotNull K key, @NotNull @NotNull Consumer<C> consumer)
      Type Parameters:
      C - type to cast to
      Parameters:
      key - the key for the entry
      consumer - consumer to process the entry, if it exists, and it's value is not null.
      Returns:
      true if an entry with given key exists, and it's value is not null. false otherwise
      Throws:
      ClassCastException - if the value of the entry with given key is not of type AbstractData
    • getAndRequireNotNull

      @NotNull default <E extends Throwable> @NotNull Object getAndRequireNotNull(@NotNull K key, @NotNull @NotNull ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E

      Gets the value with given key and returns it, if the value is not null. If the value is null, AbstractData supplied by your ExceptionSupplier will be thrown.

      Type Parameters:
      E - The Throwable to be thrown if get(Object) with given key returns null.
      Parameters:
      key - AbstractData key
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      Returns:
      value returned by get(Object). Never null.
      Throws:
      E - if get(Object) with given key returns null.
    • getAsAndRequireNotNull

      @NotNull default <C extends V, E extends Throwable> C getAsAndRequireNotNull(@NotNull K key, @NotNull @NotNull ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E

      Gets the value with given key, casts it to AbstractData and returns it, if the value is not null. If the value is null, AbstractData supplied by your ExceptionSupplier will be thrown.

      Type Parameters:
      C - The class to cast to.
      E - The Throwable to be thrown if get(Object) with given key returns null.
      Parameters:
      key - AbstractData key
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      Returns:
      value cast to AbstractData returned by get(Object). Never null.
      Throws:
      E - if get(Object) with given key returns null.
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData.
    • getAndRequireNotNullAndConvert

      @NotNull default <C extends V, R, E extends Throwable> R getAndRequireNotNullAndConvert(@NotNull K key, @NotNull @NotNull Converter<C,R> converter, @NotNull @NotNull ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E

      Gets the value with given key and casts it to AbstractData. If the value is not null it will be converted to AbstractData and then returned. If the value is null, AbstractData supplied by your ExceptionSupplier will be thrown.

      Note: if get(Object) returns null, Converter.convert(Object) will not be called. So it is safe for your Converter to assume not-null values.

      Type Parameters:
      C - The class to cast to.
      E - The Throwable to be thrown if get(Object) with given key returns null.
      R - The class to convert to.
      Parameters:
      key - AbstractData key
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      converter - Converter to convert from AbstractData to AbstractData.
      Returns:
      value cast to AbstractData returned by get(Object). Never null.
      Throws:
      E - if get(Object) with given key returns null.
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData.
    • getAndRequireNotNullAndConvertWithException

      @NotNull default <C extends V, R, E extends Throwable, F extends Throwable> R getAndRequireNotNullAndConvertWithException(@NotNull K key, @NotNull @NotNull ExceptionConverter<C,R,F> converter, @NotNull @NotNull ExceptionSupplier<K,AbstractData<K,V>,E> exceptionSupplier) throws E, F

      Gets the value with given key and casts it to AbstractData. If the value is not null it will be converted to AbstractData and then returned. If the value is null, AbstractData supplied by your ExceptionSupplier will be thrown.

      Type Parameters:
      C - The class to cast to.
      E - The Throwable to be thrown if get(Object) with given key returns null.
      F - The Throwable which your ExceptionConverter can throw.
      R - The class to convert to.
      Parameters:
      key - AbstractData key
      exceptionSupplier - ExceptionSupplier supplies a Throwable if get(Object) with given key returns null.
      converter - ExceptionConverter to convert from AbstractData to AbstractData.
      Returns:
      value cast to AbstractData returned by get(Object). Never null.
      Throws:
      E - if get(Object) with given key returns null.
      ClassCastException - if the value returned by get(Object) with given key is not of type AbstractData.
      F - if your ExceptionConverter throws this exception.
      Implementation Note:
      if get(Object) returns null, ExceptionConverter.convert(Object) will not be called. So it is safe for your ExceptionConverter to assume not-null values.
    • toRecord

      @NotNull default <T extends Record> T toRecord(Class<T> recordClass)
      Converts this AbstractData to given recordClass. This conversion supports all primitive types, String and records.
      Type Parameters:
      T - record class
      Parameters:
      recordClass - the class to the record AbstractData.
      Returns:
      record AbstractData filled by this AbstractData.
    • isEmpty

      boolean isEmpty()
      Returns:
      true if this data does not contain any entries, false otherwise
    • size

      int size()
      Returns:
      current amount of entries contained.
    • toJsonString

      @NotNull default @NotNull StringBuilder toJsonString()
      Writes this AbstractData to a StringBuilder.
      Returns:
      StringBuilder
    • getParseType

      @Internal @NotNull default @NotNull ParseType getParseType()
      How this AbstractData should be parsed
      Returns:
      ParseType
    • getData

      default AbstractData<K,V> getData()
      Specified by:
      getData in interface Datable