public class TextStorage
extends java.lang.Object
StringConvert
.
Created by Tommy Ettinger on 9/16/2016.Modifier and Type | Field and Description |
---|---|
boolean |
compress |
protected squidpony.squidmath.OrderedMap<java.lang.String,java.lang.String> |
contents |
long[] |
garbleKey |
squidpony.StringConvert<squidpony.squidmath.OrderedMap<java.lang.String,java.lang.String>> |
mapConverter |
com.badlogic.gdx.Preferences |
preferences |
java.lang.String |
storageName |
Constructor and Description |
---|
TextStorage()
Please don't use this constructor if possible; it simply calls
TextStorage(String) with the constant
String "nameless". |
TextStorage(java.lang.String fileName)
Creates a JsonStorage with the given fileName to save using Preferences from libGDX.
|
TextStorage(java.lang.String fileName,
long[] garble)
Creates a JsonStorage with the given fileName to save using Preferences from libGDX.
|
TextStorage(java.lang.String fileName,
java.lang.String garble)
Creates a JsonStorage with the given fileName to save using Preferences from libGDX.
|
Modifier and Type | Method and Description |
---|---|
TextStorage |
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.CharSequence typeName,
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, StringConvert) , and uses the class given by type
for the returned value, assuming it matches the object that was originally put with those keys. |
<T> T |
get(java.lang.String outerName,
java.lang.String innerName,
squidpony.StringConvert<?> converter,
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, StringConvert) , 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.
|
<T> TextStorage |
put(java.lang.String innerName,
T o,
squidpony.StringConvert converter)
Prepares to store the Object
o to be retrieved with innerName in the current group of objects. |
TextStorage |
remove(java.lang.String innerName)
Removes one object from the current group by the
innerName it was prepared with using
put(String, Object, StringConvert) . |
java.lang.String |
show()
Gets a String representation of the data that would be saved when
store(String) is called. |
TextStorage |
store(java.lang.String outerName)
Actually stores all objects that had previously been prepared with
put(String, Object, StringConvert) ,
with outerName used as a key to retrieve any object in the current group. |
public final com.badlogic.gdx.Preferences preferences
public final java.lang.String storageName
protected squidpony.squidmath.OrderedMap<java.lang.String,java.lang.String> contents
public final squidpony.StringConvert<squidpony.squidmath.OrderedMap<java.lang.String,java.lang.String>> mapConverter
public boolean compress
public long[] garbleKey
public TextStorage()
TextStorage(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 TextStorage(java.lang.String fileName)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object, StringConvert)
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 TextStorage(java.lang.String fileName, java.lang.String garble)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object, StringConvert)
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
- the key that must be used exactly to decrypt any data saved by this TextStoragepublic TextStorage(java.lang.String fileName, long[] garble)
store(String)
, and can further distinguish data under the outerName when
you call put(String, Object, StringConvert)
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
- the key that must be used exactly to decrypt any data saved by this TextStorage; will be copiedpublic <T> TextStorage put(java.lang.String innerName, T o, squidpony.StringConvert converter)
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).innerName
- one of the two Strings needed to retrieve this latero
- the Object to prepare to storeconverter
- a StringConvert that supports the type of opublic TextStorage store(java.lang.String outerName)
put(String, Object, StringConvert)
,
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)
.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.store(String)
is calledpublic TextStorage clear()
public TextStorage remove(java.lang.String innerName)
innerName
it was prepared with using
put(String, Object, StringConvert)
. 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.innerName
- the String key used to put an object in the current group with put(String, Object, StringConvert)
public <T> T get(java.lang.String outerName, java.lang.String innerName, squidpony.StringConvert<?> converter, java.lang.Class<T> type)
outerName
key from store(String)
and
innerName
key from put(String, Object, StringConvert)
, 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
exists, returns null. Results are undefined if type
doesn't match the actual class of the stored object.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, StringConvert)
converter
- a StringConvert, such as one from Converters
or found with
StringConvert.get(CharSequence)
, to deserialize the datatype
- the class of the value; for a class like RNG, use RNG.class
, but changed to fitpublic <T> T get(java.lang.String outerName, java.lang.String innerName, java.lang.CharSequence typeName, java.lang.Class<T> type)
outerName
key from store(String)
and
innerName
key from put(String, Object, StringConvert)
, and uses the class given by type
for the returned value, assuming it matches the object that was originally put with those keys. Uses typeName to
find an appropriate StringConvert that has already been created (and thus registered), and because typeName is a
CharSequence instead of a Class, it doesn't suffer from generic type erasure at runtime, It can and should have
the generic type arguments as if it were the type for a variable, e.g. OrderedSet<ArrayList<String>>
. If
no such object exists, returns null. Results are undefined if type
doesn't match the actual class of the
stored object, and this will return null if there is no known StringConvert for the given typeName.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, StringConvert)
typeName
- the name of the type to produce, with generic type parameters intact; used to find an appropriate StringConverttype
- the class of the value; for a class like RNG, use RNG.class
, but changed to fitpublic int preferencesSize()
Copyright © Eben Howard 2012–2022. All rights reserved.