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.isisaddons.module.togglz.fixture.dom.module.demo.TogglzDemoObjects.java

@Action(semantics = SemanticsOf.SAFE)
@ActionLayout(bookmarking = BookmarkPolicy.AS_ROOT)
@MemberOrder(sequence = "2")
public List<TogglzDemoObject> findByName(final String name) {
    return Lists/*from  w ww . j a va 2  s  .  c o m*/
            .newArrayList(Iterables.filter(listAll(), o -> o.getName() != null && o.getName().contains(name)));
}

From source file:com.totsp.tom.Tom.java

public Finally<T> where(Predicate<T> predicate) {
    this.source = Iterables.filter(this.source, predicate);
    return this;
}

From source file:org.splevo.ui.refinementbrowser.action.ApplySelectedRefinementsAction.java

@Override
protected List<Refinement> getRefinementsFromRefinementBrowser() {
    final List<Refinement> selectedRefinements = this.vpmRefinementBrowser.getSelectedRefinementsFromMainView();

    /**//w w  w  .  j a v a 2  s .c om
     * We have to repair the selected refinements in the following situation:
     * Context: Group A contains Merges M1 and M2
     * Scenario: User selects A and M1
     * 
     * Fixes to apply:
     * - F1: M1 has to be removed from the refinements to apply because it is already contained in A
     * - F2: M2 has to be removed from A as this is the users choice
     * - F3: the variation points of M2 have to be added to A in order to do a correct grouping
     * 
     */

    // F1
    Iterable<Refinement> relevantSelectedRefinements = Iterables.filter(selectedRefinements,
            new Predicate<Refinement>() {
                @Override
                public boolean apply(final Refinement selectedRefinement) {
                    return !Iterables.any(selectedRefinements, new Predicate<Refinement>() {
                        @Override
                        public boolean apply(final Refinement possibleParent) {
                            return possibleParent.getSubRefinements().contains(selectedRefinement);
                        }
                    });
                }
            });

    // F2 and F3
    Iterable<Refinement> fixedRelevantSelectedRefinements = Iterables.transform(relevantSelectedRefinements,
            new Function<Refinement, Refinement>() {
                @Override
                public Refinement apply(Refinement arg0) {
                    for (Iterator<Refinement> iter = arg0.getSubRefinements().iterator(); iter.hasNext();) {
                        Refinement r = iter.next();
                        if (!selectedRefinements.contains(r)) {
                            arg0.getVariationPoints().addAll(r.getVariationPoints());
                            iter.remove();
                        }
                    }
                    return arg0;
                }
            });

    return Lists.newArrayList(fixedRelevantSelectedRefinements);
}

From source file:org.obiba.opal.web.project.permissions.ProjectSubjectPermissionsResource.java

/**
 * Get all permissions of a subject in the project.
 *
 * @param domain//ww w. j a v a 2s. c  o  m
 * @param type
 * @return
 */
@GET
public Iterable<Opal.Acl> getSubjectPermissions(@QueryParam("type") @DefaultValue("USER") SubjectType type) {

    // make sure project exists
    projectService.getProject(name);

    Iterable<SubjectAclService.Permissions> permissions = Iterables.concat(
            subjectAclService.getSubjectNodeHierarchyPermissions(DOMAIN, getProjectNode(),
                    type.subjectFor(principal)),
            Iterables.filter(subjectAclService.getSubjectNodeHierarchyPermissions(DOMAIN, getDatasourceNode(),
                    type.subjectFor(principal)), new MagmaPermissionsPredicate()));

    return Iterables.transform(permissions, PermissionsToAclFunction.INSTANCE);
}

From source file:org.janusgraph.diskstorage.configuration.TransactionalConfiguration.java

@Override
public Iterable<String> getKeys(final String prefix) {
    return Iterables.concat(Iterables.filter(writtenValues.keySet(), new Predicate<String>() {
        @Override//from w  ww.j  a  v  a 2 s .  c om
        public boolean apply(@Nullable String s) {
            return s.startsWith(prefix);
        }
    }), Iterables.filter(config.getKeys(prefix), new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return !writtenValues.containsKey(s);
        }
    }));
}

From source file:org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions.java

@Override
public Iterable<IResourceDescription> getAllResourceDescriptions() {
    if (data != null) {
        return data.getAllResourceDescriptions();
    }//from   w  w  w  . j  a va2 s  . c om
    return Iterables.filter(new Iterable<IResourceDescription>() {
        @Override
        public Iterator<IResourceDescription> iterator() {
            return new AbstractIterator<IResourceDescription>() {
                int index = 0;
                List<Resource> resources = resourceSet.getResources();

                @Override
                protected IResourceDescription computeNext() {
                    if (resources.size() <= index)
                        return endOfData();
                    Resource resource = resources.get(index);
                    index++;
                    return getResourceDescription(resource.getURI());
                }
            };
        }
    }, Predicates.notNull());

}

From source file:org.jnario.feature.ui.launching.FeatureJavaElementDelegate.java

@Override
protected JvmIdentifiableElement findAssociatedJvmElement(EObject element) {
    if (element == null) {
        return null;
    }//from w w  w. jav a2  s . c o  m
    EObject toExecute = EcoreUtil2.getContainerOfType(element, Scenario.class);
    if (toExecute == null) {
        toExecute = EcoreUtil2.getContainerOfType(element, Feature.class);
    }
    if (toExecute == null) {
        FeatureFile featureFile = EcoreUtil2.getContainerOfType(element, FeatureFile.class);
        Iterable<Feature> features = Iterables.filter(featureFile.getXtendTypes(), Feature.class);
        Iterator<Feature> iterator = features.iterator();
        if (iterator.hasNext()) {
            toExecute = iterator.next();
        }
    }
    if (toExecute == null) {
        return null;
    }
    return super.findAssociatedJvmElement(toExecute);
}

