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.linagora.obm.ui.page.ContactPage.java

public void selectContact(final String contactDisplayName) {
    WebElement contactElement = Iterables.find(driver.findElements(By.className("contactHeader")),
            new Predicate<WebElement>() {

                @Override//from  www . j  a  v a  2 s.  c om
                public boolean apply(WebElement input) {
                    return StringUtils.contains(input.getText(), contactDisplayName);
                }

            });

    contactElement.click();
    waitForAjaxRequestToComplete();
}

From source file:org.jclouds.location.suppliers.OnlyLocationOrFirstZoneOrRegionMatchingRegionId.java

@Override
@Singleton//ww w  . jav  a  2  s .  c o  m
public Location get() {
    Set<? extends Location> locations = locationsSupplier.get();
    if (locationsSupplier.get().size() == 1)
        return getOnlyElement(locationsSupplier.get());
    IsRegionAndIdEqualsOrIsZoneParentIdEquals matcher = null;
    try {
        String region = injector.getInstance(Key.get(String.class, Region.class));
        if (region == null)
            return Iterables.get(locationsSupplier.get(), 0);
        matcher = injector.getInstance(IsRegionAndIdEqualsOrIsZoneParentIdEquals.class);
        Location toReturn = Iterables.find(locations, matcher);
        return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent();
    } catch (NoSuchElementException e) {
        throw new IllegalStateException(String.format("region %s not found in %s", matcher, locations));
    }
}

From source file:io.crate.frameworks.mesos.CrateInstances.java

public CrateInstance byTaskId(final String taskId) {
    return Iterables.find(this, new Predicate<CrateInstance>() {
        @Override/*  w  w w .ja v a2 s  .  co  m*/
        public boolean apply(CrateInstance input) {
            return input.taskId().equals(taskId);
        }
    });
}

From source file:org.jclouds.deltacloud.config.DeltacloudRestClientModule.java

public static DeltacloudCollection findCollectionWithRel(Iterable<? extends DeltacloudCollection> iterable,
        final String rel) {
    try {//from w  w w .j  av a  2  s  .c o  m
        return Iterables.find(iterable, new Predicate<DeltacloudCollection>() {

            @Override
            public boolean apply(DeltacloudCollection arg0) {
                return arg0.getRel().equals(rel);
            }

        });
    } catch (NoSuchElementException e) {
        throw new NoSuchElementException("could not find rel " + rel + " in collections " + iterable);
    }
}

From source file:org.obiba.onyx.quartz.magma.AbstractQuartzBeanResolver.java

protected OpenAnswer findOpenAnswer(final CategoryAnswer ca, final String openAnswerDefinitionName) {
    return Iterables.find(ca.getOpenAnswers(), new Predicate<OpenAnswer>() {
        public boolean apply(OpenAnswer input) {
            return input.getOpenAnswerDefinitionName().equals(openAnswerDefinitionName);
        }/* w w w .j  a  va2  s .com*/
    });
}

From source file:org.geoserver.importer.Database.java

@Override
public Table part(final String name) {
    return Iterables.find(tables, new Predicate<Table>() {
        @Override/*ww  w  .j ava2 s .co m*/
        public boolean apply(Table input) {
            return name.equals(input.getName());
        }
    });
}

From source file:com.streamreduce.connections.ConnectionProviderFactory.java

public ConnectionProvider connectionProviderFromId(final String providerId) {
    return Iterables.find(allConnectionProviders, new Predicate<ConnectionProvider>() {
        @Override/*from w  w w  .  jav a  2  s. co m*/
        public boolean apply(@Nullable ConnectionProvider connectionProvider) {
            return connectionProvider != null && connectionProvider.getId().equals(providerId);
        }
    });
}

From source file:com.eviware.soapui.utils.ContainerWalker.java

public AbstractButton findButtonWithName(String buttonName) {
    return (AbstractButton) Iterables.find(containedComponents,
            new ComponentClassAndNamePredicate(AbstractButton.class, buttonName));
}

From source file:org.jclouds.vcloud.terremark.config.TerremarkECloudRestClientModule.java

@Override
protected URI findDefaultNetworkForVDC(org.jclouds.vcloud.domain.VDC vDC, Map<String, ReferenceType> networks,
        final Injector injector) {
    // TODO FIXME XXX: In Terremark Enterprise environment with multiple VDC's this does not
    // work well.
    // Each VDC will have differnt network subnets. So we cannot assume the default VDC's
    // networks will
    // work with non-default VDC's. So make PROPERTY_VCLOUD_DEFAULT_NETWORK optional. If
    // this property
    // is not set, they are expected to add NetworkConfig to the options when launching a
    // server.//from ww  w  .j av a2  s  . c  o m
    logger.warn("default network for vdc %s not set", vDC.getName());
    try {
        return Iterables.find(networks.values(), new Predicate<ReferenceType>() {

            @Override
            public boolean apply(ReferenceType input) {
                TerremarkOrgNetwork network = injector.getInstance(TerremarkECloudClient.class)
                        .getNetwork(input.getHref());
                TerremarkNetwork terremarkNetwork = injector.getInstance(TerremarkECloudClient.class)
                        .getTerremarkNetwork(checkNotNull(
                                checkNotNull(network, "network at: " + input).getNetworkExtension(),
                                "network extension for: " + input).getHref());
                return checkNotNull(terremarkNetwork,
                        "terremark network extension at: " + network.getNetworkExtension())
                                .getNetworkType() == TerremarkNetwork.Type.DMZ;
            }

        }).getHref();
    } catch (NoSuchElementException e) {
        throw new ResourceNotFoundException("no dmz networks in vdc " + vDC.getName() + ": " + networks);
    }
}

From source file:org.jclouds.trmk.vcloud_0_8.functions.ParseLoginResponseFromHeaders.java

public String parseTokenFromHeaders(HttpResponse from) {
    String cookieHeader = from.getFirstHeaderOrNull("x-vcloud-authorization");
    if (cookieHeader != null) {
        Matcher matcher = pattern.matcher(cookieHeader);
        return matcher.find() ? matcher.group(2) : cookieHeader;
    } else {//  ww  w  .  j a  v  a  2 s.  com
        try {
            cookieHeader = Iterables.find(from.getHeaders().get(HttpHeaders.SET_COOKIE),
                    Predicates.contains(pattern));
            Matcher matcher = pattern.matcher(cookieHeader);
            matcher.find();
            return matcher.group(2);
        } catch (NoSuchElementException e) {
            throw new HttpResponseException(String.format("Header %s or %s must be present",
                    "x-vcloud-authorization", HttpHeaders.SET_COOKIE), null, from);
        }
    }
}