@SuppressWarnings("unchecked") private static <T, U> void testConversion(U expected, T from, Class<U> toClass) { if (from != null) { assertEquals(from, Convert.convert(from, Object.class)); assertEquals(from, Convert.convert(from, from.getClass())); } U conv1 = Convert.convert(from, toClass); assertEquals(expected, conv1); if (toClass.isPrimitive()) { assertTrue(wrapper(toClass).isInstance(conv1)); return; } else if (expected == null) { assertNull(conv1); } else { assertTrue(toClass.isInstance(conv1)); } Class<?> toArrayClass = Array.newInstance(toClass, 0).getClass(); Object[] conv2 = Convert.convert(new Object[] {from, from}, new Class[] {toClass, toClass}); U[] conv3 = (U[]) Convert.convert(new Object[] {from, from}, toClass); U[] conv4 = (U[]) Convert.convertArray(new Object[] {from, from}, toClass); U[] conv5 = (U[]) Convert.convertArray(new Object[] {from, from}, toArrayClass); assertEquals(2, conv2.length); assertEquals(2, conv3.length); assertEquals(2, conv4.length); assertEquals(2, conv5.length); assertEquals(expected, conv2[0]); assertEquals(expected, conv2[1]); assertEquals(expected, conv3[0]); assertEquals(expected, conv3[1]); assertEquals(expected, conv4[0]); assertEquals(expected, conv4[1]); assertEquals(expected, conv5[0]); assertEquals(expected, conv5[1]); assertTrue(Object[].class.isInstance(conv2)); assertTrue(toArrayClass.isInstance(conv3)); assertTrue(toArrayClass.isInstance(conv4)); assertTrue(toArrayClass.isInstance(conv5)); }
@SuppressWarnings("cast") @Override public final <T, U> U[] intoArray(Field<T> field, Converter<? super T, U> converter) { return (U[]) Convert.convertArray(intoArray(field), converter); }
@SuppressWarnings("unchecked") @Override public final <T> T[] intoArray(Field<?> field, Class<? extends T> type) { return (T[]) Convert.convertArray(intoArray(field), type); }
@SuppressWarnings("cast") @Override public final <U> U[] intoArray(String fieldName, Converter<?, U> converter) { return (U[]) Convert.convertArray(intoArray(fieldName), converter); }