/** * Wraps a given array with a <code>{@link ArrayWrapperList}</code> * * @param array the array to wrap. * @return the wrapped array or {@code null} if the given array was already {@code null}. * @throws IllegalArgumentException if the {@code array} is not an array. */ public static ArrayWrapperList wrap(Object array) { if (array == null) { return null; } checkArgument(array.getClass().isArray(), "The object to wrap should be an array"); return new ArrayWrapperList(array); }
/** * {@inheritDoc} */ @Override public Object get(int index) { checkIsInRange(index); return Array.get(array, index); }
@SuppressWarnings("unchecked") private static Comparable<Object>[] arrayOfComparableItems(Object array) { ArrayWrapperList arrayWrapperList = wrap(array); Comparable<Object>[] arrayOfComparableItems = new Comparable[arrayWrapperList.size()]; for (int i = 0; i < arrayWrapperList.size(); i++) { arrayOfComparableItems[i] = (Comparable<Object>) arrayWrapperList.get(i); } return arrayOfComparableItems; }
private static void assertThatArrayComponentTypeIsSortable(AssertionInfo info, Failures failures, Object array) { ArrayWrapperList arrayAsList = wrap(array); Class<?> arrayComponentType = arrayAsList.getComponentType(); if (arrayComponentType.isPrimitive()) return; if (!Comparable.class.isAssignableFrom(arrayComponentType)) throw failures.failure(info, shouldHaveMutuallyComparableElements(array)); }
/** * Convert the given group (which is either an array or a Collection) to a List. * * @param group the group to convert * @return the corresponding List * @throws IllegalArgumentException if group can't be converted to a List */ @SuppressWarnings("unchecked") private static List<?> groupAsList(Object group) { if (group.getClass().isArray()) { return wrap(group); } else if (group instanceof Collection<?>) { return new ArrayList<>((Collection<Object>) group); } throw new IllegalArgumentException("Parameter should be an array or a collection but was " + group); }
private static void assertThatArrayComponentTypeIsSortable(AssertionInfo info, Failures failures, Object array) { ArrayWrapperList arrayAsList = wrap(array); Class<?> arrayComponentType = arrayAsList.getComponentType(); if (arrayComponentType.isPrimitive()) return; if (!Comparable.class.isAssignableFrom(arrayComponentType)) throw failures.failure(info, shouldHaveMutuallyComparableElements(array)); }
/** * Extracts the values of the property (specified previously in <code>{@link #extractProperty(String)}</code>) from the elements * of the given array. * @param array the given array. * @return the values of the previously specified property extracted from the given array. * @throws IntrospectionError if an element in the given array does not have a property with a matching name. */ public List<T> from(Object[] array) { return propertySupport.propertyValues(propertyName, propertyType, wrap(array)); } }
@SuppressWarnings("unchecked") private static Comparable<Object>[] arrayOfComparableItems(Object array) { ArrayWrapperList arrayWrapperList = wrap(array); Comparable<Object>[] arrayOfComparableItems = new Comparable[arrayWrapperList.size()]; for (int i = 0; i < arrayWrapperList.size(); i++) { arrayOfComparableItems[i] = (Comparable<Object>) arrayWrapperList.get(i); } return arrayOfComparableItems; }
private static void assertThatArrayComponentTypeIsSortable(AssertionInfo info, Failures failures, Object array) { ArrayWrapperList arrayAsList = wrap(array); Class<?> arrayComponentType = arrayAsList.getComponentType(); if (arrayComponentType.isPrimitive()) return; if (!Comparable.class.isAssignableFrom(arrayComponentType)) throw failures.failure(info, shouldHaveMutuallyComparableElements(array)); }
/** * Returns a <code>{@link List}</code> containing the values of the given field name, from the elements of the given * <code>{@link Iterable}</code>. If the given {@code Iterable} is empty or {@code null}, this method will return an * empty {@code List}. This method supports nested fields (e.g. "address.street.number"). * * @param <T> the type of the extracted elements. * @param fieldName the name of the field. It may be a nested field. It is left to the clients to validate for * {@code null} or empty. * @param fieldClass the expected type of the given field. * @param target the given {@code Iterable}. * @return an {@code Iterable} containing the values of the given field name, from the elements of the given * {@code Iterable}. * @throws IntrospectionError if an element in the given {@code Iterable} does not have a field with a matching name. */ public <T> List<T> fieldValues(String fieldName, Class<T> fieldClass, Object[] target) { return fieldValues(fieldName, fieldClass, wrap(target)); }
/** * {@inheritDoc} */ @Override public Object get(int index) { checkIsInRange(index); return Array.get(array, index); }
/** * Wraps a given array with a <code>{@link ArrayWrapperList}</code> * * @param array the array to wrap. * @return the wrapped array or {@code null} if the given array was already {@code null}. * @throws IllegalArgumentException if the {@code array} is not an array. */ public static ArrayWrapperList wrap(Object array) { if (array == null) { return null; } checkArgument(array.getClass().isArray(), "The object to wrap should be an array"); return new ArrayWrapperList(array); }
@SuppressWarnings("unchecked") private static Comparable<Object>[] arrayOfComparableItems(Object array) { ArrayWrapperList arrayWrapperList = wrap(array); Comparable<Object>[] arrayOfComparableItems = new Comparable[arrayWrapperList.size()]; for (int i = 0; i < arrayWrapperList.size(); i++) { arrayOfComparableItems[i] = (Comparable<Object>) arrayWrapperList.get(i); } return arrayOfComparableItems; }
/** * Convert the given group (which is either an array or a Collection) to a List. * * @param group the group to convert * @return the corresponding List * @throws IllegalArgumentException if group can't be converted to a List */ @SuppressWarnings("unchecked") private static List<?> groupAsList(Object group) { if (group.getClass().isArray()) { return wrap(group); } else if (group instanceof Collection<?>) { return new ArrayList<>((Collection<Object>) group); } throw new IllegalArgumentException("Parameter should be an array or a collection but was " + group); }
/** * {@inheritDoc} */ @Override public Object get(int index) { checkIsInRange(index); return Array.get(array, index); }
/** * Wraps a given array with a <code>{@link ArrayWrapperList}</code> * * @param array the array to wrap. * @return the wrapped array or {@code null} if the given array was already {@code null}. * @throws IllegalArgumentException if the {@code array} is not an array. */ public static ArrayWrapperList wrap(Object array) { if (array == null) { return null; } if (!array.getClass().isArray()) { throw new IllegalArgumentException("The object to wrap should be an array"); } return new ArrayWrapperList(array); }
/** * Extracts the values of the property (specified previously in <code>{@link #extractProperty(String)}</code>) from the elements * of the given array. * @param array the given array. * @return the values of the previously specified property extracted from the given array. * @throws IntrospectionError if an element in the given array does not have a property with a matching name. */ public List<T> from(Object[] array) { return propertySupport.propertyValues(propertyName, propertyType, wrap(array)); } }