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.cognifide.aet.job.common.comparators.accessibility.report.AccessibilityReportGenerator.java

private void invoke() {
    Iterable<AccessibilityIssue> errors = Iterables.filter(nonExcludedIssues,
            new IssueTypePredicate(IssueType.ERROR));
    errorCount = Iterables.size(errors);
    warningCount = filterAndCount(!configuration.isShowWarning(), IssueType.WARN);
    noticeCount = filterAndCount(!configuration.isShowNotice(), IssueType.NOTICE);

    sortIssues(nonExcludedIssues);//from ww  w  .ja v a2 s.c o  m
    sortIssues(excludedIssues);
}

From source file:ca.cutterslade.match.scheduler.Slot.java

public Iterable<Match> getSameGymAndDayMatches(Iterable<Match> matches) {
    return Iterables.filter(matches, gymDayMatchPredicate);
}

From source file:org.apache.provisionr.core.activities.CheckProcessesEnded.java

@Override
public void execute(DelegateExecution execution) {
    @SuppressWarnings("unchecked")
    List<String> processIds = (List<String>) execution.getVariable(variableWithProcessIds);

    List<String> ended = Lists.newArrayList(Iterables.filter(processIds, new Predicate<String>() {
        @Override/*from   w  w  w  . j a  v a  2s  . c  o  m*/
        public boolean apply(String processInstanceId) {
            ProcessInstance instance = runtimeService.createProcessInstanceQuery()
                    .processInstanceId(processInstanceId).singleResult();

            return instance == null || instance.isEnded();
        }
    }));

    boolean done = (processIds.size() == ended.size());
    execution.setVariable(resultVariable, done);

    if (done) {
        LOG.info("All background processes ENDED: {}", processIds);
    } else {
        if (LOG.isInfoEnabled()) {
            LOG.info("Still waiting for: {}",
                    Sets.difference(ImmutableSet.copyOf(processIds), ImmutableSet.copyOf(ended)));
        }
    }
}

From source file:org.killbill.commons.profiling.ProfilingData.java

public List<ProfilingDataItem> getRawData() {
    if (rawData == null || rawData.isEmpty()) {
        return Collections.emptyList();
    }/*from   ww w  .ja va  2 s . c o m*/
    return Lists.newArrayList(Iterables.filter(rawData, new Predicate<ProfilingDataItem>() {
        @Override
        public boolean apply(final ProfilingDataItem input) {
            return profileFeature.isDefined(input.getProfileType());
        }
    }));
}

From source file:org.eclipse.xtext.xbase.scoping.SyntaxFilteredScope.java

@Override
public Iterable<IEObjectDescription> getElements(EObject object) {
    return Iterables.filter(parent.getElements(object), Predicates.<Object>in(values));
}

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

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(contributed = Contributed.AS_ASSOCIATION)
public FoodStuff firstLove(final Person person) {
    final List<FoodStuff> loves = Lists
            .newArrayList(/*from  w  ww.ja  v a2s . com*/
                    Iterables
                            .transform(
                                    Iterables.filter(preferences.listAllPreferences(),
                                            Preference.Predicates.preferenceOf(person,
                                                    Preference.PreferenceType.LIKE)),
                                    Preference.Functions.food()));
    return loves.isEmpty() ? null : loves.get(0);
}

From source file:co.cask.cdap.data2.transaction.queue.hbase.HBaseQueueProducer.java

public HBaseQueueProducer(HTable hTable, QueueName queueName, QueueMetrics queueMetrics,
        HBaseQueueStrategy queueStrategy, Iterable<? extends ConsumerGroupConfig> consumerGroupConfigs) {
    super(queueMetrics, queueName);
    this.queueStrategy = queueStrategy;
    // Make sure only one config per consumer group
    this.consumerGroupConfigs = ImmutableList
            .copyOf(Iterables.filter(consumerGroupConfigs, new Predicate<ConsumerGroupConfig>() {
                private final Set<Long> seenGroups = Sets.newHashSet();

                @Override//from   w  w w . ja  v a  2 s. c o m
                public boolean apply(ConsumerGroupConfig config) {
                    return seenGroups.add(config.getGroupId());
                }
            }));
    this.queueRowPrefix = QueueEntryRow.getQueueRowPrefix(queueName);
    this.rollbackKeys = Lists.newArrayList();
    this.hTable = hTable;
}

From source file:org.opensaml.profile.logic.IPRangePredicate.java

/**
 * Set the address ranges to check against.
 * //www  .  ja  va  2 s . co m
 * @param ranges    address ranges to check against
 */
public void setAddressRanges(@Nonnull @NonnullElements Iterable<IPRange> ranges) {
    Constraint.isNotNull(ranges, "Address range collection cannot be null");

    addressRanges = new ArrayList<>();
    for (final IPRange range : Iterables.filter(ranges, Predicates.notNull())) {
        addressRanges.add(range);
    }
}

From source file:org.eclipse.xtext.builder.impl.javasupport.ProjectClasspathChangeListener.java

@Override
public void elementChanged(ElementChangedEvent event) {
    if (workspace != null && workspace.isAutoBuilding()) {
        try {//from  w w  w . j  av a 2  s .  c om
            if (event.getDelta() != null) {
                Set<IJavaProject> javaProjects = getJavaProjectsWithClasspathChange(event.getDelta());
                if (!javaProjects.isEmpty()) {
                    Set<IProject> projects = Sets.newHashSet(Iterables
                            .filter(Iterables.transform(javaProjects, new Function<IJavaProject, IProject>() {
                                @Override
                                public IProject apply(IJavaProject from) {
                                    return from.getProject();
                                }
                            }), Predicates.notNull()));
                    dirtyStateManager.notifyListeners(new CoarseGrainedChangeEvent());
                    buildManager.scheduleBuildIfNecessary(projects, IBuildFlag.FORGET_BUILD_STATE_ONLY);
                }
            }
        } catch (WrappedException e) {
            log.error(e.getCause().getMessage(), e.getCause());
        } catch (RuntimeException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:org.nuxeo.ecm.automation.io.services.enricher.UserPermissionsContentEnricher.java

private Iterable<String> getPermissions(final DocumentModel doc) {
    final CoreSession session = doc.getCoreSession();
    final Principal principal = session.getPrincipal();

    return Iterables.filter(availablePermissions, new Predicate<String>() {
        public boolean apply(String permission) {
            return session.hasPermission(principal, doc.getRef(), permission);
        }//from   w  ww  . j av  a2s .c  o m
    });
}