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

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

Introduction

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

Prototype

@Nullable
public static <T> T find(Iterable<? extends T> iterable, Predicate<? super T> predicate,
        @Nullable T defaultValue) 

Source Link

Document

Returns the first element in iterable that satisfies the given predicate, or defaultValue if none found.

Usage

From source file:com.mingo.query.QueryType.java

/**
 * Gets enum by name.//from  www.j a va2s.co m
 *
 * @param name name
 * @return {@link QueryType}
 */
public static QueryType getByName(final String name) {
    return Iterables.find(Lists.newArrayList(values()), new Predicate<QueryType>() {
        public boolean apply(QueryType input) {
            return input.getName().equals(name);
        }
    }, null);
}

From source file:com.mingo.query.QueryExecutorType.java

/**
 * Gets enum by name./* w  ww  .  j a v a 2 s .  c  o m*/
 *
 * @param name name
 * @return {@link QueryExecutorType}
 */
public static QueryExecutorType getByName(final String name) {
    return Iterables.find(Lists.newArrayList(values()), new Predicate<QueryExecutorType>() {
        public boolean apply(QueryExecutorType input) {
            return input.getName().equals(name);
        }
    }, null);
}

From source file:com.mingo.query.QueryAnalyzerType.java

/**
 * Gets enum by name./*from w  ww . ja  v a  2 s.  c om*/
 *
 * @param name name
 * @return {@link QueryExecutorType}
 */
public static QueryAnalyzerType getByName(final String name) {
    return Iterables.find(Lists.newArrayList(values()), new Predicate<QueryAnalyzerType>() {
        public boolean apply(QueryAnalyzerType input) {
            return input.getName().equals(name);
        }
    }, null);
}

From source file:org.jmingo.query.QueryType.java

/**
 * Gets enum by name.//from   w w w.j a  v  a  2  s  . co m
 *
 * @param name name
 * @return {@link QueryType}
 */
public static QueryType getByName(final String name) {
    return Iterables.find(Lists.newArrayList(values()), input -> input.getName().equals(name), null);
}

From source file:com.google.gerrit.acceptance.rest.project.ProjectAssert.java

public static void assertProjects(Iterable<Project.NameKey> expected, List<ProjectInfo> actual) {
    for (final Project.NameKey p : expected) {
        ProjectInfo info = Iterables.find(actual, new Predicate<ProjectInfo>() {
            @Override/*from  www.j  av  a2  s.c  o m*/
            public boolean apply(ProjectInfo info) {
                return new Project.NameKey(info.name).equals(p);
            }
        }, null);
        assertNotNull("missing project: " + p, info);
        actual.remove(info);
    }
    assertTrue("unexpected projects: " + actual, actual.isEmpty());
}

From source file:org.jboss.as.console.client.tools.ModelBrowserValidators.java

private static FormItem findItem(String name, List<FormItem> formItems) {
    return Iterables.find(formItems, formItem -> name.equals(formItem.getName()), null);
}

From source file:ratpack.server.internal.ServerEnvironment.java

@SafeVarargs
@SuppressWarnings("varargs")
private static <T> T get(T defaultValue, Predicate<? super T> accept, Supplier<T>... suppliers) {
    return Iterables.find(Iterables.transform(Arrays.asList(suppliers), Supplier::get), accept::test,
            defaultValue);/*  w w w  . j a v  a 2s  .  c o m*/
}

From source file:ratpack.util.internal.Environment.java

@SafeVarargs
@SuppressWarnings("varargs")
protected static <T> T get(T defaultValue, Predicate<? super T> accept, Supplier<T>... suppliers) {
    return Iterables.find(Iterables.transform(Arrays.asList(suppliers), Supplier::get), accept::test,
            defaultValue);//from  w  w w.  j a  v  a  2s. co m
}

From source file:org.polymap.core.security.AuthorizationModuleExtension.java

public static AuthorizationModuleExtension forId(final String id) {
    assert id != null;
    return Iterables.find(all(), new Predicate<AuthorizationModuleExtension>() {
        public boolean apply(AuthorizationModuleExtension input) {
            return id.equals(input.ext.getDeclaringExtension().getUniqueIdentifier());
        }//from   w  w  w  . ja va2 s .co  m
    }, null);
}

From source file:io.soabase.admin.components.ComponentContainer.java

public T get(final String id) {
    return Iterables.find(components, new Predicate<T>() {
        @Override/*w  ww  .  j  a va  2s.  c o m*/
        public boolean apply(T component) {
            return component.getId().equals(id);
        }
    }, null);
}