/** * 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); }
/** * 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)); } }
/** * 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)); }
/** * 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); }
/** * 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)); } }
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)); }
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)); }
@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; }
@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; }
void assertDoesNotHaveDuplicates(AssertionInfo info, Failures failures, Object array) { assertNotNull(info, array); ArrayWrapperList wrapped = wrap(array); Iterable<?> duplicates = comparisonStrategy.duplicatesFrom(wrapped); if (!isNullOrEmpty(duplicates)) throw failures.failure(info, shouldNotHaveDuplicates(array, duplicates, comparisonStrategy)); }
void assertDoesNotHaveDuplicates(AssertionInfo info, Failures failures, Object array) { assertNotNull(info, array); ArrayWrapperList wrapped = wrap(array); Iterable<?> duplicates = comparisonStrategy.duplicatesFrom(wrapped); if (!isNullOrEmpty(duplicates)) throw failures.failure(info, shouldNotHaveDuplicates(array, duplicates, comparisonStrategy)); }
/** * 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)); } }
/** * 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<?>) { List<Object> asList = new ArrayList<Object>(); asList.addAll(((Collection<Object>) group)); return asList; } throw new IllegalArgumentException("Parameter should be an array or a collection but was " + group); }
/** * 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 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)); }
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)); }
@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; }
void assertDoesNotHaveDuplicates(AssertionInfo info, Failures failures, Object array) { assertNotNull(info, array); ArrayWrapperList wrapped = wrap(array); Iterable<?> duplicates = comparisonStrategy.duplicatesFrom(wrapped); if (!isNullOrEmpty(duplicates)) throw failures.failure(info, shouldNotHaveDuplicates(array, duplicates, comparisonStrategy)); }