Package tripleplay.util
Class TypedStorage
java.lang.Object
tripleplay.util.TypedStorage
Makes using PlayN
Storage
more civilized. Provides getting and setting of typed values
(ints, booleans, etc.). Provides support for default values. Provides Value
interface to
storage items.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns whether the specified key is mapped to some value.Returns the specified property as a string, returning null if the property does not exist.boolean
Returns the specified property as a boolean.double
Returns the specified property as a double.int
Returns the specified property as an int.long
Returns the specified property as a long.<E extends Enum<E>>
EReturns the specified property as an enum.Returns the specified property as a string, returning the supplied defautl value if the property does not exist.void
Removes the specified key (and its value) from storage.void
Sets the specified property to the supplied boolean value.void
Sets the specified property to the supplied double value.void
Sets the specified property to the supplied int value.void
Sets the specified property to the supplied long value.void
Sets the specified property to the supplied enum value.void
Sets the specified property to the supplied string value.<E> react.RSet<E>
Exposes the specified property as anRSet
.<E> react.RSet<E>
Exposes the specified property as anRSet
usingimpl
as the concrete set implementation.react.Value<Boolean>
Exposes the specified property as aValue
.react.Value<Double>
Exposes the specified property as aValue
.react.IntValue
Exposes the specified property as anIntValue
.react.Value<Long>
Exposes the specified property as aValue
.<E extends Enum<E>>
react.Value<E>Exposes the specified property as aValue
.react.Value<String>
Exposes the specified property as aValue
.
-
Constructor Details
-
TypedStorage
-
-
Method Details
-
contains
Returns whether the specified key is mapped to some value. -
get
Returns the specified property as a string, returning null if the property does not exist. -
get
Returns the specified property as a string, returning the supplied defautl value if the property does not exist. -
set
Sets the specified property to the supplied string value. -
get
Returns the specified property as an int. If the property does not exist, the default value will be returned. If the property cannot be parsed as an int, an error will be logged and the default value will be returned. -
set
Sets the specified property to the supplied int value. -
get
Returns the specified property as a long. If the property does not exist, the default value will be returned. If the property cannot be parsed as a long, an error will be logged and the default value will be returned. -
set
Sets the specified property to the supplied long value. -
get
Returns the specified property as a double. If the property does not exist, the default value will be returned. If the property cannot be parsed as a double, an error will be logged and the default value will be returned. -
set
Sets the specified property to the supplied double value. -
get
Returns the specified property as a boolean. If the property does not exist, the default value will be returned. Any existing value equal tot
(ignoring case) will be considered true; all others, false. -
set
Sets the specified property to the supplied boolean value. -
get
Returns the specified property as an enum. If the property does not exist, the default value will be returned.- Throws:
NullPointerException
- ifdefval
is null.
-
set
Sets the specified property to the supplied enum value. -
remove
Removes the specified key (and its value) from storage. -
valueFor
Exposes the specified property as aValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
valueFor
Exposes the specified property as anIntValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newIntValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
valueFor
Exposes the specified property as aValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
valueFor
Exposes the specified property as aValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
valueFor
Exposes the specified property as aValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
valueFor
Exposes the specified property as aValue
. The supplied default value will be used if the property has no current value. Updates to the value will be written back to the storage system. Note that each call to this method yields a newValue
and those values will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that value properly. -
setFor
public <E> react.RSet<E> setFor(String key, react.Function<String, E> toFunc, react.Function<E, String> fromFunc) Exposes the specified property as anRSet
. The contents of the set will be encoded as a comma separated string and the suppliedtoFunc
andfromFunc
will be used to convert an individual set item to and from a string. The to and from functions should perform escaping and unescaping of commas if the encoded representation of the items might naturally contain commas.Any modifications to the set will be immediately persisted back to storage. Note that each call to this method yields a new
RSet
and those sets will not coordinate with one another, so the caller must be sure to only call this method once for a given property and share that set properly. Changes to the underlying persistent value that do not take place through the returned set will not be reflected in the set and will be overwritten if the set changes. -
setFor
public <E> react.RSet<E> setFor(String key, react.Function<String, E> toFunc, react.Function<E, String> fromFunc, Set<E> impl) Exposes the specified property as anRSet
usingimpl
as the concrete set implementation. SeesetFor(String,Function,Function)
for more details.
-