Package dev.prozilla.pine.core.storage
Class Storage
java.lang.Object
dev.prozilla.pine.core.storage.Storage
- All Implemented Interfaces:
Destructible,Initializable,Printable,Transceivable<Storage>,Transmittable<Storage>
- Direct Known Subclasses:
LocalStorage,SessionStorage
public abstract class Storage
extends Object
implements Initializable, Destructible, Transceivable<Storage>, Printable
A key-value store that uses strings for keys and values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Applicationprotected final StorageConfigprotected booleanThe items in this store. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all items from this store that are currently in memory.voiddestroy()Saves the items from this store and clears the memory.booleangetBoolean(String key) Returns the value of the item in this store with a given key by parsing it.Returns the value of the item in this store with a given key by parsing it.getDimension(String key) Returns the value of the item in this store with a given key by parsing it.getDualDimension(String key) Returns the value of the item in this store with a given key by parsing it.floatReturns the value of the item in this store with a given key by parsing it.intReturns the value of the item in this store with a given key by parsing it.Returns the value of the item in this store with a given key.<T> TgetItem(String key, ParseFunction<T> parseFunction) Returns the value of the item in this store with a given key by parsing it.<T> TReturns the value of the item in this store with a given key by parsing it.protected LoggergetVector2f(String key) Returns the value of the item in this store with a given key by parsing it.getVector2i(String key) Returns the value of the item in this store with a given key by parsing it.getVector3f(String key) Returns the value of the item in this store with a given key by parsing it.getVector3i(String key) Returns the value of the item in this store with a given key by parsing it.getVector4f(String key) Returns the value of the item in this store with a given key by parsing it.getVector4i(String key) Returns the value of the item in this store with a given key by parsing it.booleanChecks if this store has an item with a given key.voidinit()Loads items into this store.items()Returns the items in this store.keys()Returns the keys of the items in this store.protected abstract voidload()Loads items into this store.voidOverwrites the items in this store with the items from another store.voidprint()Prints this object using the system logger then terminates the line.voidRemoves all items from this store.booleanremoveItem(String key) Removes the item with a given key.protected abstract voidsave()Saves the items from this store.self()booleanSets the value of the item with a given key to the string representation of an object.booleanSets the value of the item with a given key.<O> booleanSets the values of multiple items.protected <O> booleanSets the values of multiple items.protected booleanprotected booleanintsize()Returns the amount of items in this store.@NotNull StringtoString()Returns a string representation of this object.voidCopies the items of this store to another store.values()Returns the values of the items in this store.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface dev.prozilla.pine.common.Transceivable
receive
-
Field Details
-
items
The items in this store. -
application
-
config
-
isInitialized
protected boolean isInitialized
-
-
Constructor Details
-
Storage
Creates a new key-value store.
-
-
Method Details
-
init
public void init()Loads items into this store.- Specified by:
initin interfaceInitializable
-
destroy
public void destroy()Saves the items from this store and clears the memory.- Specified by:
destroyin interfaceDestructible
-
overwrite
Overwrites the items in this store with the items from another store.- Parameters:
source- The store to read the items from
-
transmit
Copies the items of this store to another store.- Specified by:
transmitin interfaceTransceivable<Storage>- Specified by:
transmitin interfaceTransmittable<Storage>- Parameters:
target- The store to copy the items to
-
self
- Specified by:
selfin interfaceTransceivable<Storage>
-
hasItem
Checks if this store has an item with a given key.- Parameters:
key- The key of the item- Returns:
trueif an item exists in this store with the given key.
-
getVector2f
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getVector2i
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getVector3f
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getVector3i
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getVector4f
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getVector4i
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getDimension
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getDualDimension
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getColor
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed. - See Also:
-
getItem
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the itemparser- The parser to use- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed.
-
getItem
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the itemparseFunction- The parsing function to use- Returns:
- The parsed value of the item, or
nullif the item does not exist or the parsing failed.
-
getInt
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
0if the item does not exist. - Throws:
NumberFormatException- If the parsing failed.- See Also:
-
getFloat
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
0if the item does not exist. - Throws:
NumberFormatException- If the parsing failed.- See Also:
-
getBoolean
Returns the value of the item in this store with a given key by parsing it.- Parameters:
key- The key of the item- Returns:
- The parsed value of the item, or
falseif the item does not exist. - See Also:
-
getItem
Returns the value of the item in this store with a given key.- Parameters:
key- The key of the item- Returns:
- The value of the item, or
nullif the item does not exist.
-
setItems
Sets the values of multiple items.- Parameters:
items- The key and value pairs- Returns:
trueif an item was changed.
-
setItems
Sets the values of multiple items.- Parameters:
items- The key and value pairs- Returns:
trueif an item was changed.
-
setItem
Sets the value of the item with a given key to the string representation of an object.- Parameters:
key- The key of the itemvalue- The new value- Returns:
trueif the item was changed.- See Also:
-
setItem
Sets the value of the item with a given key.- Parameters:
key- The key of the itemvalue- The new value- Returns:
trueif the item was changed.
-
removeItem
Removes the item with a given key.- Parameters:
key- The key of the item- Returns:
falseif there was no item with the given key.
-
removeAll
public void removeAll()Removes all items from this store. -
clear
public void clear()Removes all items from this store that are currently in memory. -
size
public int size()Returns the amount of items in this store.- Returns:
- The amount of items in this store.
-
items
Returns the items in this store.- Returns:
- The items in this store.
-
keys
Returns the keys of the items in this store.- Returns:
- The keys in this store.
-
values
Returns the values of the items in this store.- Returns:
- The values in this store.
-
shouldLoad
protected boolean shouldLoad() -
shouldSave
protected boolean shouldSave() -
load
protected abstract void load()Loads items into this store. -
save
protected abstract void save()Saves the items from this store. -
print
public void print()Description copied from interface:PrintablePrints this object using the system logger then terminates the line. -
getLogger
-
toString
Description copied from interface:PrintableReturns a string representation of this object.
-