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:org.apache.abdera2.common.selector.AbstractSelector.java

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

From source file:org.icgc.dcc.submission.validation.key.core.KVFileType.java

public static KVFileType from(final FileType fileType) {
    return Iterables.find(asList(values()), new Predicate<KVFileType>() {

        @Override//from  w ww .  j a  va 2  s .  c  o  m
        public boolean apply(KVFileType input) {
            return input.fileType == fileType;
        }

    });
}

From source file:org.jclouds.elb.loadbalancer.functions.LoadBalancerToLoadBalancerMetadata.java

private Location findLocationWithId(final String locationId) {
    return Iterables.find(locations.get(), new Predicate<Location>() {

        @Override//from w w w  . j a v a2  s .c  o m
        public boolean apply(Location input) {
            return input.getId().equals(locationId);
        }

    });
}

From source file:brooklyn.entity.waratek.WaratekJavaApplicationImpl.java

public JavaVirtualContainer getJavaVirtualContainer() {
    WaratekContainerLocation location = (WaratekContainerLocation) Iterables.find(getLocations(),
            Predicates.instanceOf(WaratekContainerLocation.class));
    return location.getOwner();
}

From source file:se.crafted.chrisb.ecoCreature.events.mappers.DropEventFactory.java

public Collection<DropEvent> collectDropEvents(final Event event) {
    Collection<DropEvent> emptyList = Collections.emptyList();

    EventMapper mapper = Iterables.find(mappers, new Predicate<EventMapper>() {
        @Override//from   w  w  w  .  ja v a2 s.c om
        public boolean apply(EventMapper mapper) {
            return mapper.canMap(event);
        }
    });

    return mapper != null ? mapper.mapEvent(event) : emptyList;
}

From source file:org.netbeans.modules.android.project.configs.ConfigGroup.java

public void setCurrentConfig(Config config) {
    currentConfig = Iterables.find(configs, hasSimilarName(config.getDisplayName()));
}

From source file:org.jclouds.openstack.nova.v1_1.binders.BindSecurityGroupRuleToJsonPayload.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Map<String, String> postParams) {
    Builder<String, String> payload = ImmutableMap.builder();
    payload.putAll(postParams);//from  ww w  . j a  v a 2  s . co m
    checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest<?>,
            "this binder is only valid for GeneratedHttpRequests!");
    GeneratedHttpRequest<?> gRequest = (GeneratedHttpRequest<?>) request;

    Ingress ingress = Ingress.class
            .cast(Iterables.find(gRequest.getArgs(), Predicates.instanceOf(Ingress.class)));
    payload.put("ip_protocol", ingress.getIpProtocol().toString());
    payload.put("from_port", ingress.getFromPort() + "");
    payload.put("to_port", ingress.getToPort() + "");

    return super.bindToRequest(request, ImmutableMap.of("security_group_rule", payload.build()));
}

From source file:org.jclouds.s3.blobstore.functions.LocationFromBucketLocation.java

public Location apply(BucketMetadata from) {
    if (onlyLocation != null)
        return onlyLocation;
    try {//  w w w.j  a va2  s. c  o  m
        Set<? extends Location> locations = this.locations.get();
        final String region = client.getBucketLocation(from.getName());
        assert region != null : String.format("could not get region for %s", from.getName());
        if (region != null) {
            try {
                return Iterables.find(locations, new Predicate<Location>() {

                    @Override
                    public boolean apply(Location input) {
                        return input.getId().equalsIgnoreCase(region.toString());
                    }

                });
            } catch (NoSuchElementException e) {
                logger.error("could not get location for region %s in %s", region, locations);
            }
        } else {
            logger.error("could not get region for %s", from.getName());
        }
    } catch (ContainerNotFoundException e) {
        logger.error(e, "could not get region for %s, as service suggests the bucket doesn't exist",
                from.getName());
    }
    return null;
}

From source file:org.eclipse.xtext.idea.facet.AbstractFacetConfiguration.java

protected OutputConfiguration findDefaultOutputConfiguration() {
    OutputConfiguration defOutput = Iterables.find(outputConfigDefaults.getOutputConfigurations(),
            new Predicate<OutputConfiguration>() {
                @Override/*  w w w.j  a v a 2  s  .c om*/
                public boolean apply(OutputConfiguration conf) {
                    return IFileSystemAccess.DEFAULT_OUTPUT.equals(conf.getName());
                }
            });
    return defOutput;
}

From source file:org.richfaces.component.DeclarativeTreeDataModelWalker.java

private void setupModelComponentContext(String modelId) {
    if (currentComponent instanceof TreeModelRecursiveAdaptor && modelId.equals(currentComponent.getId())) {
        // currentComponent already set
        modelData = ((TreeModelRecursiveAdaptor) currentComponent).getNodes();
    } else {/*from w  ww . jav a 2s .c o m*/
        currentComponent = Iterables.find(currentComponent.getChildren(), ComponentPredicates.withId(modelId));
        if (currentComponent instanceof TreeModelRecursiveAdaptor) {
            modelData = ((TreeModelRecursiveAdaptor) currentComponent).getRoots();
        } else {
            modelData = ((TreeModelAdaptor) currentComponent).getNodes();
        }
    }
}