From source file:org.cloudsmith.geppetto.graph.catalog.CatalogGraphProducer.java

private StyleSet labelStyleForResource(CatalogResource r, final IPath root) {

    // Produce a sorted list of parameters (that skips parameters that are really dependencies)
    List<LabelRow> labelRows = Lists.newArrayList();
    CatalogResourceParameter[] sortedProperties = Iterables.toArray(
            Iterables.filter(getParameterIterable(r), regularParameterPredicate),
            CatalogResourceParameter.class);

    Arrays.sort(sortedProperties, new Comparator<CatalogResourceParameter>() {

        @Override/*from  w  w  w . j  av  a 2s. c om*/
        public int compare(CatalogResourceParameter o1, CatalogResourceParameter o2) {
            return o1.getName().compareTo(o2.getName());
        }

    });

    // Add a labelRow for the type[id]
    StringBuilder builder = new StringBuilder();
    builder.append(r.getType());
    builder.append("[");
    builder.append(r.getTitle());
    builder.append("]");

    int width = 0;
    boolean hasParameters = sortedProperties.length > 0;
    boolean hasFooter = r.getFile() != null;
    if (hasParameters || hasFooter)
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));

    labelRows.add(getStyles().labelRow(STYLE_ResourceTitleRow, //
            getStyles().labelCell(STYLE_ResourceTitleCell, builder.toString(), Span.colSpan(3))));
    width += builder.length();

    // Rendering of separator line fails in graphviz 2.28 with an error
    // labelRows.add(getStyles().rowSeparator());
    if (hasParameters || hasFooter) {
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
        labelRows.add(
                getStyles().labelRow("RowSeparator", getStyles().labelCell("HRCell", "", Span.colSpan(3))));
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
    }
    // parameters
    for (CatalogResourceParameter a : sortedProperties) {
        final String aName = a.getName();

        // output file contents as "DATA" as we can't fit the entire contents into a cell.
        List<String> values = "content".equals(aName) ? Lists.newArrayList("DATA") : a.getValue();
        builder = new StringBuilder();
        for (String v : values) {
            builder.append(v);
            builder.append(" ");
        }
        // remove trailing space
        builder.deleteCharAt(builder.length() - 1);
        String value = builder.toString();

        labelRows.add(getStyles().labelRow(STYLE_ResourcePropertyRow, //
                getStyles().labelCell(STYLE_ResourcePropertyName, a.getName()), //
                getStyles().labelCell(STYLE_ResourcePropertyValue, DOUBLE_RIGHT_ARROW + value, Span.colSpan(2)) //
        ));

        int tmpWidth = a.getName().length() + value.length() + 2;
        if (tmpWidth > width)
            width = tmpWidth;
    }

    // A footer with filename[line]
    // (is not always present)
    if (hasFooter) {
        builder = new StringBuilder();
        // shorten the text by making it relative to root if possible
        if (root != null)
            builder.append(new Path(r.getFile()).makeRelativeTo(root).toString());
        else
            builder.append(r.getFile());
        if (r.getLine() != null) {
            builder.append("[");
            builder.append(r.getLine());
            builder.append("]");
        }
        String tooltip = builder.toString();
        if (builder.length() > width) {
            builder.delete(0, builder.length() - width);
            builder.insert(0, "[...]");
        }

        if (hasParameters)
            labelRows.add(getStyles().labelRow("RowSeparator",
                    getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
        int line = -1;
        try {
            line = Integer.valueOf(r.getLine());
        } catch (NumberFormatException e) {
            line = -1;
        }

        labelRows.add(getStyles().labelRow(STYLE_ResourceFileInfoRow, //
                getStyles().labelCell(STYLE_ResourceFileInfoCell, builder.toString(), Span.colSpan(3))
                        .withStyles(//
                                getStyles().tooltip(tooltip), //
                                getStyles().href(
                                        getHrefProducer().hrefToManifest(new Path(r.getFile()), root, line)) //
                )) //
        );
    } else if (hasParameters) {
        // add a bit of padding at the bottom if there is no footer
        labelRows.add(getStyles().labelRow("RowSeparator",
                getStyles().labelCell("SpacingCell", "", Span.colSpan(3))));
    }

    return StyleSet.withStyle(//
            getStyles().labelFormat(//
                    getStyles().labelTable(STYLE_ResourceTable, //
                            labelRows.toArray(new LabelRow[labelRows.size()]))));

}

From source file:org.summer.dsl.model.ui.notification.LayeredTypeResourceDescription.java

public Iterable<IEObjectDescription> getExportedObjectsByType(final EClass type) {
    Iterable<IEObjectDescription> additionallyFiltered = Iterables.filter(additionallyExported,
            new Predicate<IEObjectDescription>() {
                public boolean apply(IEObjectDescription input) {
                    return EcoreUtil2.isAssignableFrom(type, input.getEClass());
                }/*from   w w  w.ja  v  a 2s . c  o m*/
            });
    return Iterables.concat(delegate.getExportedObjectsByType(type), additionallyFiltered);
}

From source file:org.sonar.updatecenter.common.PluginReferential.java

/**
 * @return the list of plugins where last releases is master releases
 *//*  ww  w  .j  ava2 s  .  c om*/
public List<Plugin> getLastMasterReleasePlugins() {
    return newArrayList(Iterables.filter(plugins, new Predicate<Plugin>() {
        public boolean apply(Plugin input) {
            return input.getLastRelease().isMaster();
        }
    }));
}