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.business.internal.session.danalysis.SessionVSMUpdater.java

@Override
public void modelerDesciptionFilesLoaded() {
    Collection<Resource> allResources = Lists
            .newArrayList(session.getTransactionalEditingDomain().getResourceSet().getResources());
    for (Resource res : Iterables.filter(allResources,
            new ResourceFileExtensionPredicate(SiriusUtil.DESCRIPTION_MODEL_EXTENSION, true))) {
        // Unload emtpy odesign.
        if (!res.isModified() && res.isLoaded() && res.getContents().isEmpty()) {
            session.unregisterResourceInCrossReferencer(res);
            res.unload();//from  w w w .j a v a2s  .c o m
        }
        // Reload unloaded odesign (ViewpointRegistry can unload them).
        IFile correspondingFile = WorkspaceSynchronizer.getFile(res);
        if (!res.isLoaded() && correspondingFile != null && correspondingFile.exists()) {
            try {
                res.load(Collections.emptyMap());
                if (res.isLoaded() && !res.getContents().isEmpty()) {
                    session.registerResourceInCrossReferencer(res);
                    // Refresh the imports of interpreter in case of new
                    // Java Extension
                    InterpreterRegistry.prepareImportsFromSession(session.getInterpreter(), session);
                }
            } catch (IOException e) {
                SiriusPlugin.getDefault().warning(
                        MessageFormat.format(Messages.SessionVSMUpdater_VSMLoadErrorMsg, res.getURI()), e);
            }
        }
    }
    session.notifyListeners(SessionListener.VSM_UPDATED);
}

From source file:org.onosproject.net.flow.FlowRuleService.java

/**
 * Returns a list of rules filtered by device id and flow live type.
 *
 * @param deviceId the device id to lookup
 * @param liveType the flow live type to lookup
 * @return collection of flow entries/*www.  j av  a  2s  .c  om*/
 */
default Iterable<FlowEntry> getFlowEntriesByLiveType(DeviceId deviceId, FlowEntry.FlowLiveType liveType) {
    return Iterables.filter(getFlowEntries(deviceId), fe -> fe.liveType() == liveType);
}

From source file:org.auraframework.impl.css.parser.omakase.ThemeFunction.java

@Override
public Iterable<Term> terms() {
    return members != null ? Iterables.filter(members, Term.class) : ImmutableList.<Term>of();
}

From source file:com.blacklocus.jres.response.bulk.JresBulkReply.java

public Iterable<JresBulkItemResult> getErrorResults() {
    return Iterables.filter(getResults(), new Predicate<JresBulkItemResult>() {
        @Override/*from   w  w  w. j  a  va  2  s .  c  om*/
        public boolean apply(JresBulkItemResult input) {
            return input.getResult().hasError();
        }
    });
}

From source file:uk.ac.stfc.isis.ibex.epics.observing.FilteredCollectionObservable.java

@Override
protected Collection<T> transform(Pair<Collection<T>, Collection<String>> value) {
    if (value.first == null || value.second == null) {
        return Collections.emptyList();
    }/*from www  .j  a  v a  2 s.c o m*/

    return Lists.newArrayList(Iterables.filter(value.first, filterByName(value.second)));
}

From source file:org.vclipse.configscan.views.ErrorBasedContentProviderExtension.java

@Override
public Object[] getChildren(TreePath parentPath) {
    int segmentCount = parentPath.getSegmentCount();
    Object lastSegment = parentPath.getLastSegment();
    if (segmentCount < 2) {
        if (lastSegment instanceof TestGroup) {
            Iterable<TestCase> filter = Iterables.filter(((TestGroup) lastSegment).getTestCases(),
                    new Predicate<TestCase>() {
                        @Override
                        public boolean apply(TestCase testCase) {
                            return Status.FAILURE == testCase.getStatus();
                        }/*from w  w w. j  a  v a  2s. com*/
                    });
            return Lists.newArrayList(filter).toArray();
        } else if (!(lastSegment instanceof TestRun)) {
            return super.getChildren(new TreePath(new Object[] { lastSegment }));
        }
    } else if (segmentCount == 2) {
        if (lastSegment instanceof TestGroup) {
            return super.getChildren(parentPath);
        } else if (!(lastSegment instanceof TestRun)) {
            return super.getChildren(new TreePath(new Object[] { lastSegment }));
        }
    } else {
        return super.getChildren(parentPath);
    }
    return new Object[0];
}

From source file:com.iamcontent.io.cli.CommandLineDriver.java

protected Iterable<String> commandStrings() {
    licenseWriter.printInteractiveInstructions();
    return Iterables.filter(inputLines(), commandShouldBeProcessed());
}

From source file:org.caleydo.view.tourguide.stratomex.s.StateMachineImpl.java

@Override
public Collection<RootState> getRootStates() {
    return Lists.newArrayList(Iterables.filter(this.states.values(), RootState.class));
}

From source file:org.eclipse.qvtd.compiler.internal.scheduler.SuperRegion.java

@SuppressWarnings("null")
public @NonNull Iterable<OperationRegion> getOperationRegions() {
    return Iterables.filter(allRegions, OperationRegion.class);
}

From source file:io.airlift.discovery.store.PersistentStore.java

@Override
public Iterable<Entry> getAll() {
    return Iterables.filter(Iterables.transform(db, new Function<Map.Entry<byte[], byte[]>, Entry>() {
        @Override//  w  w  w . ja v a  2  s.  com
        public Entry apply(Map.Entry<byte[], byte[]> dbEntry) {
            try {
                return mapper.readValue(dbEntry.getValue(), Entry.class);
            } catch (IOException e) {
                byte[] key = dbEntry.getKey();
                log.error(e, "Corrupt entry " + Arrays.toString(key));

                // delete the corrupt entry... if another node has a non-corrupt version it will be replicated
                db.delete(key);

                // null if filtered below
                return null;
            }
        }
    }), notNull());
}