diff options
author | Camil Staps | 2015-04-15 23:01:38 +0200 |
---|---|---|
committer | Camil Staps | 2015-04-15 23:01:38 +0200 |
commit | 3747e177b9b8a00ea8350c4714ed16f3dc33e046 (patch) | |
tree | a0ede7e36e5d6bee5b15055da34526a1998f4ef0 /app | |
parent | javadoc DatedString (diff) |
javadoc DatedStringPreferenceSet
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/com/camilstaps/common/DatedStringPreferenceSet.java | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/app/src/main/java/com/camilstaps/common/DatedStringPreferenceSet.java b/app/src/main/java/com/camilstaps/common/DatedStringPreferenceSet.java index 4e3e449..93db51e 100644 --- a/app/src/main/java/com/camilstaps/common/DatedStringPreferenceSet.java +++ b/app/src/main/java/com/camilstaps/common/DatedStringPreferenceSet.java @@ -12,10 +12,18 @@ import java.util.Iterator; import java.util.Set; /** - * Created by camilstaps on 11-4-15. + * A set of DatedStrings to store in SharedPreferences + * @author Camil Staps */ public class DatedStringPreferenceSet { + /** + * Get a Set from the SharedPreferences + * @param context + * @param key the SharedPreferences key + * @param type the type of DatedString to cast to + * @return the set + */ public static Set<Object> get(Context context, String key, Class type) { Set<Object> set = new HashSet<>(); for (String s : PreferenceManager.getDefaultSharedPreferences(context).getStringSet(key, new HashSet<String>())) { @@ -30,6 +38,12 @@ public class DatedStringPreferenceSet { return set; } + /** + * Put a Set to the SharedPreferences + * @param context + * @param key the SharedPreferences key + * @param set + */ public static void put(Context context, String key, Set<DatedString> set) { SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); Set<String> putSet = new HashSet<>(); @@ -40,12 +54,24 @@ public class DatedStringPreferenceSet { editor.apply(); } + /** + * Add one DatedString to a set + * @param context + * @param key the SharedPreferences key + * @param object the DatedString to add + */ public static void add(Context context, String key, DatedString object) { Set<DatedString> set = (Set) DatedStringPreferenceSet.get(context, key, DatedString.class); set.add(object); DatedStringPreferenceSet.put(context, key, (Set) set); } + /** + * Remove all DatedStrings with the same Date as the given DatedString, and put this new DatedString if any object was removed + * @param context + * @param key the SharedPreferences key + * @param object the object to 'update' + */ public static void update(Context context, String key, DatedString object) { Set<DatedString> set = (Set) get(context, key, object.getClass()); Iterator<DatedString> iterator = set.iterator(); @@ -63,6 +89,13 @@ public class DatedStringPreferenceSet { put(context, key, set); } + /** + * Check if a certain Date exists as the Date of a DatedString in some set + * @param context + * @param key the SharedPreferences key + * @param date the Date + * @return + */ public static boolean has(Context context, String key, Date date) { Set<DatedString> set = (Set) get(context, key, DatedString.class); for (DatedString item : set) { @@ -73,6 +106,14 @@ public class DatedStringPreferenceSet { return false; } + /** + * Update the object if it already exists, or add it if it doesn't + * @see #update(android.content.Context, String, DatedString) + * @see #add(android.content.Context, String, DatedString) + * @param context + * @param key the SharedPreferences key + * @param object the object to 'update' or add + */ public static void updateOrAdd(Context context, String key, DatedString object) { if (has(context, key, object.getDate())) { update(context, key, object); @@ -81,10 +122,21 @@ public class DatedStringPreferenceSet { } } + /** + * Remove all elements of a set + * @param context + * @param key the SharedPreferences key + */ public static void clear(Context context, String key) { put(context, key, new HashSet<DatedString>()); } + /** + * Remove all elements with a certain Date from a set + * @param context + * @param key the SharedPreferences key + * @param date the Date + */ public static void remove(Context context, String key, Date date) { Set<DatedString> set = (Set) get(context, key, DatedString.class); Iterator<DatedString> iterator = set.iterator(); |