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:io.joynr.generator.loading.Query.java

public <T> Iterable<T> all(Class<T> type) {
    return Iterables.filter(content, type);
}

From source file:com.openlattice.mail.EmailRequest.java

public EmailRequest(Optional<String> from, String[] to, Optional<String[]> cc, Optional<String[]> bcc) {

    this.from = Preconditions.checkNotNull(from);
    this.to = ImmutableList
            .copyOf(Iterables.filter(Arrays.asList(Preconditions.checkNotNull(to)), new Predicate<String>() {

                @Override/*from  www  . j a  v  a 2  s . co m*/
                public boolean apply(String input) {
                    return StringUtils.isNotBlank(input);
                }

            })).toArray(new String[0]);
    this.cc = Preconditions.checkNotNull(cc);
    this.bcc = Preconditions.checkNotNull(bcc);
    Preconditions.checkState(this.to.length > 0);
}

From source file:org.isisaddons.app.kitchensink.dom.contrib.contributed.PreferenceContributions.java

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public List<FoodStuff> likes(final Person person) {
    return Lists.newArrayList(Iterables.transform(
            Iterables.filter(preferences.listAllPreferences(), Preference.Predicates.preferenceOf(person)),
            Preference.Functions.food()));
}

From source file:org.eclipse.xtext.scoping.impl.MultimapBasedSelectable.java

@Override
public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) {
    if (allDescriptions.isEmpty())
        return Collections.emptyList();
    return Iterables.filter(allDescriptions, new Predicate<IEObjectDescription>() {
        @Override//  w  w w . j  av  a 2  s .c o m
        public boolean apply(IEObjectDescription input) {
            return EcoreUtil2.isAssignableFrom(type, input.getEClass());
        }
    });
}

From source file:org.richfaces.tests.page.fragments.impl.log.LogEntries.java

public LogEntries filter(LogFilterBuilder builder) {
    return new LogEntries(Iterables.filter(this, builder.build()));
}

From source file:pl.softech.eav.domain.specification.Specifications.java

public static <T> List<T> filter(List<T> elements, final Specification<T> specification) {
    checkNotNull(specification);/*from  w ww.  j  av  a2  s . c  om*/
    checkNotNull(elements);
    return Lists.newArrayList(Iterables.filter(elements, new Predicate<T>() {

        @Override
        public boolean apply(T input) {
            return specification.isSafisfiedBy(input);
        }
    }));
}

From source file:edu.byu.nlp.data.docs.DocPipes.java

/**
 * Do feature selection (on the wordIndex itself)
 *//*from   w ww.  j a  v  a 2s  . c o  m*/
public static Indexer<String> selectFeatures(Iterable<Map<String, Object>> data,
        FeatureSelectorFactory featureSelectorFactory, Indexer<String> wordIndex) {

    if (featureSelectorFactory != null) {
        // we don't want to double-count some document when it comes to calculating feature selection
        // only include 1 document (with data) per source
        Iterable<Map<String, Object>> filtered = Lists
                .newArrayList(Iterables.filter(data, new Predicate<Map<String, Object>>() {
                    Set<String> usedSources = Sets.newHashSet();

                    @Override
                    public boolean apply(Map<String, Object> input) {
                        String source = (String) DataStreamInstance.getSource(input);
                        if (DataStreamInstance.getData(input) == null || usedSources.contains(source)) {
                            return false;
                        }
                        usedSources.add(source);
                        return true;
                    }
                }));
        // Create count vectors
        Transform vectorizer = DataStreams.Transforms.transformFieldValue(DataStreamInstance.DATA,
                new CountVectorizer<String>(wordIndex));
        Iterable<Map<String, Object>> countVectors = Iterables.transform(filtered, vectorizer);

        // Feature selection
        int numFeatures = wordIndex.size();
        BitSet features = featureSelectorFactory.newFeatureSelector(numFeatures).process(countVectors);
        logger.info("Number of features before selection = " + numFeatures);
        wordIndex = wordIndex.retain(features);
        logger.info("Number of features after selection = " + wordIndex.size());
    }
    return wordIndex;
}

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

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

    return Lists.newArrayList(Iterables.filter(eventRepository.listAll(), new Predicate<Event>() {
        @Override/*w w w  .  j  a va  2 s  . com*/
        public boolean apply(final Event input) {
            return input.isActiveOn(clockService.now());
        }
    }));
}

From source file:org.eclipse.emf.compare.internal.spec.ConflictSpec.java

/**
 * {@inheritDoc}/*from   w w w  .j  a va2  s .c o  m*/
 * 
 * @see org.eclipse.emf.compare.impl.ConflictImpl#getRightDifferences()
 */
@Override
public EList<Diff> getRightDifferences() {
    final EList<Diff> rightDiffs = new BasicEList<Diff>();
    for (Diff diff : Iterables.filter(getDifferences(),
            EMFComparePredicates.fromSide(DifferenceSource.RIGHT))) {
        rightDiffs.add(diff);
    }
    return rightDiffs;
}

From source file:brooklyn.location.affinity.EntityTypeAntiAffinityRule.java

@Override
public boolean apply(@Nullable Location input) {
    Collection<Entity> all = getManagementContext().getEntityManager().getEntities();
    return Iterables.all(Iterables.filter(all, entityType),
            Predicates.not(EntityPredicates.withLocation(input)));
}