Package dev.cashire.cashconfig.items
Class ConfigList
java.lang.Object
dev.cashire.cashconfig.items.BaseConfigItem<List<BaseConfigItem<?>>>
dev.cashire.cashconfig.items.ConfigList
Configuration item for a json array 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 Array item with no key.ConfigList(@NotNull String key, List<BaseConfigItem<?>> items, BaseConfigItem.Type subType)
Creates an Array item with given key and items null is a valid parameter for items and subType.ConfigList(String key)
Creates an empty Array item with no key.ConfigList(String key, @NotNull BaseConfigItem<?> item)
Creates an Array item with given key and item. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addItem(@NotNull BaseConfigItem<?> item)
Adds an item to this Array Item.void
fromJson(@NotNull com.google.gson.JsonElement element)
Deserialize data from theJsonElement
into this item.getItem(int index)
Returns the item at the given index.Gets the type that the this array item is limited to.List<BaseConfigItem<?>>
getValue()
The return value is an unmodifiable view of the listCollections.unmodifiableList(List)
.removeItem(int index)
Remove an Item from the list.void
setValue(@NotNull List<BaseConfigItem<?>> value)
Set the value of this item.int
size()
The amount of items in this Array 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
-
ConfigList
public ConfigList()Creates an empty Array item with no key. Should not be used if adding this item toConfigGroup
The first item added (viaaddItem(BaseConfigItem)
) will setBaseConfigItem.Type
of the items stored in the array. -
ConfigList
Creates an empty Array item with no key. The first item added (viaaddItem(BaseConfigItem)
) will setBaseConfigItem.Type
of the items stored in the array.- Parameters:
key
- The key to be used if put in a group
-
ConfigList
Creates an Array item with given key and item. Subtype is inferred from given item- Parameters:
key
- The key to be used if put in a group.item
- item to add to this array by default.
-
ConfigList
public ConfigList(@NotNull @NotNull String key, List<BaseConfigItem<?>> items, BaseConfigItem.Type subType)Creates an Array item with given key and items null is a valid parameter for items and subType. If items is null at creation, a empty list will be used instead. If subType is null at creation, the first item added (whether by items parameter oraddItem(BaseConfigItem)
) will setBaseConfigItem.Type
of the items stored in the array.- Parameters:
key
- The key to be used if put in a group.items
- List of items to add to this array by default.subType
- The type of this array- Throws:
IllegalArgumentException
- if an item in the array doesn't match subType
-
-
Method Details
-
size
public int size()The amount of items in this Array Item.- Returns:
- count of
getValue()
-
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.
-
getSubType
Gets the type that the this array item is limited to. if this value is null, the first item added withaddItem(BaseConfigItem)
will set this type.- Returns:
BaseConfigItem.Type
of the items.
-
addItem
Adds an item to this Array Item. if subType is null, then this item will set the type for this array based on it's type.- Parameters:
item
- item to add.- Throws:
IllegalArgumentException
- type of item did not matchgetSubType()
-
getItem
Returns the item at the given index.- Parameters:
index
- position in the list- Returns:
- item that was found
-
removeItem
Remove an Item from the list.- Parameters:
index
- position to remove- Returns:
- item if removed, null 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
-