static analysis fixes
This commit is contained in:
parent
7348f997f6
commit
ca034dbdae
|
|
@ -39,6 +39,22 @@ import rx.Single;
|
||||||
*/
|
*/
|
||||||
public class PreferenceStore<T> implements Store<String, T> {
|
public class PreferenceStore<T> implements Store<String, T> {
|
||||||
|
|
||||||
|
private static boolean isTypeBoolean(@NonNull final Type type) {
|
||||||
|
return type.equals(Boolean.class) || type.equals(boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTypeInteger(@NonNull final Type type) {
|
||||||
|
return type.equals(Integer.class) || type.equals(int.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTypeFloat(@NonNull final Type type) {
|
||||||
|
return type.equals(Float.class) || type.equals(float.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isTypeLong(@NonNull final Type type) {
|
||||||
|
return type.equals(Long.class) || type.equals(long.class);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final SharedPreferences preferences;
|
private final SharedPreferences preferences;
|
||||||
|
|
||||||
|
|
@ -61,15 +77,15 @@ public class PreferenceStore<T> implements Store<String, T> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storeObjectType.equals(Boolean.class) || storeObjectType.equals(boolean.class)) {
|
if (isTypeBoolean(storeObjectType)) {
|
||||||
preferences.edit().putBoolean(key, (Boolean) storeObject).apply();
|
preferences.edit().putBoolean(key, (Boolean) storeObject).apply();
|
||||||
} else if (storeObjectType.equals(String.class)) {
|
} else if (storeObjectType.equals(String.class)) {
|
||||||
preferences.edit().putString(key, (String) storeObject).apply();
|
preferences.edit().putString(key, (String) storeObject).apply();
|
||||||
} else if (storeObjectType.equals(Integer.class) || storeObjectType.equals(int.class)) {
|
} else if (isTypeInteger(storeObjectType)) {
|
||||||
preferences.edit().putInt(key, (Integer) storeObject).apply();
|
preferences.edit().putInt(key, (Integer) storeObject).apply();
|
||||||
} else if (storeObjectType.equals(Long.class) || storeObjectType.equals(long.class)) {
|
} else if (isTypeLong(storeObjectType)) {
|
||||||
preferences.edit().putLong(key, (Long) storeObject).apply();
|
preferences.edit().putLong(key, (Long) storeObject).apply();
|
||||||
} else if (storeObjectType.equals(Float.class) || storeObjectType.equals(float.class)) {
|
} else if (isTypeFloat(storeObjectType)) {
|
||||||
preferences.edit().putFloat(key, (Float) storeObject).apply();
|
preferences.edit().putFloat(key, (Float) storeObject).apply();
|
||||||
} else {
|
} else {
|
||||||
Lc.assertion("Unsupported type of object " + storeObjectType);
|
Lc.assertion("Unsupported type of object " + storeObjectType);
|
||||||
|
|
@ -87,15 +103,15 @@ public class PreferenceStore<T> implements Store<String, T> {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (storeObjectType.equals(Boolean.class) || storeObjectType.equals(boolean.class)) {
|
if (isTypeBoolean(storeObjectType)) {
|
||||||
return (T) ((Boolean) preferences.getBoolean(key, false));
|
return (T) ((Boolean) preferences.getBoolean(key, false));
|
||||||
} else if (storeObjectType.equals(String.class)) {
|
} else if (storeObjectType.equals(String.class)) {
|
||||||
return (T) (preferences.getString(key, null));
|
return (T) (preferences.getString(key, null));
|
||||||
} else if (storeObjectType.equals(Integer.class) || storeObjectType.equals(int.class)) {
|
} else if (isTypeInteger(storeObjectType)) {
|
||||||
return (T) ((Integer) preferences.getInt(key, 0));
|
return (T) ((Integer) preferences.getInt(key, 0));
|
||||||
} else if (storeObjectType.equals(Long.class) || storeObjectType.equals(long.class)) {
|
} else if (isTypeLong(storeObjectType)) {
|
||||||
return (T) ((Long) preferences.getLong(key, 0L));
|
return (T) ((Long) preferences.getLong(key, 0L));
|
||||||
} else if (storeObjectType.equals(Float.class) || storeObjectType.equals(float.class)) {
|
} else if (isTypeFloat(storeObjectType)) {
|
||||||
return (T) ((Float) preferences.getFloat(key, 0f));
|
return (T) ((Float) preferences.getFloat(key, 0f));
|
||||||
}
|
}
|
||||||
Lc.assertion("Unsupported type of object " + storeObjectType);
|
Lc.assertion("Unsupported type of object " + storeObjectType);
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,7 @@ public final class PreferenceUtils {
|
||||||
public static <T extends Enum<T>> NonNullStorable<String, T, String> enumStorable(@NonNull final String name,
|
public static <T extends Enum<T>> NonNullStorable<String, T, String> enumStorable(@NonNull final String name,
|
||||||
@NonNull final Class<T> enumClass,
|
@NonNull final Class<T> enumClass,
|
||||||
@NonNull final SharedPreferences preferences,
|
@NonNull final SharedPreferences preferences,
|
||||||
final T defaultValue) {
|
@NonNull final T defaultValue) {
|
||||||
return new Storable.Builder<String, T, String>(name, enumClass,
|
return new Storable.Builder<String, T, String>(name, enumClass,
|
||||||
String.class, new PreferenceStore<>(preferences), new EnumToStringConverter<>())
|
String.class, new PreferenceStore<>(preferences), new EnumToStringConverter<>())
|
||||||
.setDefaultValue(defaultValue)
|
.setDefaultValue(defaultValue)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue