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:net.conquiris.lucene.search.ExplicitComparator.java

/**
* Constructor.//from  www  . ja v a 2  s  .co  m
* @param values Values in sort order. Duplicates and {@code nulls} are filtered out.
*/
private ExplicitComparator(Iterable<? extends T> values) {
    checkNotNull(values);
    ImmutableMap.Builder<T, Integer> builder = ImmutableMap.builder();
    Set<T> visited = Sets.newHashSet();
    int rank = 0;
    for (T value : Iterables.filter(values, Predicates.notNull())) {
        if (visited.add(value)) {
            builder.put(value, rank);
            rank++;
        }
    }
    this.rankMap = builder.build();
    this.otherRank = rank + 1;
}

From source file:org.eclipse.xtext.resource.containers.StateBasedContainer.java

@Override
protected Iterable<IEObjectDescription> filterByURI(Iterable<IEObjectDescription> unfiltered) {
    return Iterables.filter(unfiltered, new Predicate<IEObjectDescription>() {
        private Collection<URI> contents = null;

        @Override/*from ww w . j  a  v a2  s  .  co m*/
        public boolean apply(IEObjectDescription input) {
            if (contents == null) {
                contents = state.getContents();
            }
            URI resourceURI = input.getEObjectURI().trimFragment();
            final boolean contains = contents.contains(resourceURI);
            return contains;
        }
    });
}

From source file:org.eclipse.sirius.editor.tools.internal.marker.SiriusEditorInterpreterMarkerService.java

/**
 * Returns all the Validation Error markers contained in the given resource
 * and relative to the given element only.
 * /* w ww .  j av a2 s .  c o  m*/
 * @param resource
 *            the resource to test
 * @param elementURI
 *            the URI of the element
 * @return all the Validation Error markers contained in the given resource
 *         and relative to the given element only
 */
public static Collection<IMarker> getValidationMarkersForElement(IResource resource, final String elementURI) {
    IMarker[] markers = findResourceMarkers(resource, EValidator.MARKER);
    final Collection<IMarker> validationMarkers;
    if (markers != null) {
        validationMarkers = Lists.newArrayList(markers);
    } else {
        validationMarkers = Lists.newArrayList();
    }
    ArrayList<IMarker> validationMarkersRelativeToElement = Lists
            .newArrayList(Iterables.filter(validationMarkers, new Predicate<IMarker>() {

                public boolean apply(IMarker input) {
                    String uriAttribute = input.getAttribute(EValidator.URI_ATTRIBUTE, null);
                    return elementURI.equals(uriAttribute);
                }

            }));
    return validationMarkersRelativeToElement;
}

From source file:io.crate.execution.engine.collect.RowsTransformer.java

public static Iterable<Row> toRowsIterable(InputFactory inputFactory, ReferenceResolver<?> referenceResolver,
        RoutedCollectPhase collectPhase, Iterable<?> iterable) {
    WhereClause whereClause = collectPhase.whereClause();
    if (whereClause.noMatch()) {
        return Collections.emptyList();
    }/* w w w.j a v a  2  s  .  co m*/
    InputFactory.Context ctx = inputFactory.ctxForRefs(referenceResolver);
    ctx.add(collectPhase.toCollect());
    OrderBy orderBy = collectPhase.orderBy();
    if (orderBy != null) {
        for (Symbol symbol : orderBy.orderBySymbols()) {
            ctx.add(symbol);
        }
    }

    @SuppressWarnings("unchecked")
    Iterable<Row> rows = Iterables.transform(iterable,
            new ValueAndInputRow<>(ctx.topLevelInputs(), ctx.expressions()));
    if (whereClause.hasQuery()) {
        assert DataTypes.BOOLEAN.equals(
                whereClause.query().valueType()) : "whereClause.query() must be of type " + DataTypes.BOOLEAN;

        //noinspection unchecked  whereClause().query() is a symbol of type boolean so it must become Input<Boolean>
        rows = Iterables.filter(rows, InputCondition.asPredicate(ctx.add(whereClause.query())));
    }
    if (orderBy == null) {
        return rows;
    }
    return sortRows(Iterables.transform(rows, Row::materialize), collectPhase);
}

