public static <T> Optional<T> headOption(final List<T> list) { return IterableUtils.headOption(list); }
public static <T> Iterable<T> requireNonEmpty(final Iterable<T> iterable) { if (isEmpty(iterable)) { throw new IllegalArgumentException("iterable must not be empty."); } return iterable; }
/** * Creates a predicate which is a shortcut for multiple or statements. * @param queryModel the parent model * @param values possible values to query for, if it is for Strings, the may need to be escaped concerning double quotes. * @throws IllegalArgumentException if values is empty */ public IsInPredicate(final QueryModel<M> queryModel, final Iterable<V> values) { super(queryModel); requireNonEmpty(values);//SPHERE.IO requires values not to be empty this.values = values; }
private String renderPath(final SearchModel<T> model) { return toStream(model.buildPath()).collect(joining(".")); } }
public static <T> Stream<T> toStream(final Iterable<T> iterable) { return toList(iterable).stream(); }
private void assertModelsInBackend() { final List<T> instances = createInBackendByName(modelNames()); final List<String> actualNames = instances.stream().map(o -> extractName(o)). filter(name -> modelNames().contains(name)).sorted().collect(toList()); assertThat(actualNames). overridingErrorMessage(String.format("The test requires instances with the names %s.", IterableUtils.toString(modelNames()))). isEqualTo(modelNames()); }
public static <T> List<String> toIds(final Iterable<? extends Identifiable<T>> elements) { return toStream(elements).map(element -> element.getId()).collect(toList()); }
public static <T> String toString(final Iterable<T> iterable) { final StringJoiner joiner = new StringJoiner(", "); toList(iterable).forEach(item -> joiner.add(item.toString())); return "[" + joiner.toString() + "]"; } }
public static <T> List<String> toIds(final Iterable<? extends Identifiable<T>> elements) { return toStream(elements).map(element -> element.getId()).collect(toList()); }
public static <T> Optional<T> headOption(final List<T> list) { return IterableUtils.headOption(list); } }
public static <T> Optional<T> headOption(final Iterable<T> iterable) { Optional<T> result = Optional.empty(); if (!isEmpty(iterable)) { result = Optional.of(iterable.iterator().next()); } return result; }
public Optional<String> get(final Iterable<Locale> locales) { final Optional<Locale> firstFoundLocale = toStream(locales).filter(locale -> translations.containsKey(locale)).findFirst(); return firstFoundLocale.flatMap(foundLocale -> get(foundLocale)); }
private static List<String> escape(final Iterable<String> args) { return toStream(args).map(x -> escape(x)).collect(toList()); } }
protected final String serializedPath() { return toStream(searchModel.buildPath()).collect(joining(".")); }
/** * Turns a group of terms into an expression of the form "term1,term2,..." * @return the generated term expression. */ private Optional<String> toTermExpression() { String termExpression = toStream(terms).map(t -> serializer().apply(t)) .filter(t -> !t.isEmpty()).collect(joining(",")); if (termExpression.isEmpty()) { return Optional.empty(); } else { return Optional.of(termExpression); } } }
/** * Turns a group of ranges into an expression of the form "(e1 to e2),(e3 to e4),..." * @return the generated range expression. */ private String toRangeExpression(Iterable<? extends Range<V>> ranges) { return toStream(ranges).map(r -> r.serialize(serializer())).filter(r -> !r.isEmpty()).collect(joining(",")); } }
public final Predicate<T> isIn(final Iterable<? extends Referenceable<R>> references) { final List<String> ids = toStream(references).map(r -> r.toReference().getId()).collect(toList()); return new StringQuerySortingModel<>(Optional.of(this), "id").isOneOf(ids); }