public class SquidStorage extends JsonStorage
compress, contents, garbleKey, json, preferences, storageName
Constructor and Description |
---|
SquidStorage()
Please don't use this constructor if possible; it simply calls
SquidStorage(String) with the constant
String "nameless". |
SquidStorage(java.lang.String fileName)
Creates a SquidStorage with the given fileName to save using Preferences from libGDX.
|
SquidStorage(java.lang.String fileName,
long[] garble)
Creates a SquidStorage with the given fileName to save using Preferences from libGDX.
|
SquidStorage(java.lang.String fileName,
java.lang.String garble)
Creates a SquidStorage with the given fileName to save using Preferences from libGDX.
|
Modifier and Type | Method and Description |
---|---|
SquidStorage |
clear()
Clears the current group of objects; recommended if you intend to store under multiple outerName keys.
|
<T> T |
get(java.lang.String outerName,
java.lang.String innerName,
java.lang.Class<T> type)
Gets an object from the storage by the given
outerName key from store(String) and
innerName key from put(String, Object) , and uses the class given by type for the
returned value, assuming it matches the object that was originally put with those keys. |
int |
preferencesSize()
Gets the approximate size of the currently-stored preferences.
|
SquidStorage |
put(java.lang.String innerName,
java.lang.Object o)
Prepares to store the Object
o to be retrieved with innerName in the current group of objects. |
SquidStorage |
remove(java.lang.String innerName)
Removes one object from the current group by the
innerName it was prepared with using
put(String, Object) . |
java.lang.String |
show()
Gets a String representation of the data that would be saved when
store(String) is called. |
SquidStorage |
store(java.lang.String outerName)
Actually stores all objects that had previously been prepared with
put(String, Object) , with
outerName used as a key to retrieve any object in the current group. |
public SquidStorage()
SquidStorage(String)
with the constant
String "nameless". This could easily overlap with other files/sections in Preferences, so you should always
prefer giving a String argument to the constructor, typically the name of the game.the recommended constructor to use
public SquidStorage(java.lang.String fileName)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object)
to put each individual item into the saved storage with its own innerName.
fileName
- the valid file name to create or open from Preferences; typically the name of the game/app.public SquidStorage(java.lang.String fileName, java.lang.String garble)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object)
to put each individual item into the saved storage with its own innerName.
fileName
- the valid file name to create or open from Preferences; typically the name of the game/app.garble
- a String that will be used as a key to obfuscate the saved output if non-nullpublic SquidStorage(java.lang.String fileName, long[] garble)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object)
to put each individual item into the saved storage with its own innerName.
fileName
- the valid file name to create or open from Preferences; typically the name of the game/app.garble
- a long array that will be used as a key to obfuscate the saved output if non-nullpublic SquidStorage put(java.lang.String innerName, java.lang.Object o)
o
to be retrieved with innerName
in the current group of objects.
Does not write to a permanent location until store(String)
is called. The innerName used to store an
object is required to get it back again, and can also be used to remove it before storing (or storing again).put
in class JsonStorage
innerName
- one of the two Strings needed to retrieve this latero
- the Object to prepare to storepublic SquidStorage store(java.lang.String outerName)
put(String, Object)
, with
outerName
used as a key to retrieve any object in the current group. Flushes the preferences, making the
changes permanent (until overwritten), but does not change the current group (you may want to call this method
again with additional items in the current group, and that would simply involve calling put() again). If you want
to clear the current group, use clear()
. If you want to remove just one object from the current group,
use remove(String)
.store
in class JsonStorage
outerName
- one of the two Strings needed to retrieve any of the objects in the current grouppublic java.lang.String show()
store(String)
is called. This can be
useful for finding particularly problematic objects that require unnecessary space when serialized.show
in class JsonStorage
store(String)
is calledpublic SquidStorage clear()
clear
in class JsonStorage
public SquidStorage remove(java.lang.String innerName)
innerName
it was prepared with using
put(String, Object)
. This does not affect already-stored objects unless store(String)
is called
after this, in which case the new version of the current group, without the object this removed, is stored.remove
in class JsonStorage
innerName
- the String key used to put an object in the current group with put(String, Object)
public <T> T get(java.lang.String outerName, java.lang.String innerName, java.lang.Class<T> type)
outerName
key from store(String)
and
innerName
key from put(String, Object)
, and uses the class given by type
for the
returned value, assuming it matches the object that was originally put with those keys. If no such object is
present, returns null. Results are undefined if type
doesn't match the actual class of the stored object.get
in class JsonStorage
T
- the type of the value to retrieve; if type was RNG.class
, this would be RNG
outerName
- the key used to store the group of objects with store(String)
innerName
- the key used to store the specific object with put(String, Object)
type
- the class of the value; for a class like RNG, use RNG.class
, but changed to fitpublic int preferencesSize()
preferencesSize
in class JsonStorage
Copyright © Eben Howard 2012–2022. All rights reserved.