/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array an int array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Integer> toList(int[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a double array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Double> toList(double[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a byte array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Byte> toList(byte[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a boolean array * @return a list containing the contents of this array. * @since 1.6.0 */ @SuppressWarnings("unchecked") public static List<Boolean> toList(boolean[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a short array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Short> toList(short[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a float array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Float> toList(float[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a char array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Character> toList(char[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a List of the same size, with each element * added to the list. * * @param array a long array * @return a list containing the contents of this array. * @since 1.0 */ @SuppressWarnings("unchecked") public static List<Long> toList(long[] array) { return DefaultTypeTransformation.primitiveArrayToList(array); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a short array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Short> toSet(short[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a float array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Float> toSet(float[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a char array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Character> toSet(char[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a double array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Double> toSet(double[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a boolean array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Boolean> toSet(boolean[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
public static Collection arrayAsCollection(Object value) { if (value.getClass().getComponentType().isPrimitive()) { return primitiveArrayToList(value); } return arrayAsCollection((Object[]) value); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array an int array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Integer> toSet(int[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a byte array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Byte> toSet(byte[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Converts this array to a Set, with each unique element * added to the set. * * @param array a long array * @return a set containing the unique contents of this array. * @since 1.8.0 */ @SuppressWarnings("unchecked") public static Set<Long> toSet(long[] array) { return toSet(DefaultTypeTransformation.primitiveArrayToList(array)); }
/** * Allows conversion of arrays into a mutable List * * @param array an array * @return the array as a List */ public static List primitiveArrayToList(Object array) { int size = Array.getLength(array); List list = new ArrayList(size); for (int i = 0; i < size; i++) { Object item = Array.get(array, i); if (item != null && item.getClass().isArray() && item.getClass().getComponentType().isPrimitive()) { item = primitiveArrayToList(item); } list.add(item); } return list; }
public static Object[] despreadList(Object[] args, Object[] spreads, int[] positions) { List ret = new ArrayList(); int argsPos = 0; int spreadPos = 0; for (int pos = 0; pos < positions.length; pos++) { for (; argsPos < positions[pos]; argsPos++) { ret.add(args[argsPos]); } Object value = spreads[spreadPos]; if (value == null) { ret.add(null); } else if (value instanceof List) { ret.addAll((List) value); } else if (value.getClass().isArray()) { ret.addAll(DefaultTypeTransformation.primitiveArrayToList(value)); } else { String error = "cannot spread the type " + value.getClass().getName() + " with value " + value; if (value instanceof Map) { error += ", did you mean to use the spread-map operator instead?"; } throw new IllegalArgumentException(error); } spreadPos++; } for (; argsPos < args.length; argsPos++) { ret.add(args[argsPos]); } return ret.toArray(); }
left = primitiveArrayToList(left); right = primitiveArrayToList(right);