Class TypedStorage

java.lang.Object
tripleplay.util.TypedStorage

public class TypedStorage extends Object
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

    Constructors
    Constructor
    Description
    TypedStorage(Log log, Storage storage)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns whether the specified key is mapped to some value.
    get(String key)
    Returns the specified property as a string, returning null if the property does not exist.
    boolean
    get(String key, boolean defval)
    Returns the specified property as a boolean.
    double
    get(String key, double defval)
    Returns the specified property as a double.
    int
    get(String key, int defval)
    Returns the specified property as an int.
    long
    get(String key, long defval)
    Returns the specified property as a long.
    <E extends Enum<E>>
    E
    get(String key, E defval)
    Returns the specified property as an enum.
    get(String key, String defval)
    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
    set(String key, boolean value)
    Sets the specified property to the supplied boolean value.
    void
    set(String key, double value)
    Sets the specified property to the supplied double value.
    void
    set(String key, int value)
    Sets the specified property to the supplied int value.
    void
    set(String key, long value)
    Sets the specified property to the supplied long value.
    void
    set(String key, Enum<?> value)
    Sets the specified property to the supplied enum value.
    void
    set(String key, String value)
    Sets the specified property to the supplied string value.
    <E> react.RSet<E>
    setFor(String key, react.Function<String,E> toFunc, react.Function<E,String> fromFunc)
    Exposes the specified property as an RSet.
    <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 an RSet using impl as the concrete set implementation.
    react.Value<Boolean>
    valueFor(String key, boolean defval)
    Exposes the specified property as a Value.
    react.Value<Double>
    valueFor(String key, double defval)
    Exposes the specified property as a Value.
    react.IntValue
    valueFor(String key, int defval)
    Exposes the specified property as an IntValue.
    react.Value<Long>
    valueFor(String key, long defval)
    Exposes the specified property as a Value.
    <E extends Enum<E>>
    react.Value<E>
    valueFor(String key, E defval)
    Exposes the specified property as a Value.
    react.Value<String>
    valueFor(String key, String defval)
    Exposes the specified property as a Value.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TypedStorage

      public TypedStorage(Log log, Storage storage)
  • Method Details

    • contains

      public boolean contains(String key)
      Returns whether the specified key is mapped to some value.
    • get

      public String get(String key)
      Returns the specified property as a string, returning null if the property does not exist.
    • get

      public String get(String key, String defval)
      Returns the specified property as a string, returning the supplied defautl value if the property does not exist.
    • set

      public void set(String key, String value)
      Sets the specified property to the supplied string value.
    • get

      public int get(String key, int defval)
      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

      public void set(String key, int value)
      Sets the specified property to the supplied int value.
    • get

      public long get(String key, long defval)
      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

      public void set(String key, long value)
      Sets the specified property to the supplied long value.
    • get

      public double get(String key, double defval)
      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

      public void set(String key, double value)
      Sets the specified property to the supplied double value.
    • get

      public boolean get(String key, boolean defval)
      Returns the specified property as a boolean. If the property does not exist, the default value will be returned. Any existing value equal to t (ignoring case) will be considered true; all others, false.
    • set

      public void set(String key, boolean value)
      Sets the specified property to the supplied boolean value.
    • get

      public <E extends Enum<E>> E get(String key, E defval)
      Returns the specified property as an enum. If the property does not exist, the default value will be returned.
      Throws:
      NullPointerException - if defval is null.
    • set

      public void set(String key, Enum<?> value)
      Sets the specified property to the supplied enum value.
    • remove

      public void remove(String key)
      Removes the specified key (and its value) from storage.
    • valueFor

      public react.Value<String> valueFor(String key, String defval)
      Exposes the specified property as a Value. 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 new Value 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

      public react.IntValue valueFor(String key, int defval)
      Exposes the specified property as an IntValue. 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 new IntValue 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

      public react.Value<Long> valueFor(String key, long defval)
      Exposes the specified property as a Value. 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 new Value 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

      public react.Value<Double> valueFor(String key, double defval)
      Exposes the specified property as a Value. 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 new Value 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

      public react.Value<Boolean> valueFor(String key, boolean defval)
      Exposes the specified property as a Value. 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 new Value 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

      public <E extends Enum<E>> react.Value<E> valueFor(String key, E defval)
      Exposes the specified property as a Value. 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 new Value 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 an RSet. The contents of the set will be encoded as a comma separated string and the supplied toFunc and fromFunc 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 an RSet using impl as the concrete set implementation. See setFor(String,Function,Function) for more details.