Example usage for com.google.common.collect Iterables filter

List of usage examples for com.google.common.collect Iterables filter

Introduction

In this page you can find the example usage for com.google.common.collect Iterables filter.

Prototype

@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> Iterable<T> filter(final Iterable<?> unfiltered, final Class<T> desiredType) 

Source Link

Document

Returns all elements in unfiltered that are of the type desiredType .

Usage

From source file:org.eclipse.sirius.ui.tools.internal.actions.session.CloseSessionsAction.java

/**
 * Looks for selected sessions to close.
 * //from www .j a v a  2 s.  c  o m
 * {@inheritDoc}
 */
@Override
protected boolean updateSelection(IStructuredSelection selection) {
    if (selection != null) {
        for (Session concernedSession : Iterables.filter(selection.toList(), Session.class)) {
            sessionsToCloseURI.add(concernedSession.getSessionResource().getURI());
        }
        // This is a workaround to avoid the session to close to be stored
        // in the
        // selection field by the super class (BaseSelectionListener) and
        // hence create a memory leak
        if (!selection.isEmpty()) {
            super.selectionChanged(new StructuredSelection());
        }
    }

    return !sessionsToCloseURI.isEmpty();
}

From source file:org.obiba.opal.web.shell.reporting.ProjectReportTemplatesResource.java

@GET
public Set<Opal.ReportTemplateDto> get() {
    ImmutableSet.Builder<ReportTemplate> setBuilder = ImmutableSet.builder();
    setBuilder.addAll(/*from w ww  .j a  v  a2  s .com*/
            Iterables.filter(reportTemplateService.getReportTemplates(name), new Predicate<ReportTemplate>() {
                @Override
                public boolean apply(ReportTemplate template) {
                    return ReportTemplateAuthorizer.authzGet(template);
                }
            }));
    return Dtos.asDto(setBuilder.build());
}

From source file:org.gradle.plugins.ide.internal.generator.XmlPersistableConfigurationObject.java

@Nullable
protected static Node findFirstWithAttributeValue(@Nullable List<Node> nodes, final String attribute,
        final String value) {
    return nodes == null ? null : Iterables.getFirst(Iterables.filter(nodes, new Predicate<Node>() {
        @Override/*from   ww w.  ja  v a 2s.  c o  m*/
        public boolean apply(Node node) {
            return value.equals(node.attribute(attribute));
        }
    }), null);
}

From source file:domainapp.app.services.homepage.HomePageViewModel.java

@CollectionLayout(render = RenderType.EAGERLY)
@MemberOrder(sequence = "2")
public List<Event> getOpenEvents() {

    return Lists.newArrayList(Iterables.filter(eventRepository.listAll(), new Predicate<Event>() {
        @Override//  ww w .java 2 s.  c om
        public boolean apply(final Event input) {
            return input.isOpenOn(clockService.now());
        }
    }));
}

From source file:com.reprezen.kaizen.oasparser.jsonoverlay.Resolver.java

private static Iterable<JsonNode> findReferenceNodes(JsonNode tree) {
    return Iterables.filter(treeWalk(tree), refNodeFilter);
}

From source file:org.obeonetwork.dsl.uml2.design.tests.automation.common.ModelChangeRecorder.java

public Iterable<EObject> attachedObjects() {
    return Iterables.concat(Iterables.transform(
            Iterables.filter(changes, Predicates.and(Notifications.containmentRef, Notifications.addition)),
            Notifications.toObjectValue));
}

From source file:org.jclouds.openstack.nova.v1_1.compute.loaders.LoadFloatingIpsForInstance.java

@Override
public Iterable<String> load(final ZoneAndId key) throws Exception {
    String zone = key.getZone();/*ww w .j a v  a  2 s.  c  o  m*/
    Optional<FloatingIPClient> ipClientOptional = client.getFloatingIPExtensionForZone(zone);
    if (ipClientOptional.isPresent()) {
        return Iterables.transform(
                Iterables.filter(ipClientOptional.get().listFloatingIPs(), new Predicate<FloatingIP>() {
                    @Override
                    public boolean apply(FloatingIP input) {
                        return key.getId().equals(input.getInstanceId());
                    }
                }), new Function<FloatingIP, String>() {
                    @Override
                    public String apply(FloatingIP input) {
                        return input.getIp();
                    }
                });
    }
    return ImmutableSet.of();
}

From source file:com.netflix.simianarmy.client.aws.chaos.FilteringChaosCrawler.java

/**
 * Return the filtered list of InstanceGroups using the requested predicate. The filter is applied on the InstanceGroup retrieved from the ASGChaosCrawler class.
 * @param list list of InstanceGroups result of the chaos crawler
 * @return The appropriate {@link InstanceGroup}
 */// w ww  . j  a v  a  2 s .  c om
protected List<InstanceGroup> filter(List<InstanceGroup> list) {
    return Lists.newArrayList(Iterables.filter(list, predicate));
}

From source file:com.opengamma.integration.tool.portfolio.xml.v1_0.jaxb.SwapTrade.java

/**
 * Helper method for extracting the pay legs on a swap.
 * @return the pay legs for this trade//  w ww.ja v  a 2 s  . c  o  m
 */
public Iterable<SwapLeg> getPayLegs() {
    return Iterables.filter(getSwapLegs(), new IsPayLegPredicate());
}

From source file:org.gradle.internal.resource.transport.aws.s3.S3ResourceResolver.java

private List<String> resolveFileResourceNames(ObjectListing objectListing) {
    List<S3ObjectSummary> objectSummaries = objectListing.getObjectSummaries();
    if (null != objectSummaries) {
        return ImmutableList.copyOf(Iterables.filter(Iterables.transform(objectSummaries, EXTRACT_FILE_NAME),
                Predicates.notNull()));//from  w w w .  ja  v a2 s  .c om
    }
    return Collections.emptyList();

}