Search code examples
javaandroidsnappydb

Default values with SnappyDB


I'm using SnappyDB in my app as a store for some key value pairs. I'm wrapping the DB interface with my own interface with default values in it's api. Example:

String get(String key, String defaultValue);

I noticed the only way to know if a key doesn't exist in the DB is to catch an exception and assume the reason for it was a missing key (which is a wild assumption).

Any ideas on how I could implement the default value feature in a less ugly, more accurate way that won't hide relevant exceptions?

Thanks.


Solution

  • You can use:

    boolean isKeyExist = snappyDB.exists("key");