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:com.isotrol.impe3.core.engine.ContentTypeRoutingMap.java

private ContentTypeRoutingMap(final ContentTypes contentTypes, final Predicate<? super ContentType> predicate,
        final Segmenter segmenter) {
    final Iterable<ContentType> types = Iterables.filter(contentTypes.values(), predicate);
    final CacheLoader<Locale, ImmutableMap<String, ContentType>> creation = new CacheLoader<Locale, ImmutableMap<String, ContentType>>() {
        public ImmutableMap<String, ContentType> load(Locale from) {
            try {
                // No builder to avoid errors because of duplicates.
                final Map<String, ContentType> map = Maps.newHashMap();
                for (ContentType c : types) {
                    try {
                        final String segment = segmenter.get(from, c);
                        if (segment != null) {
                            map.put(segment, c);
                        }/*from w w  w  .java  2  s .  c  om*/
                    } catch (RuntimeException e) {
                        Loggers.core().error("Unable to compute CTRMap segment for content type [{}]: {}",
                                new Object[] { c.getId(), e.getMessage() });
                    }
                }
                return ImmutableMap.copyOf(map);
            } catch (RuntimeException e) {
                Loggers.core().error("Unable to compute CTRMap value map for locale [{}]: {}",
                        new Object[] { from, e.getMessage() });
                return ImmutableMap.of();
            }
        }
    };
    this.cache = CacheBuilder.newBuilder().build(creation);
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.migration.BorderSizeRepresentationFileMigrationParticipant.java

@Override
protected void postLoad(DAnalysis dAnalysis, Version loadedVersion) {
    // Replace all borderSize of Container equals to 0 by 1 and replace all
    // borderSizeComputationExpression of Container equals to "0" by "1". If
    // the expression is not "0" (default value), we let the borderSize
    // unchanged.
    if (loadedVersion.compareTo(MIGRATION_VERSION) < 0) {
        for (DView dView : dAnalysis.getOwnedViews()) {
            for (DDiagram dDiagram : Iterables.filter(dView.getOwnedRepresentations(), DDiagram.class)) {
                for (DDiagramElementContainer diagramElement : dDiagram.getContainers()) {
                    if (diagramElement.getStyle() instanceof BorderedStyle) {
                        BorderedStyle containerBorderedStyle = (BorderedStyle) diagramElement.getStyle();
                        if ("0".equals(containerBorderedStyle.getBorderSizeComputationExpression())) { //$NON-NLS-1$
                            containerBorderedStyle.setBorderSizeComputationExpression("1"); //$NON-NLS-1$
                            if (containerBorderedStyle.getBorderSize().intValue() == 0) {
                                containerBorderedStyle.setBorderSize(1);
                            }//from   www.j  av a  2  s  . co m
                        }
                    }
                }
            }
        }

    }
}

From source file:cc.recommenders.evaluation.distribution.calc.QueryTypeProvider.java

@Override
protected void logResults() {

    for (String appPrefix : new String[] { "Q0_", "QNM_" }) {
        append("\n%%%%%%%%%% prepend '%s' %%%%%%%%%%\n", appPrefix);
        Iterable<String> apps = Iterables.filter(allApps, startsWith(appPrefix));
        Iterable<NM> nms = Iterables.filter(results.keySet(), useNM(appPrefix));
        logSubResult(appPrefix, apps, nms);
    }/* w  w  w. j a v a2s . c  o m*/
}

From source file:org.eclipse.sirius.tests.swtbot.sequence.condition.CheckNumberOfChildren.java

public boolean test() throws Exception {
    List<SWTBotGefEditPart> children = gefBot.children();
    final Matcher<? extends GraphicalEditPart> instanceOf = IsInstanceOf.instanceOf(editPartClass);
    Predicate<SWTBotGefEditPart> requested = new Predicate<SWTBotGefEditPart>() {
        /**/*from w  ww  . j a  v a 2s .c o m*/
         * {@inheritDoc}
         */
        public boolean apply(SWTBotGefEditPart input) {
            return instanceOf.matches(input);
        }
    };

    return Iterables.size(Iterables.filter(children, requested)) == expectedEditPartNumber;

}

From source file:todoapp.dom.module.similarto.SimilarToContributions.java

@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
@Action(semantics = SemanticsOf.SAFE)
public List<ToDoItem> similarTo(final ToDoItem toDoItem) {
    final List<ToDoItem> similarToDoItems = allMatches(new QueryDefault<>(ToDoItem.class,
            "findByAtPathAndCategory", "atPath", currentUsersAtPath(), "category", toDoItem.getCategory()));
    return Lists.newArrayList(Iterables.filter(similarToDoItems, excluding(toDoItem)));
}

From source file:org.opentestsystem.shared.progman.transformer.TenantComponentTransformer.java

@Override
public Tenant apply(final Tenant tenant) {
    if (tenant != null && tenant.getTenantSubscriptions() != null) {
        final Iterable<TenantSubscription> matchingTenantSubscriptionList = Iterables.transform(
                Iterables.filter(tenant.getTenantSubscriptions(), this.matchingTenantSub),
                this.tenantSubscriptionTransformer);
        final List<TenantSubscription> tenantSubsToPreserve = Lists.newArrayList(
                Iterables.filter(tenant.getTenantSubscriptions(), Predicates.not(this.matchingTenantSub)));
        if (this.retain) {
            Iterables.addAll(tenantSubsToPreserve, matchingTenantSubscriptionList);
        }//from w  w  w . j a  v a 2s  . com
        tenant.setTenantSubscriptions(tenantSubsToPreserve);
    }
    return tenant;
}

From source file:org.apache.brooklyn.location.jclouds.pool.MachineSet.java

public MachineSet filtered(Predicate<NodeMetadata>... criteria) {
    return new MachineSet(Iterables.filter(members, MachinePoolPredicates.compose(criteria)));
}

From source file:org.jclouds.vcloud.compute.functions.ImagesInOrg.java

@Override
public Iterable<? extends Image> apply(Org from) {
    Iterable<? extends CatalogItem> catalogs = allCatalogItemsInOrg.apply(from);
    Iterable<? extends VAppTemplate> vAppTemplates = vAppTemplatesForCatalogItems.apply(catalogs);
    return Iterables.transform(Iterables.filter(vAppTemplates, Predicates.notNull()),
            imageForVAppTemplateProvider.get().withParent(from));
}

From source file:org.opendaylight.ovsdb.openstack.netvirt.impl.ProviderNetworkManagerImpl.java

@Override
public NetworkingProvider getProvider(Node node) {
    if (nodeToProviderMapping.get(node) != null) {
        return nodeToProviderMapping.get(node);
    }//from   w w  w.ja  va  2 s . c om

    final String targetVersion = Constants.OPENFLOW13;
    Predicate<ProviderEntry> providerEntryPredicate = new Predicate<ProviderEntry>() {
        @Override
        public boolean apply(ProviderEntry providerEntry) {
            //ToDo: This should match on southboundProtocol and providerType too
            return providerEntry.getProperties().get(Constants.OPENFLOW_VERSION_PROPERTY).equals(targetVersion);
        }
    };

    Iterable<ProviderEntry> matchingProviders = Iterables.filter(providers.values(), providerEntryPredicate);
    if (!matchingProviders.iterator().hasNext()) {
        logger.error("No providers matching {} found", targetVersion);
    }

    // Return the first match as only have one matching provider today
    // ToDo: Tie-breaking logic
    NetworkingProvider provider = matchingProviders.iterator().next().getProvider();
    nodeToProviderMapping.put(node, provider);
    return provider;
}

From source file:org.fuusio.api.nfc.SmartPosterRecord.java

/**
 * Returns the first element of {@code elements} which is an instance of {@code type}, or
 * {@code null} if no such element exists.
 *//*from   ww w . ja  va2 s . com*/
private static <T> T getFirstIfExists(final Iterable<?> elements, final Class<T> type) {
    final Iterable<T> filtered = Iterables.filter(elements, type);
    T instance = null;

    if (!Iterables.isEmpty(filtered)) {
        instance = Iterables.get(filtered, 0);
    }
    return instance;
}