@Test public void testConvertWrapperListToPrimitiveArray() { List<Integer> integerList = new ArrayList<>(); integerList.add(1); Object reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(integerList, new int[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); List<Long> longList = new ArrayList<>(); longList.add(1l); reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(longList, new long[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); List<Character> characterList = new ArrayList<>(); characterList.add('a'); reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(characterList, new char[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); List<Boolean> booleanList = new ArrayList<>(); booleanList.add(true); reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(booleanList, new boolean[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); List<Float> floatList = new ArrayList<>(); floatList.add(1.0f); reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(floatList, new float[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); List<Double> doubleList = new ArrayList<>(); doubleList.add(1.0d); reuslt = PrimitiveTypeUtils.toWrapperListToPrimitiveArray(doubleList, new double[]{}.getClass()); assertTrue(reuslt.getClass().isArray()); assertTrue(reuslt.getClass().getComponentType().isPrimitive()); }
public static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType) { if (primitiveType.isArray()) { primitiveType = primitiveType.getComponentType(); } if (boolean.class.equals(primitiveType)) { return Booleans.toArray(wrapperList); } else if (float.class.equals(primitiveType)) { return Floats.toArray(wrapperList); } else if (long.class.equals(primitiveType)) { return Longs.toArray(wrapperList); } else if (int.class.equals(primitiveType)) { return Ints.toArray(wrapperList); } else if (short.class.equals(primitiveType)) { return Shorts.toArray(wrapperList); } else if (byte.class.equals(primitiveType)) { return Bytes.toArray(wrapperList); } else if (double.class.equals(primitiveType)) { return Doubles.toArray(wrapperList); } else if (char.class.equals(primitiveType)) { return Chars.toArray(wrapperList); } else { throw new IllegalArgumentException(primitiveType.getName() + " is not a supported primitive type"); } }
PrimitiveTypeUtils { public static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType) { if (primitiveType.isArray()) { primitiveType = primitiveType.getComponentType(); } if (boolean.class.equals(primitiveType)) { return Booleans.toArray(wrapperList); } else if (float.class.equals(primitiveType)) { return Floats.toArray(wrapperList); } else if (long.class.equals(primitiveType)) { return Longs.toArray(wrapperList); } else if (int.class.equals(primitiveType)) { return Ints.toArray(wrapperList); } else if (short.class.equals(primitiveType)) { return Shorts.toArray(wrapperList); } else if (byte.class.equals(primitiveType)) { return Bytes.toArray(wrapperList); } else if (double.class.equals(primitiveType)) { return Doubles.toArray(wrapperList); } else if (char.class.equals(primitiveType)) { return Chars.toArray(wrapperList); } else { throw new IllegalArgumentException(primitiveType.getName() + " is not a supported primitive type"); } } }
PrimitiveTypeUtils { public static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType) { if (primitiveType.isArray()) { primitiveType = primitiveType.getComponentType(); } if (boolean.class.equals(primitiveType)) { return Booleans.toArray(wrapperList); } else if (float.class.equals(primitiveType)) { return Floats.toArray(wrapperList); } else if (long.class.equals(primitiveType)) { return Longs.toArray(wrapperList); } else if (int.class.equals(primitiveType)) { return Ints.toArray(wrapperList); } else if (short.class.equals(primitiveType)) { return Shorts.toArray(wrapperList); } else if (byte.class.equals(primitiveType)) { return Bytes.toArray(wrapperList); } else if (double.class.equals(primitiveType)) { return Doubles.toArray(wrapperList); } else if (char.class.equals(primitiveType)) { return Chars.toArray(wrapperList); } else { throw new IllegalArgumentException(primitiveType.getName() + " is not a supported primitive type"); } }  }
PrimitiveTypeUtils { public static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType) { if (primitiveType.isArray()) { primitiveType = primitiveType.getComponentType(); } if (boolean.class.equals(primitiveType)) { return Booleans.toArray(wrapperList); } else if (float.class.equals(primitiveType)) { return Floats.toArray(wrapperList); } else if (long.class.equals(primitiveType)) { return Longs.toArray(wrapperList); } else if (int.class.equals(primitiveType)) { return Ints.toArray(wrapperList); } else if (short.class.equals(primitiveType)) { return Shorts.toArray(wrapperList); } else if (byte.class.equals(primitiveType)) { return Bytes.toArray(wrapperList); } else if (double.class.equals(primitiveType)) { return Doubles.toArray(wrapperList); } else if (char.class.equals(primitiveType)) { return Chars.toArray(wrapperList); } else { throw new IllegalArgumentException(primitiveType.getName() + " is not a supported primitive type"); } }  static Class<?> toWrapper(final TypeToken<?> primitiveTypeToken); static TypeToken<?> toWrapperTypeToken(final TypeToken<?> primitiveTypeToken); static Class<?> toWrapper(final Class<?> primitiveType); static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType); }
PrimitiveTypeUtils { public static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType) { if (primitiveType.isArray()) { primitiveType = primitiveType.getComponentType(); } if (boolean.class.equals(primitiveType)) { return Booleans.toArray(wrapperList); } else if (float.class.equals(primitiveType)) { return Floats.toArray(wrapperList); } else if (long.class.equals(primitiveType)) { return Longs.toArray(wrapperList); } else if (int.class.equals(primitiveType)) { return Ints.toArray(wrapperList); } else if (short.class.equals(primitiveType)) { return Shorts.toArray(wrapperList); } else if (byte.class.equals(primitiveType)) { return Bytes.toArray(wrapperList); } else if (double.class.equals(primitiveType)) { return Doubles.toArray(wrapperList); } else if (char.class.equals(primitiveType)) { return Chars.toArray(wrapperList); } else { throw new IllegalArgumentException(primitiveType.getName() + " is not a supported primitive type"); } }  static Class<?> toWrapper(final TypeToken<?> primitiveTypeToken); static TypeToken<?> toWrapperTypeToken(final TypeToken<?> primitiveTypeToken); static Class<?> toWrapper(final Class<?> primitiveType); static Object toWrapperListToPrimitiveArray(final List wrapperList, Class<?> primitiveType);  }