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.jnario.jnario.test.util.Query.java

public <T extends EObject> T find(String name, Class<T> type) {
    return Iterables.find(all(type), Predicates2.nameIs(name));
}

From source file:com.atlassian.jira.rest.client.domain.EntityHelper.java

@SuppressWarnings("unused")
public static <T extends IdentifiableEntity<K>, K> T findEntityById(Iterable<T> entities, final K id) {
    return Iterables.find(entities, HasIdPredicate.forId(id));
}

From source file:org.jclouds.compute.suppliers.DefaultLocationSupplier.java

@Override
public Location get() {
    return Iterables.find(locations.get(), new Predicate<Location>() {

        @Override//w  ww.  j  a va2  s  .c  o  m
        public boolean apply(Location input) {
            return input.getScope() == LocationScope.ZONE;
        }

    });
}

From source file:org.polarsys.reqcycle.traceability.cache.emfbased.predicates.TraceabilityLinkPredicate.java

@Override
public boolean apply(TraceabilityLink arg0) {
    try {//w w w.  java2 s  . c om
        if (Objects.equal(arg0.getLabel(), label)) {
            if (Iterables.find(arg0.getSources(), Predicates.equalTo(source)) != null) {
                if (Iterables.elementsEqual(arg0.getTargets(), targets)) {
                    return true;
                }
            }
        }
    } catch (NoSuchElementException e) {
    }
    return false;
}

From source file:org.jclouds.ec2.compute.loaders.LoadPublicIpForInstanceOrNull.java

@Override
public String load(final RegionAndName key) throws Exception {
    try {//  w ww.j  av  a 2  s  .c o  m
        return Iterables.find(client.getElasticIPAddressApi().get().describeAddressesInRegion(key.getRegion()),
                new Predicate<PublicIpInstanceIdPair>() {

                    @Override
                    public boolean apply(PublicIpInstanceIdPair input) {
                        return key.getName().equals(input.getInstanceId());
                    }

                }).getPublicIp();
    } catch (NoSuchElementException e) {
        return null;
    }
}

From source file:org.jclouds.ec2.compute.functions.LoadPublicIpForInstanceOrNull.java

@Override
public String load(final RegionAndName key) throws Exception {
    try {/*from w  w  w .  java  2  s  . c o m*/
        return Iterables.find(client.getElasticIPAddressServices().describeAddressesInRegion(key.getRegion()),
                new Predicate<PublicIpInstanceIdPair>() {

                    @Override
                    public boolean apply(PublicIpInstanceIdPair input) {
                        return key.getName().equals(input.getInstanceId());
                    }

                }).getPublicIp();
    } catch (NoSuchElementException e) {
        return null;
    }
}

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

public AbstractButton findButtonWithIcon(String iconFile) {
    AbstractButton returnedButton = (AbstractButton) Iterables.find(containedComponents,
            new ButtonWithIconPredicate(iconFile));
    if (returnedButton == null) {
        throw new NoSuchElementException("No button found with icon file " + iconFile);
    }// w  ww .j  a  v  a  2s . co m
    return returnedButton;
}

From source file:org.jclouds.ibmdev.predicates.AddressFree.java

public boolean apply(Address address) {
    logger.trace("looking for state on address %s", address);
    final String id = address.getId();
    try {/*from w  ww.  j  av a  2  s  .  co m*/
        address = Iterables.find(client.listAddresses(), new Predicate<Address>() {

            @Override
            public boolean apply(Address input) {
                return input.getId().equals(id);
            }
        });
    } catch (NoSuchElementException e) {
        return false;
    }
    logger.trace("%s: looking for address state %s: currently: %s", address.getId(), Address.State.FREE,
            address.getState());
    return address.getState() == Address.State.FREE;

}

From source file:io.joynr.generator.loading.Query.java

public EObject find(Predicate<EObject> predicate) {
    return Iterables.find(content, predicate);
}

From source file:org.jclouds.aws.suppliers.DefaultLocationSupplier.java

@Override
@Singleton//from ww w .jav a2  s. c  o  m
public Location get() {
    try {
        Location toReturn = Iterables.find(set.get(), new Predicate<Location>() {

            @Override
            public boolean apply(Location input) {
                switch (input.getScope()) {
                case ZONE:
                    return input.getParent().getId().equals(region);
                case REGION:
                    return input.getId().equals(region);
                default:
                    return false;
                }
            }

        });
        return toReturn.getScope() == LocationScope.REGION ? toReturn : toReturn.getParent();
    } catch (NoSuchElementException e) {
        throw new IllegalStateException(String.format("region: %s not found in %s", region, set));
    }
}