@Test public void testResolveArrayClass() { assertEquals(boolean[].class, ArrayPreference.resolveArrayClass(new boolean[]{true})); assertEquals(byte[].class, ArrayPreference.resolveArrayClass(new byte[]{0})); assertEquals(char[].class, ArrayPreference.resolveArrayClass(new char[]{0})); assertEquals(short[].class, ArrayPreference.resolveArrayClass(new short[]{2})); assertEquals(int[].class, ArrayPreference.resolveArrayClass(new int[]{1})); assertEquals(float[].class, ArrayPreference.resolveArrayClass(new float[]{1.5f})); assertEquals(long[].class, ArrayPreference.resolveArrayClass(new long[]{198L})); assertEquals(double[].class, ArrayPreference.resolveArrayClass(new double[]{15D})); assertEquals(Boolean[].class, ArrayPreference.resolveArrayClass(new Boolean[]{true, null})); assertEquals(Byte[].class, ArrayPreference.resolveArrayClass(new Byte[]{0, null})); assertEquals(Short[].class, ArrayPreference.resolveArrayClass(new Short[]{2, null})); assertEquals(Integer[].class, ArrayPreference.resolveArrayClass(new Integer[]{1, null})); assertEquals(Float[].class, ArrayPreference.resolveArrayClass(new Float[]{1.5f, null})); assertEquals(Long[].class, ArrayPreference.resolveArrayClass(new Long[]{198L, null})); assertEquals(Double[].class, ArrayPreference.resolveArrayClass(new Double[]{15D, null})); assertEquals(String[].class, ArrayPreference.resolveArrayClass(new String[]{"", null})); assertEquals(null, ArrayPreference.resolveArrayClass(new Date[0])); }
static Class<?> resolveArrayClass(final Object array) { if (array instanceof boolean[]) { return boolean[].class; } else if (array instanceof byte[]) { return byte[].class; } else if (array instanceof char[]) { return char[].class; } else if (array instanceof short[]) { return short[].class; } else if (array instanceof int[]) { return int[].class; } else if (array instanceof float[]) { return float[].class; } else if (array instanceof long[]) { return long[].class; } else if (array instanceof double[]) { return double[].class; } else if (array instanceof Byte[]) { return Byte[].class; } else if (array instanceof Character[]) { return Character[].class; } else if (array instanceof Short[]) { return Short[].class; } else if (array instanceof Integer[]) { return Integer[].class; } else if (array instanceof Float[]) { return Float[].class; } else if (array instanceof Long[]) { return Long[].class; } else if (array instanceof Double[]) { return Double[].class; } else if (array instanceof Boolean[]) { return Boolean[].class; } else if (array instanceof String[]) { return String[].class; } return null; }
ArrayPreference extends SharedPreference<T> { static Class<?> resolveArrayClass(final Object array) { if (array instanceof boolean[]) { return boolean[].class; } else if (array instanceof byte[]) { return byte[].class; } else if (array instanceof char[]) { return char[].class; } else if (array instanceof short[]) { return short[].class; } else if (array instanceof int[]) { return int[].class; } else if (array instanceof float[]) { return float[].class; } else if (array instanceof long[]) { return long[].class; } else if (array instanceof double[]) { return double[].class; } else if (array instanceof Byte[]) { return Byte[].class; } else if (array instanceof Character[]) { return Character[].class; } else if (array instanceof Short[]) { return Short[].class; } else if (array instanceof Integer[]) { return Integer[].class; } else if (array instanceof Float[]) { return Float[].class; } else if (array instanceof Long[]) { return Long[].class; } else if (array instanceof Double[]) { return Double[].class; } else if (array instanceof Boolean[]) { return Boolean[].class; } else if (array instanceof String[]) { return String[].class; } return null; } }
ArrayPreference extends SharedPreference<T> { static Class<?> resolveArrayClass(final Object array) { if (array instanceof boolean[]) { return boolean[].class; } else if (array instanceof byte[]) { return byte[].class; } else if (array instanceof char[]) { return char[].class; } else if (array instanceof short[]) { return short[].class; } else if (array instanceof int[]) { return int[].class; } else if (array instanceof float[]) { return float[].class; } else if (array instanceof long[]) { return long[].class; } else if (array instanceof double[]) { return double[].class; } else if (array instanceof Byte[]) { return Byte[].class; } else if (array instanceof Character[]) { return Character[].class; } else if (array instanceof Short[]) { return Short[].class; } else if (array instanceof Integer[]) { return Integer[].class; } else if (array instanceof Float[]) { return Float[].class; } else if (array instanceof Long[]) { return Long[].class; } else if (array instanceof Double[]) { return Double[].class; } else if (array instanceof Boolean[]) { return Boolean[].class; } else if (array instanceof String[]) { return String[].class; } return null; } ArrayPreference(@NonNull final String key, @Nullable final T defValue); }
ArrayPreference extends SharedPreference<T> { static Class<?> resolveArrayClass(final Object array) { if (array instanceof boolean[]) { return boolean[].class; } else if (array instanceof byte[]) { return byte[].class; } else if (array instanceof char[]) { return char[].class; } else if (array instanceof short[]) { return short[].class; } else if (array instanceof int[]) { return int[].class; } else if (array instanceof float[]) { return float[].class; } else if (array instanceof long[]) { return long[].class; } else if (array instanceof double[]) { return double[].class; } else if (array instanceof Byte[]) { return Byte[].class; } else if (array instanceof Character[]) { return Character[].class; } else if (array instanceof Short[]) { return Short[].class; } else if (array instanceof Integer[]) { return Integer[].class; } else if (array instanceof Float[]) { return Float[].class; } else if (array instanceof Long[]) { return Long[].class; } else if (array instanceof Double[]) { return Double[].class; } else if (array instanceof Boolean[]) { return Boolean[].class; } else if (array instanceof String[]) { return String[].class; } return null; } ArrayPreference(@NonNull final String key, @Nullable final T defValue); @CheckResult static boolean putIntoPreferences(@NonNull final SharedPreferences preferences, @NonNull final String key, @Nullable final Object value); @SuppressWarnings("unchecked") @Nullable static A getFromPreferences(@NonNull final SharedPreferences preferences, @NonNull final String key, @Nullable final Object defValue); }
ArrayPreference extends SharedPreference<T> { static Class<?> resolveArrayClass(final Object array) { if (array instanceof boolean[]) { return boolean[].class; } else if (array instanceof byte[]) { return byte[].class; } else if (array instanceof char[]) { return char[].class; } else if (array instanceof short[]) { return short[].class; } else if (array instanceof int[]) { return int[].class; } else if (array instanceof float[]) { return float[].class; } else if (array instanceof long[]) { return long[].class; } else if (array instanceof double[]) { return double[].class; } else if (array instanceof Byte[]) { return Byte[].class; } else if (array instanceof Character[]) { return Character[].class; } else if (array instanceof Short[]) { return Short[].class; } else if (array instanceof Integer[]) { return Integer[].class; } else if (array instanceof Float[]) { return Float[].class; } else if (array instanceof Long[]) { return Long[].class; } else if (array instanceof Double[]) { return Double[].class; } else if (array instanceof Boolean[]) { return Boolean[].class; } else if (array instanceof String[]) { return String[].class; } return null; } ArrayPreference(@NonNull final String key, @Nullable final T defValue); @CheckResult static boolean putIntoPreferences(@NonNull final SharedPreferences preferences, @NonNull final String key, @Nullable final Object value); @SuppressWarnings("unchecked") @Nullable static A getFromPreferences(@NonNull final SharedPreferences preferences, @NonNull final String key, @Nullable final Object defValue);  }