@SuppressWarnings("ConstantConditions") @Test public void testCreateArrayInSize() { assertThat(ArrayPreference.createArrayInSize(Date.class, 1), is(nullValue())); assertThat(((boolean[]) ArrayPreference.createArrayInSize(boolean.class, 1)).length, is(1)); assertThat(((byte[]) ArrayPreference.createArrayInSize(byte.class, 2)).length, is(2)); assertThat(((char[]) ArrayPreference.createArrayInSize(char.class, 3)).length, is(3)); assertThat(((short[]) ArrayPreference.createArrayInSize(short.class, 4)).length, is(4)); assertThat(((int[]) ArrayPreference.createArrayInSize(int.class, 5)).length, is(5)); assertThat(((float[]) ArrayPreference.createArrayInSize(float.class, 6)).length, is(6)); assertThat(((long[]) ArrayPreference.createArrayInSize(long.class, 7)).length, is(7)); assertThat(((double[]) ArrayPreference.createArrayInSize(double.class, 8)).length, is(8)); assertThat(((Boolean[]) ArrayPreference.createArrayInSize(Boolean.class, 1)).length, is(1)); assertThat(((Byte[]) ArrayPreference.createArrayInSize(Byte.class, 2)).length, is(2)); assertThat(((Character[]) ArrayPreference.createArrayInSize(Character.class, 3)).length, is(3)); assertThat(((Short[]) ArrayPreference.createArrayInSize(Short.class, 4)).length, is(4)); assertThat(((Integer[]) ArrayPreference.createArrayInSize(Integer.class, 5)).length, is(5)); assertThat(((Float[]) ArrayPreference.createArrayInSize(Float.class, 6)).length, is(6)); assertThat(((Long[]) ArrayPreference.createArrayInSize(Long.class, 7)).length, is(7)); assertThat(((Double[]) ArrayPreference.createArrayInSize(Double.class, 8)).length, is(8)); }
static Object createArrayInSize(final Class<?> componentClass, final int size) { if (byte.class.equals(componentClass)) { return new byte[size]; } else if (char.class.equals(componentClass)) { return new char[size]; } else if (short.class.equals(componentClass)) { return new short[size]; } else if (int.class.equals(componentClass)) { return new int[size]; } else if (float.class.equals(componentClass)) { return new float[size]; } else if (long.class.equals(componentClass)) { return new long[size]; } else if (double.class.equals(componentClass)) { return new double[size]; } else if (boolean.class.equals(componentClass)) { return new boolean[size]; } else if (Character.class.equals(componentClass)) { return new Character[size]; } else if (Byte.class.equals(componentClass)) { return new Byte[size]; } else if (Short.class.equals(componentClass)) { return new Short[size]; } else if (Integer.class.equals(componentClass)) { return new Integer[size]; } else if (Float.class.equals(componentClass)) { return new Float[size]; } else if (Long.class.equals(componentClass)) { return new Long[size]; } else if (Double.class.equals(componentClass)) { return new Double[size]; } else if (Boolean.class.equals(componentClass)) { return new Boolean[size]; } else if (String.class.equals(componentClass)) { return new String[size]; } return null; }
ArrayPreference extends SharedPreference<T> { static Object createArrayInSize(final Class<?> componentClass, final int size) { if (byte.class.equals(componentClass)) { return new byte[size]; } else if (char.class.equals(componentClass)) { return new char[size]; } else if (short.class.equals(componentClass)) { return new short[size]; } else if (int.class.equals(componentClass)) { return new int[size]; } else if (float.class.equals(componentClass)) { return new float[size]; } else if (long.class.equals(componentClass)) { return new long[size]; } else if (double.class.equals(componentClass)) { return new double[size]; } else if (boolean.class.equals(componentClass)) { return new boolean[size]; } else if (Character.class.equals(componentClass)) { return new Character[size]; } else if (Byte.class.equals(componentClass)) { return new Byte[size]; } else if (Short.class.equals(componentClass)) { return new Short[size]; } else if (Integer.class.equals(componentClass)) { return new Integer[size]; } else if (Float.class.equals(componentClass)) { return new Float[size]; } else if (Long.class.equals(componentClass)) { return new Long[size]; } else if (Double.class.equals(componentClass)) { return new Double[size]; } else if (Boolean.class.equals(componentClass)) { return new Boolean[size]; } else if (String.class.equals(componentClass)) { return new String[size]; } return null; } }
ArrayPreference extends SharedPreference<T> { static Object createArrayInSize(final Class<?> componentClass, final int size) { if (byte.class.equals(componentClass)) { return new byte[size]; } else if (char.class.equals(componentClass)) { return new char[size]; } else if (short.class.equals(componentClass)) { return new short[size]; } else if (int.class.equals(componentClass)) { return new int[size]; } else if (float.class.equals(componentClass)) { return new float[size]; } else if (long.class.equals(componentClass)) { return new long[size]; } else if (double.class.equals(componentClass)) { return new double[size]; } else if (boolean.class.equals(componentClass)) { return new boolean[size]; } else if (Character.class.equals(componentClass)) { return new Character[size]; } else if (Byte.class.equals(componentClass)) { return new Byte[size]; } else if (Short.class.equals(componentClass)) { return new Short[size]; } else if (Integer.class.equals(componentClass)) { return new Integer[size]; } else if (Float.class.equals(componentClass)) { return new Float[size]; } else if (Long.class.equals(componentClass)) { return new Long[size]; } else if (Double.class.equals(componentClass)) { return new Double[size]; } else if (Boolean.class.equals(componentClass)) { return new Boolean[size]; } else if (String.class.equals(componentClass)) { return new String[size]; } return null; } ArrayPreference(@NonNull final String key, @Nullable final T defValue); }
ArrayPreference extends SharedPreference<T> { static Object createArrayInSize(final Class<?> componentClass, final int size) { if (byte.class.equals(componentClass)) { return new byte[size]; } else if (char.class.equals(componentClass)) { return new char[size]; } else if (short.class.equals(componentClass)) { return new short[size]; } else if (int.class.equals(componentClass)) { return new int[size]; } else if (float.class.equals(componentClass)) { return new float[size]; } else if (long.class.equals(componentClass)) { return new long[size]; } else if (double.class.equals(componentClass)) { return new double[size]; } else if (boolean.class.equals(componentClass)) { return new boolean[size]; } else if (Character.class.equals(componentClass)) { return new Character[size]; } else if (Byte.class.equals(componentClass)) { return new Byte[size]; } else if (Short.class.equals(componentClass)) { return new Short[size]; } else if (Integer.class.equals(componentClass)) { return new Integer[size]; } else if (Float.class.equals(componentClass)) { return new Float[size]; } else if (Long.class.equals(componentClass)) { return new Long[size]; } else if (Double.class.equals(componentClass)) { return new Double[size]; } else if (Boolean.class.equals(componentClass)) { return new Boolean[size]; } else if (String.class.equals(componentClass)) { return new String[size]; } 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 Object createArrayInSize(final Class<?> componentClass, final int size) { if (byte.class.equals(componentClass)) { return new byte[size]; } else if (char.class.equals(componentClass)) { return new char[size]; } else if (short.class.equals(componentClass)) { return new short[size]; } else if (int.class.equals(componentClass)) { return new int[size]; } else if (float.class.equals(componentClass)) { return new float[size]; } else if (long.class.equals(componentClass)) { return new long[size]; } else if (double.class.equals(componentClass)) { return new double[size]; } else if (boolean.class.equals(componentClass)) { return new boolean[size]; } else if (Character.class.equals(componentClass)) { return new Character[size]; } else if (Byte.class.equals(componentClass)) { return new Byte[size]; } else if (Short.class.equals(componentClass)) { return new Short[size]; } else if (Integer.class.equals(componentClass)) { return new Integer[size]; } else if (Float.class.equals(componentClass)) { return new Float[size]; } else if (Long.class.equals(componentClass)) { return new Long[size]; } else if (Double.class.equals(componentClass)) { return new Double[size]; } else if (Boolean.class.equals(componentClass)) { return new Boolean[size]; } else if (String.class.equals(componentClass)) { return new String[size]; } 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);  }