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.ext.emf.EClassQuery.java

/**
 * Returns all the non-containment features of the queried {@link EClass}.
 * /* ww  w.ja va 2s .  com*/
 * @return all the non-containment features of the {@link EClass}.
 */
public Collection<EStructuralFeature> getAllNonContainmentFeatures() {
    return ImmutableList.copyOf(
            Iterables.filter(eClass.getEAllStructuralFeatures(), Predicates.not(new IsContaintmentFeature())));
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.refresh.SequenceRefreshExtension.java

/**
 * {@inheritDoc}/*w w  w .j  av a2  s.com*/
 */
public void beforeRefresh(DDiagram dDiagram) {
    if (dDiagram instanceof SequenceDDiagram) {
        currentDiagram = (SequenceDDiagram) dDiagram;

        Collection<DDiagramElement> nodeEvents = getEventsToSync(currentDiagram);

        if (nodeEvents.size() != 0) {
            flags = Maps.newHashMapWithExpectedSize(nodeEvents.size());
            for (DDiagramElement elt : nodeEvents) {
                Iterable<AbsoluteBoundsFilter> flag = Iterables.filter(elt.getGraphicalFilters(),
                        AbsoluteBoundsFilter.class);
                EObject semanticTarget = elt.getTarget();
                if (semanticTarget != null && Iterables.size(flag) == 1) {
                    flags.put(semanticTarget, Iterables.getOnlyElement(flag));
                }
            }
        }
    }
}

From source file:org.eclipselabs.spray.xtext.scoping.AliasingScope.java

/**
 * Creates the aliasing scope.//from   w  w w  .j  a  va2 s . co  m
 * 
 * @param parent
 *            Parent scope
 * @param aliasingFunction
 *            A function that maps qualified names to their aliases
 */
public AliasingScope(IScope parent, final Function<QualifiedName, QualifiedName> aliasingFunction) {
    super(IScope.NULLSCOPE, false);
    final Function<IEObjectDescription, IEObjectDescription> toAliasedDescription = new Function<IEObjectDescription, IEObjectDescription>() {
        @Override
        public IEObjectDescription apply(IEObjectDescription input) {
            // the alias function might result into null, return null in this case. The nulls will be filtered afterwards
            final QualifiedName alias = aliasingFunction.apply(input.getQualifiedName());
            return alias != null ? new AliasedEObjectDescription(alias, input) : null;
        }
    };
    elements = Iterables.filter(Iterables.transform(parent.getAllElements(), toAliasedDescription),
            Predicates.notNull());
}

From source file:de.monticore.codegen.mc2cd.manipul.RemoveRedundantSupertypesManipulation.java

private void removeRedundantSuperTypes(List<ASTReferenceType> superClasses) {
    for (int i = 0; i < superClasses.size();) {
        ASTReferenceType inspectedAttribute = superClasses.get(i);
        Iterable<ASTReferenceType> remainingAttributes = Iterables.filter(superClasses,
                attribute -> !attribute.equals(inspectedAttribute));
        if (isRedundant(inspectedAttribute, remainingAttributes)) {
            superClasses.remove(i);//from   www .ja  v  a 2s. c o m
        } else {
            i++;
        }
    }
}

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

@Override
public Iterable<? extends Hardware> 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()),
            sizeForVAppTemplateProvider.get().withParent(from));
}

From source file:com.cloudera.oryx.app.serving.als.MostPopularItems.java

static List<IDCount> mapTopCountsToIDCounts(Map<String, Integer> counts, int howMany, int offset,
        final Rescorer rescorer) {
    Iterable<Pair<String, Integer>> countPairs = Iterables.transform(counts.entrySet(),
            new Function<Map.Entry<String, Integer>, Pair<String, Integer>>() {
                @Override/*from   w w  w .j a  v a 2 s  .  c o m*/
                public Pair<String, Integer> apply(Map.Entry<String, Integer> input) {
                    return new Pair<>(input.getKey(), input.getValue());
                }
            });

    if (rescorer != null) {
        countPairs = Iterables.filter(countPairs, new Predicate<Pair<String, Integer>>() {
            @Override
            public boolean apply(Pair<String, Integer> input) {
                return !rescorer.isFiltered(input.getFirst());
            }
        });
    }

    List<Pair<String, Integer>> allTopCountPairs = Ordering.from(PairComparators.<Integer>bySecond())
            .greatestOf(countPairs, howMany + offset);
    List<Pair<String, Integer>> topCountPairs = selectedSublist(allTopCountPairs, howMany, offset);

    return Lists.transform(topCountPairs, new Function<Pair<String, Integer>, IDCount>() {
        @Override
        public IDCount apply(Pair<String, Integer> idCount) {
            return new IDCount(idCount.getFirst(), idCount.getSecond());
        }
    });
}

From source file:org.jclouds.examples.rackspace.clouddns.DeleteDomains.java

private void deleteAllDomains() throws TimeoutException {
    System.out.format("Delete Domains%n");

    Set<Domain> allDomains = dnsApi.getDomainApi().list().concat().toSet();
    Iterable<Domain> topLevelDomains = Iterables.filter(allDomains, IS_DOMAIN);
    Iterable<Integer> topLevelDomainIds = Iterables.transform(topLevelDomains, GET_DOMAIN_ID);

    awaitComplete(dnsApi, dnsApi.getDomainApi().delete(topLevelDomainIds, true));

    System.out.format("  Deleted %s top level domains and all subdomains%n", Iterables.size(topLevelDomainIds));
}

From source file:org.isisaddons.wicket.timeline.cpt.ui.EventProviderAbstract.java

private void createEvents(final EntityCollectionModel model, final String TimelineName) {
    final Collection<ObjectAdapter> entityList = model.getObject();
    final Iterable<Event> events = Iterables.filter(Iterables.transform(entityList, newEvent(TimelineName)),
            NOT_NULL);/*from   w  w  w .  j a va2 s  .  c om*/
    for (final Event event : events) {
        eventById.put(event.getId(), event);
    }
}

From source file:uk.co.onehp.trickle.dao.HibernateBetDao.java

@Override
public List<Bet> getBetsToPlace() {
    List<Bet> bets = incompleteBets();
    List<Bet> filteredBets;
    filteredBets = Lists.newArrayList(Iterables.filter(bets, new Predicate<Bet>() {
        @Override/*w  ww. j  a v  a 2  s.  co m*/
        public boolean apply(Bet bet) {
            return new LocalDateTime().isAfter(bet.getHorse().getRace().getStartTime()
                    .minusSeconds(DateUtil.getMostSeconds(bet.getUnprocessedTimings())));
        }
    }));
    return filteredBets;
}

From source file:org.eclipse.xtext.ui.editor.outline.impl.OutlineFilterAndSorter.java

protected Iterable<IFilter> getEnabledFilters() {
    return Iterables.filter(filters, new Predicate<IFilter>() {
        @Override//from www .  j  av a  2 s  .co m
        public boolean apply(IFilter filter) {
            return filter.isEnabled();
        }
    });
}