@SuppressWarnings("ConstantConditions") @Test public void testSetArrayValueAt() { final String[] array = (String[]) ArrayPreference.createArrayInSize(String.class, 10); for (int i = 0; i < array.length; i++) { ArrayPreference.setArrayValueAt(String[].class, array, i, Integer.toString(i + 1)); assertThat(array[i], is(Integer.toString(i + 1))); } }
@VisibleForTesting static void setArrayValueAt(final Class<?> arrayClass, final Object array, final int index, final Object value) { if (value == null) { Array.set(array, index, null); return; } if (byte[].class.equals(arrayClass) || Byte[].class.equals(arrayClass)) { Array.set(array, index, Byte.valueOf(value.toString())); } else if (char[].class.equals(arrayClass) || Character[].class.equals(arrayClass)) { Array.set(array, index, value.toString().charAt(0)); } else if (short[].class.equals(arrayClass) || Short[].class.equals(arrayClass)) { Array.set(array, index, Short.valueOf(value.toString())); } else if (float[].class.equals(arrayClass) || Float[].class.equals(arrayClass)) { Array.set(array, index, Float.valueOf(value.toString())); } else if (long[].class.equals(arrayClass) || Long[].class.equals(arrayClass)) { Array.set(array, index, Long.valueOf(value.toString())); } else { Array.set(array, index, value); } }
ArrayPreference extends SharedPreference<T> { @VisibleForTesting static void setArrayValueAt(final Class<?> arrayClass, final Object array, final int index, final Object value) { if (value == null) { Array.set(array, index, null); return; } if (byte[].class.equals(arrayClass) || Byte[].class.equals(arrayClass)) { Array.set(array, index, Byte.valueOf(value.toString())); } else if (char[].class.equals(arrayClass) || Character[].class.equals(arrayClass)) { Array.set(array, index, value.toString().charAt(0)); } else if (short[].class.equals(arrayClass) || Short[].class.equals(arrayClass)) { Array.set(array, index, Short.valueOf(value.toString())); } else if (float[].class.equals(arrayClass) || Float[].class.equals(arrayClass)) { Array.set(array, index, Float.valueOf(value.toString())); } else if (long[].class.equals(arrayClass) || Long[].class.equals(arrayClass)) { Array.set(array, index, Long.valueOf(value.toString())); } else { Array.set(array, index, value); } } }
ArrayPreference extends SharedPreference<T> { @VisibleForTesting static void setArrayValueAt(final Class<?> arrayClass, final Object array, final int index, final Object value) { if (value == null) { Array.set(array, index, null); return; } if (byte[].class.equals(arrayClass) || Byte[].class.equals(arrayClass)) { Array.set(array, index, Byte.valueOf(value.toString())); } else if (char[].class.equals(arrayClass) || Character[].class.equals(arrayClass)) { Array.set(array, index, value.toString().charAt(0)); } else if (short[].class.equals(arrayClass) || Short[].class.equals(arrayClass)) { Array.set(array, index, Short.valueOf(value.toString())); } else if (float[].class.equals(arrayClass) || Float[].class.equals(arrayClass)) { Array.set(array, index, Float.valueOf(value.toString())); } else if (long[].class.equals(arrayClass) || Long[].class.equals(arrayClass)) { Array.set(array, index, Long.valueOf(value.toString())); } else { Array.set(array, index, value); } } ArrayPreference(@NonNull final String key, @Nullable final T defValue); }
ArrayPreference extends SharedPreference<T> { @VisibleForTesting static void setArrayValueAt(final Class<?> arrayClass, final Object array, final int index, final Object value) { if (value == null) { Array.set(array, index, null); return; } if (byte[].class.equals(arrayClass) || Byte[].class.equals(arrayClass)) { Array.set(array, index, Byte.valueOf(value.toString())); } else if (char[].class.equals(arrayClass) || Character[].class.equals(arrayClass)) { Array.set(array, index, value.toString().charAt(0)); } else if (short[].class.equals(arrayClass) || Short[].class.equals(arrayClass)) { Array.set(array, index, Short.valueOf(value.toString())); } else if (float[].class.equals(arrayClass) || Float[].class.equals(arrayClass)) { Array.set(array, index, Float.valueOf(value.toString())); } else if (long[].class.equals(arrayClass) || Long[].class.equals(arrayClass)) { Array.set(array, index, Long.valueOf(value.toString())); } else { Array.set(array, index, value); } } 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> { @VisibleForTesting static void setArrayValueAt(final Class<?> arrayClass, final Object array, final int index, final Object value) { if (value == null) { Array.set(array, index, null); return; } if (byte[].class.equals(arrayClass) || Byte[].class.equals(arrayClass)) { Array.set(array, index, Byte.valueOf(value.toString())); } else if (char[].class.equals(arrayClass) || Character[].class.equals(arrayClass)) { Array.set(array, index, value.toString().charAt(0)); } else if (short[].class.equals(arrayClass) || Short[].class.equals(arrayClass)) { Array.set(array, index, Short.valueOf(value.toString())); } else if (float[].class.equals(arrayClass) || Float[].class.equals(arrayClass)) { Array.set(array, index, Float.valueOf(value.toString())); } else if (long[].class.equals(arrayClass) || Long[].class.equals(arrayClass)) { Array.set(array, index, Long.valueOf(value.toString())); } else { Array.set(array, index, value); } } 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);  }