orhanobut / hawk

✔️ Secure, simple key-value storage for Android
Apache License 2.0
3.98k stars 388 forks source link

set default value like sharedPreferences #206

Closed sajjadmohammadi closed 6 years ago

sajjadmohammadi commented 6 years ago

Hi guys. how can set default value like sharedPreferences? if Hawk does not have this feature, can cause Repeats the code. For example, block the commands "commands_one" and "commands_two": "commands_two" is repeat in following code

if(Hawk.contains(key)){ if(Hawk.get(key).equals("myValue")){ //commands_one }else{ //commands_two } }else{ //commands_two }

hehpollon commented 6 years ago

@sajjadmohammadi From 'repeats the code' perspective, default value is not necessary. It can be solved by logic.

if(Hawk.contains(key) && Hawk.get(key).equals("myValue")) {
    // commands_one
} else {
    // commands_two
}
orhanobut commented 6 years ago

Hawk has an overloaded get method which accepts default value.

Hawk.get(key, defaultValue). Does this help?

orhanobut commented 6 years ago

Closing this issue for now, we can definitely re-open if needed