Class ConfigGroup


public final class ConfigGroup extends BaseConfigItem<List<BaseConfigItem<?>>>
Configuration item for a json object for BaseConfigItem.
  • Constructor Details

    • ConfigGroup

      public ConfigGroup()
      Creates an empty Group item with no key. Should not be used if adding this item to ConfigGroup
    • ConfigGroup

      public ConfigGroup(@NotNull @NotNull String key)
      Creates an empty Group item with given key.
      Parameters:
      key - The key to be used if put in a group.
    • ConfigGroup

      public ConfigGroup(@NotNull @NotNull String key, List<BaseConfigItem<?>> items)
      Creates a Group item with given key and items. null is a valid parameter for items. If items is null at creation, an empty list will be used instead.
      Parameters:
      key - The key to be used if put in a group.
      items - List of items to add to this group by default.
      Throws:
      InvalidParameterException - Two items in items have the same key.
  • Method Details

    • size

      public int size()
      The amount of items in this Group item.
      Returns:
      count of getValue()
    • addItem

      public boolean addItem(@NotNull @NotNull BaseConfigItem<?> item)
      Adds an item to this Group item.
      Parameters:
      item - item to add.
      Returns:
      true if added false if key for that item already exists.
    • getItem

      public BaseConfigItem<?> getItem(@NotNull @NotNull String key)
      Gets an item with the given key.
      Parameters:
      key - key to look for.
      Returns:
      the item if found, otherwise null
    • removeItem

      public BaseConfigItem<?> removeItem(@NotNull @NotNull String key)
      Remove an item at a given key.
      Parameters:
      key - key to look for.
      Returns:
      the item if removed, null otherwise
    • setItem

      public BaseConfigItem<?> setItem(@NotNull @NotNull BaseConfigItem<?> item)
      Sets the item at the given item.
      Parameters:
      item - item to set (key must be set)
      Returns:
      returns previous item or null
    • hasItem

      public boolean hasItem(@NotNull @NotNull String key)
      Checks to see if an item of a given key exists.
      Parameters:
      key - key to check.
      Returns:
      true if item exits, false otherwise.
    • toJson

      public void toJson(@NotNull @NotNull com.google.gson.JsonObject parent)
      Description copied from class: BaseConfigItem
      Serializes data into the given JsonObject. This item is put in the JsonObject at key value given by BaseConfigItem.getKey(). It is put in as type given by BaseConfigItem.getType()
      Specified by:
      toJson in class BaseConfigItem<List<BaseConfigItem<?>>>
      Parameters:
      parent - JsonObject to add this item to.
    • toJson

      public void toJson(@NotNull @NotNull com.google.gson.JsonArray parent)
      Description copied from class: BaseConfigItem
      Serializes data into the given JsonArray This item's BaseConfigItem.getKey() value is ignored in this case. It is put in as type given by BaseConfigItem.getType()
      Specified by:
      toJson in class BaseConfigItem<List<BaseConfigItem<?>>>
      Parameters:
      parent - JsonArray to add to this item to.
    • fromJson

      public void fromJson(@NotNull @NotNull com.google.gson.JsonElement element)
      Description copied from class: BaseConfigItem
      Deserialize data from the JsonElement into this item. Treats the JsonElement as the type given by BaseConfigItem.getType()
      Specified by:
      fromJson in class BaseConfigItem<List<BaseConfigItem<?>>>
      Parameters:
      element - JsonElement to load data from.
    • getValue

      public List<BaseConfigItem<?>> getValue()
      The return value is an unmodifiable view of the list Collections.unmodifiableList(List).
      Overrides:
      getValue in class BaseConfigItem<List<BaseConfigItem<?>>>
      Returns:
      value stored by this item type.
      See Also:
      BaseConfigItem.Type
    • setValue

      public void setValue(@NotNull @NotNull List<BaseConfigItem<?>> value)
      Description copied from class: BaseConfigItem
      Set the value of this item.
      Overrides:
      setValue in class BaseConfigItem<List<BaseConfigItem<?>>>
      Parameters:
      value - value to use instead of current value.