Interface DataWrapper<K,V>

All Superinterfaces:
AbstractData<K,V>, ContentOnlyData<K,V>, Datable, Iterable<Entry<K,V>>
All Known Subinterfaces:
SAODataWrapper<O>, SODataWrapper
All Known Implementing Classes:
SAODataWrapperImpl, SODataWrapperImpl

public interface DataWrapper<K,V> extends ContentOnlyData<K,V>
a data wrapper wraps a single object inside a AbstractData.

When parsed a normal AbstractData will be parsed to a json-object. That means it will start with a "{".
This is not always useful. For example when parsing an array to a json-array without a json-object around it. That the use case of the DataWrapper. It will parse the object it is wrapping without adding a json-object around it.

That is why a DataWrapper can only have a single Entry at a time. Adding or removing this will throw an UnsupportedOperationException
See Also:
  • Method Details

    • getKey

      K getKey()
      Returns:
      the key of the entry inside this DataWrapper
    • getEntry

      @NotNull @NotNull Entry<K,V> getEntry(@NotNull K key)
      Specified by:
      getEntry in interface AbstractData<K,V>
      Parameters:
      key - key
      Returns:
      Entry with given key or null, if no such Entry exists.
    • set

      default void set(@NotNull V obj)
    • get

      default V get()
    • add

      default boolean add(@NotNull K key, @Nullable V value)
      Description copied from interface: AbstractData
      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).

      Specified by:
      add in interface AbstractData<K,V>
      Parameters:
      key - key
      value - value
      Returns:
      true if a new Entry was added, false otherwise
    • addEntry

      default void addEntry(@NotNull @NotNull Entry<K,V> entry)
      Description copied from interface: AbstractData
      Adds a new Entry.

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

      Specified by:
      addEntry in interface AbstractData<K,V>
      Parameters:
      entry - entry to add
    • remove

      @Nullable default @Nullable Entry<K,V> remove(@NotNull K key)
      Description copied from interface: AbstractData

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

      Specified by:
      remove in interface AbstractData<K,V>
      Parameters:
      key - key for the entry to remove
      Returns:
      the removed Entry or null if no entry was removed.
    • isEmpty

      default boolean isEmpty()
      Specified by:
      isEmpty in interface AbstractData<K,V>
      Returns:
      true if this data does not contain any entries, false otherwise
    • size

      default int size()
      Specified by:
      size in interface AbstractData<K,V>
      Returns:
      current amount of entries contained.
    • iterator

      @NotNull default @NotNull Iterator<Entry<K,V>> iterator()
      Specified by:
      iterator in interface Iterable<K>