private Filters(Iterable<E> iterable) { this.initialIterable = iterable; // copy list to avoid modifying iterable this.filteredIterable = newArrayList(iterable); }
@Test public void selectByQuery_with_empty_list_of_keys_returns_all() { insertOrganization(ORGANIZATION_DTO_1); insertOrganization(ORGANIZATION_DTO_2); OrganizationQuery organizationQuery = newOrganizationQueryBuilder().setKeys(Lists.emptyList()).build(); assertThat(underTest.selectByQuery(dbSession, organizationQuery, forPage(1).andSize(10))) .extracting(OrganizationDto::getUuid) .containsOnly(ORGANIZATION_DTO_1.getUuid(), ORGANIZATION_DTO_2.getUuid()); }
/** * Asserts that the given object has null fields except the given ones. * * @param <A> the actual type. * @param info contains information about the assertion. * @param actual the given object. * @param propertiesOrFieldsToIgnore the fields to ignore in comparison. * @throws AssertionError is actual is {@code null}. * @throws AssertionError if some of the fields of the actual object are not null. */ public <A> void assertHasAllNullFieldsOrPropertiesExcept(AssertionInfo info, A actual, String... propertiesOrFieldsToIgnore) { assertNotNull(info, actual); Set<Field> declaredFields = getDeclaredFieldsIncludingInherited(actual.getClass()); Set<String> ignoredFields = newLinkedHashSet(propertiesOrFieldsToIgnore); List<String> nonNullFieldNames = declaredFields.stream() .filter(field -> !ignoredFields.contains(field.getName())) .filter(field -> canReadFieldValue(field, actual)) .filter(field -> getPropertyOrFieldValue(actual, field.getName()) != null) .map(Field::getName) .collect(toList()); if (!nonNullFieldNames.isEmpty()) { throw failures.failure(info, shouldHaveAllNullFields(actual, nonNullFieldNames, list(propertiesOrFieldsToIgnore))); } }
private Filters(E[] array) { this(newArrayList(array)); }
public static <T> Collection<T> toCollection(Iterable<T> iterable) { return iterable instanceof Collection ? (Collection<T>) iterable : newArrayList(iterable); }
public Builder annotations(Class<? extends Annotation>... annotations) { mAnnotations = Lists.newArrayList(annotations); return this; }
public Builder externalAnnotations(AnnotationSpec... externalAnnotations) { mExternalAnnotations = Lists.newArrayList(externalAnnotations); return this; }
private Filters(Iterable<E> iterable) { this.initialIterable = iterable; // copy list to avoid modifying iterable this.filteredIterable = newArrayList(iterable); }
public static <T> Collection<T> toCollection(Iterable<T> iterable) { return iterable instanceof Collection ? (Collection<T>) iterable : newArrayList(iterable); }
private Filters(E[] array) { this(newArrayList(array)); }
@SafeVarargs public static <T> ArrayList<T> list(T... elements) { return newArrayList(elements); }
private List<DateFormat> dateFormatsInOrderOfUsage() { List<DateFormat> allDateFormatsInOrderOfUsage = newArrayList(userDateFormats.get()); allDateFormatsInOrderOfUsage.addAll(DEFAULT_DATE_FORMATS); return allDateFormatsInOrderOfUsage; }
@SafeVarargs public static <T> Iterable<T> iterable(T... elements) { if (elements == null) return null; ArrayList<T> list = newArrayList(); java.util.Collections.addAll(list, elements); return list; }
private static List<StackTraceElement> stackTraceInCurrentThread() { return newArrayList(Thread.currentThread().getStackTrace()); }
/** * Create an array from an {@link Iterable}. * <p> * Note: this method will return Object[]. If you require a typed array please use {@link #toArray(Iterable, Class)}. * It's main usage is to keep the generic type for chaining call like in: * <pre><code class='java'> public S containsOnlyElementsOf(Iterable<? extends T> iterable) { * return containsOnly(toArray(iterable)); * }</code></pre> * * @param iterable an {@link Iterable} to translate in an array. * @param <T> the type of elements of the {@code Iterable}. * @return all the elements from the given {@link Iterable} in an array. {@code null} if given {@link Iterable} is * null. */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Iterable<? extends T> iterable) { if (iterable == null) return null; return (T[]) newArrayList(iterable).toArray(); }
/** * Creates a <em>mutable</em> {@link ArrayList} containing the given elements. * * @param <T> the generic type of the {@code ArrayList} to create. * @param elements the elements to store in the {@code ArrayList}. * @return the created {@code ArrayList}, of {@code null} if the given array of elements is {@code null}. */ @SafeVarargs public static <T> ArrayList<T> newArrayList(T... elements) { if (elements == null) { return null; } ArrayList<T> list = newArrayList(); java.util.Collections.addAll(list, elements); return list; }
@SafeVarargs public static <T> ArrayList<T> list(T... elements) { return newArrayList(elements); }
private List<DateFormat> dateFormatsInOrderOfUsage() { List<DateFormat> allDateFormatsInOrderOfUsage = newArrayList(userDateFormats.get()); allDateFormatsInOrderOfUsage.addAll(DEFAULT_DATE_FORMATS); return allDateFormatsInOrderOfUsage; }
@SafeVarargs public static <T> Iterable<T> iterable(T... elements) { if (elements == null) return null; ArrayList<T> list = newArrayList(); java.util.Collections.addAll(list, elements); return list; }
private static List<StackTraceElement> stackTraceInCurrentThread() { return newArrayList(Thread.currentThread().getStackTrace()); }