Package dev.cashire.cashconfig.items
Class ConfigGroup
java.lang.Object
dev.cashire.cashconfig.items.BaseConfigItem<List<BaseConfigItem<?>>>
dev.cashire.cashconfig.items.ConfigGroup
Configuration item for a json object for
BaseConfigItem
.-
Nested Class Summary
Nested classes/interfaces inherited from class dev.cashire.cashconfig.items.BaseConfigItem
BaseConfigItem.Type
-
Field Summary
Fields inherited from class dev.cashire.cashconfig.items.BaseConfigItem
key, type, value
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty Group item with no key.ConfigGroup(@NotNull String key)
Creates an empty Group item with given key.ConfigGroup(@NotNull String key, List<BaseConfigItem<?>> items)
Creates a Group item with given key and items. -
Method Summary
Modifier and TypeMethodDescriptionboolean
addItem(@NotNull BaseConfigItem<?> item)
Adds an item to this Group item.void
fromJson(@NotNull com.google.gson.JsonElement element)
Deserialize data from theJsonElement
into this item.Gets an item with the given key.List<BaseConfigItem<?>>
getValue()
The return value is an unmodifiable view of the listCollections.unmodifiableList(List)
.boolean
Checks to see if an item of a given key exists.removeItem(@NotNull String key)
Remove an item at a given key.setItem(@NotNull BaseConfigItem<?> item)
Sets the item at the given item.void
setValue(@NotNull List<BaseConfigItem<?>> value)
Set the value of this item.int
size()
The amount of items in this Group item.void
toJson(@NotNull com.google.gson.JsonArray parent)
Serializes data into the givenJsonArray
This item'sBaseConfigItem.getKey()
value is ignored in this case.void
toJson(@NotNull com.google.gson.JsonObject parent)
Serializes data into the givenJsonObject
.
-
Constructor Details
-
ConfigGroup
public ConfigGroup()Creates an empty Group item with no key. Should not be used if adding this item toConfigGroup
-
ConfigGroup
Creates an empty Group item with given key.- Parameters:
key
- The key to be used if put in a group.
-
ConfigGroup
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
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
Gets an item with the given key.- Parameters:
key
- key to look for.- Returns:
- the item if found, otherwise null
-
removeItem
Remove an item at a given key.- Parameters:
key
- key to look for.- Returns:
- the item if removed, null otherwise
-
setItem
Sets the item at the given item.- Parameters:
item
- item to set (key must be set)- Returns:
- returns previous item or null
-
hasItem
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 givenJsonObject
. This item is put in theJsonObject
at key value given byBaseConfigItem.getKey()
. It is put in as type given byBaseConfigItem.getType()
- Specified by:
toJson
in classBaseConfigItem<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 givenJsonArray
This item'sBaseConfigItem.getKey()
value is ignored in this case. It is put in as type given byBaseConfigItem.getType()
- Specified by:
toJson
in classBaseConfigItem<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 theJsonElement
into this item. Treats theJsonElement
as the type given byBaseConfigItem.getType()
- Specified by:
fromJson
in classBaseConfigItem<List<BaseConfigItem<?>>>
- Parameters:
element
-JsonElement
to load data from.
-
getValue
The return value is an unmodifiable view of the listCollections.unmodifiableList(List)
.- Overrides:
getValue
in classBaseConfigItem<List<BaseConfigItem<?>>>
- Returns:
- value stored by this item type.
- See Also:
BaseConfigItem.Type
-
setValue
Description copied from class:BaseConfigItem
Set the value of this item.- Overrides:
setValue
in classBaseConfigItem<List<BaseConfigItem<?>>>
- Parameters:
value
- value to use instead of current value.
-