You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modified preference initialization mechanism to ignore the initialization if the preference is already available within the underlying shared preference.
Copy file name to clipboardExpand all lines: PreferenceStore/src/main/java/com/buggysofts/preferencestore/BoundedPreference.java
+18-17Lines changed: 18 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
6
6
/**
7
7
* A preference which with a predefined set of non-null values, and a default value.
8
-
* */
8
+
*/
9
9
10
10
publicclassBoundedPreference<T> {
11
11
privatefinalStringkey;
@@ -16,13 +16,13 @@ public class BoundedPreference<T> {
16
16
/**
17
17
* Create a bounded preference.
18
18
* <br>
19
-
* @param keyName Name of the preference. Should be of the form <b>pref_key_*</b>.
20
-
* @param desc Description of the preference, its context, purpose & usability, and any other important information. This is not going to be used anywhere, the purpose of this is to remind the user what it is for and how to use it.
21
-
* @param allValues All the supported values (by this preference). Each of the items must not be null.
22
-
* @param defaultValueIndex Index of the value that should be used as default.
23
19
*
20
+
* @param keyName Name of the preference. Should be of the form <b>pref_key_*</b>.
21
+
* @param desc Description of the preference, its context, purpose & usability, and any other important information. This is not going to be used anywhere, the purpose of this is to remind the user what it is for and how to use it.
22
+
* @param allValues All the supported values (by this preference). Each of the items must not be null.
23
+
* @param defaultValueIndex Index of the value that should be used as default.
24
24
* @throws RuntimeException if any contract violation is found.
25
-
* */
25
+
*/
26
26
publicBoundedPreference(@NonNullStringkeyName,
27
27
@NonNullStringdesc,
28
28
@NonNullT[] allValues,
@@ -32,62 +32,63 @@ public BoundedPreference(@NonNull String keyName,
32
32
this.allValues = allValues;
33
33
this.defaultValueIndex = defaultValueIndex;
34
34
35
-
if(key == null){
35
+
if(key == null){
36
36
thrownewRuntimeException("Key must not be null.");
37
37
}
38
-
if(allValues == null || allValues.length == 0){
38
+
if(allValues == null || allValues.length == 0){
39
39
thrownewRuntimeException("Empty value list is not allowed.");
40
40
} else {
41
41
for (inti = 0; i < allValues.length; i++) {
42
-
if(allValues[i] == null){
42
+
if(allValues[i] == null){
43
43
thrownewRuntimeException("Preference values can not be null.");
0 commit comments