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

public static <T> T find(Iterable<T> iterable, Predicate<? super T> predicate) 

Source Link

Document

Returns the first element in iterable that satisfies the given predicate; use this method only when such an element is known to exist.

Usage

From source file:com.allogy.couch.importers.MimeCouchDocumentImporter.java

private static Header getHeader(Iterable<Header> headers, final String headerName) {
    return Iterables.find(headers, new Predicate<Header>() {
        public boolean apply(@Nullable Header header) {
            return header != null && headerName.equalsIgnoreCase(header.getName());
        }//from  w w w. j  a  va  2s .co m
    });
}

From source file:org.apache.abdera2.common.selector.AbstractSelector.java

public X choose(Iterable<X> items) {
    if (items == null)
        return null;
    return Iterables.find(items, this);
}

From source file:org.jclouds.chef.binders.BindCreateClientOptionsToJsonPayload.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
    checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
            "this binder is only valid for GeneratedHttpRequests");
    GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
    checkState(gRequest.getInvocation().getArgs() != null, "args should be initialized at this point");

    String name = checkNotNull(postParams.remove("name"), "name").toString();
    CreateClientOptions options = (CreateClientOptions) Iterables.find(gRequest.getInvocation().getArgs(),
            Predicates.instanceOf(CreateClientOptions.class));

    return bindToRequest(request, new CreateClientParams(name, options));
}

From source file:org.dyndns.jkiddo.dmp.model.Library.java

public Database getDatabase(final long id) {
    return Iterables.find(databases, new Predicate<Database>() {

        @Override//  ww  w . ja  va  2  s. c  o m
        public boolean apply(Database input) {
            return input.getItemId() == id;
        }
    });
}

From source file:org.jclouds.rackspace.cloudloadbalancers.v1.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata.java

@Override
public LoadBalancerMetadata apply(LoadBalancer input) {

    Location location = Iterables.find(locations.get(), LocationPredicates.idEquals(input.getRegion()));

    String id = input.getRegion() + "/" + input.getId();
    // TODO Builder
    return new LoadBalancerMetadataImpl(LoadBalancerType.LB, String.valueOf(input.getId()), input.getName(), id,
            location, null, ImmutableMap.<String, String>of(),
            Iterables.transform(input.getVirtualIPs(), new Function<VirtualIPWithId, String>() {

                @Override/*  w  ww. j  a  va2s  . c o  m*/
                public String apply(VirtualIPWithId arg0) {
                    return arg0.getAddress();
                }

            }));
}

From source file:bear.core.Stages.java

public Stage findByName(String stageName) {
    return Iterables.find(stages, Predicates2.fieldEquals("name", stageName));
}

From source file:com.allogy.couch.multipart.CouchMultipart.java

private static Header getHeader(Iterable<Header> headers, final String headerName) {
    return Iterables.find(headers, new Predicate<Header>() {
        public boolean apply(Header header) {
            return header != null && headerName.equalsIgnoreCase(header.getName());
        }//w  w w  . j  a v  a 2 s.c  o  m
    });
}

From source file:org.fusesource.ide.fabric8.ui.actions.jclouds.CloudDetailsEditAction.java

protected void editCloud(final ConfigurationDetails cloudDetails) {
    cloudDetails.flush();/* ww  w.  ja v a 2  s .  c  o  m*/
    try {
        CloudDetails.reloadCloudDetailList();
    } catch (Exception e) {
        FabricPlugin.getLogger().error(e);
    }

    // now lets select the one with this id
    Object found = Iterables.find(CloudDetails.getCloudDetailList(), new Predicate<CloudDetails>() {

        @Override
        public boolean apply(CloudDetails details) {
            return Objects.equal(cloudDetails.getId(), details.getId());
        }
    });

    if (found != null) {
        onCloudDetailsEdited(found);
    }
}

From source file:org.hudsonci.maven.plugin.ui.gwt.buildinfo.internal.ModuleDataProvider.java

/**
 * @throws NoSuchElementException if no matching moduleId is found
 *//*from w  w w .j a  va  2  s .  c o  m*/
public MavenProjectDTO find(final String moduleId) throws NoSuchElementException {
    checkNotNull(moduleId);

    return Iterables.find(this.getList(), new Predicate<MavenProjectDTO>() {
        public boolean apply(MavenProjectDTO input) {
            return moduleId.equals(input.getId());
        }
    });
}

From source file:kr.debop4j.data.hibernate.forTesting.DatabaseTestFixtureBase.java

/**
 * Gets unit of work test context.//from  w ww.  ja  v a 2 s.co  m
 *
 * @param dbConfigurationClass the db configuration class
 * @return the unit of work test context
 */
protected static UnitOfWorkTestContextBase getUnitOfWorkTestContext(final Class dbConfigurationClass) {

    UnitOfWorkTestContextBase context = null;
    if (contexts.size() > 0) {
        Predicate<UnitOfWorkTestContextBase> criteria = new Predicate<UnitOfWorkTestContextBase>() {
            @Override
            public boolean apply(@Nullable UnitOfWorkTestContextBase input) {
                return (input != null) && dbConfigurationClass == input.getDbConfigurationClass();
            }
        };
        try {
            context = Iterables.find(contexts, criteria);
        } catch (NoSuchElementException ignored) {
            context = null;
        }
    }

    if (context == null) {
        context = UnitOfWorkTestContextBase.create(dbConfigurationClass);
        contexts.add(context);

        if (log.isDebugEnabled())
            log.debug("create UnitOfWorkTestContext by [{}]", dbConfigurationClass);
    }

    return context;
}