Example usage for com.google.common.collect Iterables getFirst

List of usage examples for com.google.common.collect Iterables getFirst

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getFirst.

Prototype

@Nullable
public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue) 

Source Link

Document

Returns the first element in iterable or defaultValue if the iterable is empty.

Usage

From source file:org.kitesdk.data.spi.Predicates.java

@SuppressWarnings("unchecked")
public static <T> In<T> in(Set<T> set) {
    T item = Iterables.getFirst(set, null);
    if (item != null && item instanceof CharSequence) {
        return (In<T>) new In(new CharSequences.ImmutableCharSequenceSet((Set<CharSequence>) set));
    }/*from  www.j  a  v  a2 s.  c om*/
    return new In<T>(set);
}

From source file:ezbake.thrift.authentication.X509Utils.java

public static String getO(LdapName name) {
    return Iterables.getFirst(getValueOfType(name, DnFields.O), "");
}

From source file:ezbake.thrift.authentication.X509Utils.java

public static String getC(LdapName name) {
    return Iterables.getFirst(getValueOfType(name, DnFields.C), "");
}

From source file:com.google.api.server.spi.config.validation.InconsistentApiConfigurationException.java

private static String getErrorMessage(ApiConfig config, ApiConfig otherConfig,
        Iterable<ApiConfigInconsistency<Object>> inconsistencies) {
    Preconditions.checkArgument(!Iterables.isEmpty(inconsistencies));
    ApiConfigInconsistency<?> firstInconsistency = Iterables.getFirst(inconsistencies, null);
    return String.format(
            "API-wide configuration does not match between the classes %s and %s. All "
                    + "API classes with the same API name and version must have the exact same API-wide "
                    + "configuration. Differing property: %s (%s vs %s).",
            config.getApiClassConfig().getApiClassJavaName(),
            otherConfig.getApiClassConfig().getApiClassJavaName(), firstInconsistency.getPropertyName(),
            firstInconsistency.getValue1(), firstInconsistency.getValue2());
}

From source file:uk.co.flax.luwak.termextractor.QueryTermList.java

public static QueryTermList selectBest(List<QueryTermList> termlists, Comparator<QueryTermList> comparator) {
    Collections.sort(termlists, comparator);
    return Iterables.getFirst(termlists, null);
}

From source file:com.teradata.benchto.driver.FailedBenchmarkExecutionException.java

private static String createMessage(List<BenchmarkExecutionResult> failedBenchmarkResults) {
    checkArgument(!failedBenchmarkResults.isEmpty(), "no failures");

    return format("%s benchmarks failed, first failure was: %s", failedBenchmarkResults.size(),
            Iterables.getFirst(failedBenchmarkResults.get(0).getFailureCauses(), null));
}

From source file:org.trimou.handlebars.EmbedHelper.java

@Override
public void execute(Options options) {
    String sourceName = Iterables.getFirst(options.getParameters(), "").toString();
    String mustacheSource = options.source(sourceName);
    StringBuilder script = new StringBuilder();
    script.append("<script id=\"").append(sourceName.replace("/", "_")).append("\" type=\"text/template\">\n")
            .append(mustacheSource).append("\n").append("</script>");
    options.append(script.toString());//  w  w  w  . j a v a2 s  . c o m
}

From source file:nextmethod.web.razor.tokenizer.symbols.SymbolExtensions.java

public static LocationTagged<String> getContent(@Nullable final Iterable<? extends ISymbol> symbols,
        @Nonnull final SourceLocation spanStart) {
    if (symbols == null || Iterables.isEmpty(symbols)) {
        return new LocationTagged<>(Strings.Empty, spanStart);
    } else {//from ww  w  .java2  s  . com
        final ISymbol first = Iterables.getFirst(symbols, null);
        final StringBuilder sb = new StringBuilder();
        for (ISymbol symbol : symbols) {
            sb.append(symbol.getContent());
        }
        return new LocationTagged<>(sb.toString(), SourceLocation.add(spanStart, first.getStart()));
    }
}

From source file:me.taylorkelly.mywarp.util.IterableUtils.java

/**
 * Returns an Optional containing the first element in iterable or {@code Optional.absend()} if the iterable is
 * empty.//from w  w w .j av a 2s.  c  o m
 *
 * @param <T>      the type of entries
 * @param iterable the iterable to check
 * @return the first element
 */
public static <T> Optional<T> getFirst(Iterable<T> iterable) {
    T first = Iterables.getFirst(iterable, null);
    return Optional.fromNullable(first);
}

From source file:org.apache.hadoop.metrics2.impl.MetricsRecords.java

private static MetricsTag getFirstTagByName(MetricsRecord record, String name) {
    return Iterables.getFirst(Iterables.filter(record.tags(), new MetricsTagPredicate(name)), null);
}