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.diagram.ui.internal.edit.parts.SiriusNoteEditPart.java

/**
 * Redirect the direct edit request to the
 * {@link DescriptionCompartmentEditPart}.
 * //from  w  w w . j  a  v a2 s .c om
 * @param request
 *            the direct edit request
 */
@Override
protected void performDirectEditRequest(Request request) {
    Iterable<DescriptionCompartmentEditPart> descriptionCompartmentEditPartsfilter = Iterables
            .filter(this.getChildren(), DescriptionCompartmentEditPart.class);
    if (Iterables.size(descriptionCompartmentEditPartsfilter) == 1) {
        DescriptionCompartmentEditPart descriptionCompartmentEditPart = Iterables
                .getOnlyElement(descriptionCompartmentEditPartsfilter);
        descriptionCompartmentEditPart.performRequest(request);
    }
}

From source file:com.opengamma.integration.tool.portfolio.xml.v1_0.conversion.PortfolioDocumentConverterV1_0.java

@Override
public Iterable<VersionedPortfolioHandler> convert(PortfolioDocumentV1_0 portfolioDocument) {

    Iterable<Portfolio> portfolios = extractPortfolios(portfolioDocument);

    Iterable<VersionedPortfolioHandler> transformed = Iterables.transform(portfolios, new PortfolioExtractor());

    // Portfolios with errors will leave nulls in the iterable which we need to remove
    return Iterables.filter(transformed, new Predicate<VersionedPortfolioHandler>() {
        @Override//  ww  w .j  a  va  2s .  co m
        public boolean apply(VersionedPortfolioHandler versionedPortfolioHandler) {
            return versionedPortfolioHandler != null;
        }
    });
}

From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.utils.Utils.java

/**
 * Return a iterable of each targeted edit part
 * /*from   w  w  w. j  a v a2  s  .  c  o m*/
 * @param req
 * @return
 */
public static Iterable<IGraphicalEditPart> getTargetedEditPart(ChangeBoundsRequest req) {
    if (req != null && req.getEditParts() != null) {
        return Iterables
                .transform(Iterables.filter((Iterable<Object>) req.getEditParts(), new Predicate<Object>() {

                    public boolean apply(Object input) {
                        return input instanceof IGraphicalEditPart;
                    }
                }), new Function<Object, IGraphicalEditPart>() {

                    public IGraphicalEditPart apply(Object from) {
                        return (IGraphicalEditPart) from;
                    }
                });
    }
    return Collections.EMPTY_LIST;
}

From source file:com.b2international.snowowl.snomed.reasoner.model.NeverGroupedKey.java

@Override
public void collect(final OWLDataFactory df, final DefaultPrefixManager prefixManager,
        final List<OWLAxiom> axioms, final Set<OWLClassExpression> terms, final DefinitionNode definitionNode) {

    collectDirectDefinitions(df, prefixManager, axioms, terms, definitionNode);

    for (final UnionGroupKey unionKey : Iterables.filter(definitionNode.getSubNodeKeys(),
            UnionGroupKey.class)) {
        unionKey.collect(df, prefixManager, axioms, terms, definitionNode.getSubNode(unionKey));
    }/* w  w w  .j av  a2 s. c o  m*/
}

From source file:org.ow2.petals.cloud.manager.commands.iaas.ListAccountsCommand.java

@Override
protected Object doExecute() throws Exception {
    Iterable<Provider> filtered = Iterables.filter(registryService.get(), new Predicate<Provider>() {
        public boolean apply(Provider p) {
            if (filter == null || filter.trim().length() == 0) {
                return true;
            }/*from w  ww. ja  v  a2 s  . c  o  m*/
            return p.getName().contains(filter);
        }
    });
    System.out.println("Registered IaaS accounts :");
    for (Provider p : filtered) {
        System.out.println(" - " + p);
    }
    return null;
}

From source file:org.eclipse.sirius.diagram.ui.internal.edit.policies.DNodeContainerItemSemanticEditPolicy.java

/**
 * @was-generated/*  w  w  w .  j  a v a2 s .  c  o  m*/
 */
protected void addDestroyChildNodesCommand(CompoundCommand cmd) {
    View view = (View) getHost().getModel();
    EAnnotation annotation = view.getEAnnotation("Shortcut"); //$NON-NLS-1$
    if (annotation != null) {
        return;
    }
    for (Node node : Iterables.filter(view.getChildren(), Node.class)) {
        switch (SiriusVisualIDRegistry.getVisualID(node)) {
        case DNode4EditPart.VISUAL_ID:
            cmd.add(getDestroyElementCommand(node));
            break;
        case DNodeContainerViewNodeContainerCompartmentEditPart.VISUAL_ID:
        case DNodeContainerViewNodeContainerCompartment2EditPart.VISUAL_ID:
            for (Node cnode : Iterables.filter(node.getChildren(), Node.class)) {
                switch (SiriusVisualIDRegistry.getVisualID(cnode)) {
                case DNode3EditPart.VISUAL_ID:
                case DNodeContainer2EditPart.VISUAL_ID:
                case DNodeList2EditPart.VISUAL_ID:
                    cmd.add(getDestroyElementCommand(cnode));
                    break;
                }
            }
            break;
        default:
            break;
        }
    }
}

From source file:org.trancecode.xml.saxon.SaxonAxis.java

public static Iterable<XdmNode> childNodes(final XdmNode node) {
    return Iterables.filter(childXdmItems(node), XdmNode.class);
}

From source file:org.objectweb.fractal.fscript.console.PrefixCompletor.java

private Collection<String> getCandidatesStartingWith(final String prefix) {
    Set<String> values = getAllPossibleValues();
    List<String> candidates = Lists.newArrayList();
    Iterables.addAll(candidates, Iterables.filter(values, new Predicate<String>() {
        public boolean apply(String name) {
            return name.startsWith(prefix);
        }/*w ww.jav a2 s  .  c o m*/
    }));
    return candidates;
}

From source file:org.isisaddons.app.kitchensink.dom.mixins.mixin.PreferencesService.java

List<Preference> preferencesOf(final Person person) {
    return Lists.newArrayList(
            Iterables.filter(preferences.listAllPreferences(), Preference.Predicates.preferenceOf(person)));
}

From source file:com.huangyunkun.jviff.core.impl.HtmlResultReport.java

@Override
public void report(List<StepResult> stepResults, File outputDir) throws IOException {
    Iterable<StepResult> stepResultIterable = Iterables.filter(stepResults, new Predicate<StepResult>() {
        @Override/*from  w ww. j  a v  a 2  s . co  m*/
        public boolean apply(StepResult input) {
            return input.getStep().getRecord();
        }
    });
    final Context ctx = new Context();
    ctx.setVariable("stepResults", stepResultIterable);
    String templateFile = Resources.getResource("html/index.html").getPath();
    String html = templateEngine.process(templateFile, ctx);
    File outputFile = new File(outputDir, "index.html");
    Files.write(html, outputFile, Charset.forName("utf8"));
    copyResources(outputDir);
}