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.linagora.linshare.view.tapestry.pages.administration.thread.Index.java

public Object onActionFromShowAdmin(String lsUuid) {
    admin.setSelectedThread(Iterables.find(threads, ThreadVo.equalTo(lsUuid)));
    return admin;
}

From source file:org.jclouds.gogrid.compute.functions.ServerToNodeMetadata.java

@Override
public NodeMetadata apply(Server from) {
    NodeMetadataBuilder builder = new NodeMetadataBuilder();
    builder.ids(from.getId() + "");
    builder.name(from.getName());//from www  .  j  a  va2 s . com
    Location location = Iterables.find(locations.get(),
            LocationPredicates.idEquals(from.getDatacenter().getId() + ""));
    builder.location(location);
    builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
    builder.hardware(parseHardware(from));
    builder.imageId(from.getImage().getId() + "");

    Image image = parseImage(from);
    if (image != null)
        builder.operatingSystem(image.getOperatingSystem());

    builder.status(serverStateToNodeStatus.get(from.getState()));
    builder.publicAddresses(ImmutableSet.of(from.getIp().getIp()));
    return builder.build();
}

From source file:io.opencensus.stats.StatsTestUtil.java

/**
 * Asserts that the two sets of {@code DistributionAggregate}s are equivalent, with a given
 * tolerance. The tolerance is used when comparing the mean and sum of values. The order of the
 * {@code DistributionAggregate}s has no effect. The expected parameter is last, because it is
 * likely to be a larger expression./* ww  w.j a  v a2 s.  c  o m*/
 *
 * @param tolerance the tolerance used for {@code double} comparison.
 * @param actual the actual test result.
 * @param expected the expected value.
 * @throws AssertionError if the {@code DistributionAggregate}s don't match.
 */
static void assertDistributionAggregatesEquivalent(double tolerance, Collection<DistributionAggregate> actual,
        Collection<DistributionAggregate> expected) {
    Function<DistributionAggregate, List<Tag>> getTagsFunction = new Function<DistributionAggregate, List<Tag>>() {
        @Override
        public List<Tag> apply(DistributionAggregate agg) {
            return agg.getTags();
        }
    };
    Iterable<List<Tag>> expectedTags = Iterables.transform(expected, getTagsFunction);
    Iterable<List<Tag>> actualTags = Iterables.transform(actual, getTagsFunction);
    Truth.assertThat(actualTags).containsExactlyElementsIn(expectedTags);
    for (DistributionAggregate expectedAgg : expected) {
        DistributionAggregate actualAgg = Iterables.find(actual,
                Predicates.compose(Predicates.equalTo(expectedAgg.getTags()), getTagsFunction));
        assertDistributionAggregateValuesEquivalent("DistributionAggregate tags=" + expectedAgg.getTags(),
                tolerance, expectedAgg, actualAgg);
    }
}

From source file:org.richfaces.cdk.templatecompiler.statements.FreeMarkerTestBase.java

protected void verifyHelpers(TemplateStatement statement, HelperMethod... expected) {
    Iterable<HelperMethod> requiredHelpers = statement.getRequiredMethods();
    for (final HelperMethod expectedHelper : expected) {
        try {/*  w  w w.  ja  va2s.  c o  m*/
            Iterables.find(requiredHelpers, new Predicate<HelperMethod>() {
                @Override
                public boolean apply(HelperMethod input) {
                    return input.equals(expectedHelper);
                }
            });
        } catch (NoSuchElementException e) {
            assertTrue("Helper method " + expectedHelper + " not found in statement", false);
        }
    }
}

From source file:com.github.richardwilly98.esdms.DocumentImpl.java

@Override
@JsonIgnore/*from   w  w w. j a v  a2s  .c  o m*/
public Version getCurrentVersion() {
    if (versions == null || versions.size() == 0) {
        return null;
    } else {
        try {
            return Iterables.find(versions, new Predicate<Version>() {
                @Override
                public boolean apply(Version version) {
                    return version.isCurrent();
                }
            });
        } catch (NoSuchElementException ex) {
            return null;
        }
    }
}

From source file:org.linagora.linshare.view.tapestry.pages.administration.thread.Index.java

public void onActionFromDelete(String lsUuid) {
    delete = Iterables.find(threads, ThreadVo.equalTo(lsUuid));
}

From source file:org.jclouds.ovh.OVHComputeClient.java

public DistributionStruct getImage(final String name) throws OvhWsException {
    listServers();/*from w  w w .j  a  v  a2 s.  com*/
    return Iterables.find(listImages(), new Predicate<DistributionStruct>() {

        @Override
        public boolean apply(DistributionStruct input) {
            return input.getName().equalsIgnoreCase(name);
        }
    });
}

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

public ExternalIntegrationConnectionProvider externalIntegrationConnectionProviderFromId(
        final String providerId) {
    return Iterables.find(allExternalIntegrationConnectionProviders,
            new Predicate<ExternalIntegrationConnectionProvider>() {
                @Override/*from w  w w .ja  v  a2 s.c  o m*/
                public boolean apply(@Nullable ExternalIntegrationConnectionProvider connectionProvider) {
                    return connectionProvider != null && connectionProvider.getId().equals(providerId);
                }
            });
}

From source file:org.linagora.linshare.view.tapestry.pages.thread.Index.java

public Object onActionFromShowThreadContent(String lsUuid) {
    threadContent.setMySelectedThread(Iterables.find(threads, ThreadVo.equalTo(lsUuid)));
    return threadContent;
}

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

public <T extends Component> T findComponent(String name, Class<? extends T> componentClass) {
    return (T) Iterables.find(containedComponents, new ComponentClassAndNamePredicate(componentClass, name));
}