From source file:org.linqs.psl.utils.dataloading.graph.Entity.java

public Iterable<Relation<ET, RT>> getRelations(RT relType, final Subgraph<ET, RT> subgraph) {
    return Iterables.filter(relations.get(relType), new Predicate<Relation<ET, RT>>() {
        @Override/*from   w w  w .  ja  v  a 2s  .  c om*/
        public boolean apply(Relation<ET, RT> rel) {
            return subgraph.containsRelation(rel);
        }

    });
}

From source file:com.eviware.loadui.components.soapui.utils.SoapUiProjectUtils.java

/**
 * Disables all soapUI assertions for the specified TestCase.
 * /*from w w  w  .  ja  v  a2s. co  m*/
 * @param testCase
 */
public static void disableSoapUIAssertions(@Nonnull TestCase testCase) {
    for (Assertable assertableStep : Iterables.filter(testCase.getTestStepList(), Assertable.class))
        for (TestAssertion assertion : assertableStep.getAssertionList())
            ((WsdlMessageAssertion) assertion).setDisabled(true);
}

From source file:com.google.cloud.genomics.dataflow.utils.DataflowWorkarounds.java

/**
 * Shortcut for registering all genomics related classes in dataflow
 *///from  www .ja  va2s  . com
@SuppressWarnings({ "unchecked", "rawtypes" })
public static void registerGenomicsCoders(Pipeline p) {
    LOG.info("Registering coders for genomics classes");

    List<ClassLoader> classLoadersList = new LinkedList<ClassLoader>();
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());

    Collection<URL> urls = newArrayList(Iterables.filter(
            ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0])), new Predicate<URL>() {

                @Override
                public boolean apply(URL url) {
                    return !url.toString().endsWith("jnilib") && !url.toString().endsWith("zip");
                }

            }));

    Reflections reflections = new Reflections(
            new ConfigurationBuilder().setScanners(new SubTypesScanner(), new ResourcesScanner()).setUrls(urls)
                    .filterInputsBy(new FilterBuilder()
                            .include(FilterBuilder.prefix("com.google.api.services.genomics.model"))));

    for (Class clazz : reflections.getSubTypesOf(GenericJson.class)) {
        LOG.info("Registering coder for " + clazz.getSimpleName());
        DataflowWorkarounds.registerCoder(p, clazz, GenericJsonCoder.of(clazz));
    }
}

From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.SizeBothAction.java

@Override
protected boolean calculateEnabled() {
    boolean enabled = super.calculateEnabled();
    if (enabled) {
        for (AbstractDiagramElementContainerEditPart container : Iterables.filter(getSelectedObjects(),
                AbstractDiagramElementContainerEditPart.class)) {
            if (container.isRegion() || (container instanceof AbstractDiagramContainerEditPart
                    && ((AbstractDiagramContainerEditPart) container).isRegionContainer())) {
                enabled = false;//from   w  w w .  j a v a  2 s. co m
                break;
            }
        }
    }
    return enabled && canEditInstance();
}

From source file:jflowmap.util.Log4ExportAppender.java

/**
 * @param timestamp The number of milliseconds elapsed from 1/1/1970.
 *///from   w ww.  ja v  a 2  s  .  c o m
public Iterable<String> getMessagesAfter(final long timestamp) {
    return messagesOf(Iterables.filter(messageEvents, new Predicate<Pair<Long, String>>() {
        @Override
        public boolean apply(Pair<Long, String> input) {
            return input.first() > timestamp;
        }
    }));
}

From source file:org.sonar.core.technicaldebt.DefaultTechnicalDebtModel.java

public List<DefaultCharacteristic> rootCharacteristics() {
    return newArrayList(Iterables.filter(characteristics(), new Predicate<DefaultCharacteristic>() {
        @Override//from w  w  w  .  j  a v a  2  s.com
        public boolean apply(DefaultCharacteristic input) {
            return input.isRoot();
        }
    }));
}