Example usage for com.google.common.collect Iterators filter

List of usage examples for com.google.common.collect Iterators filter

Introduction

In this page you can find the example usage for com.google.common.collect Iterators filter.

Prototype

@SuppressWarnings("unchecked") 
@GwtIncompatible("Class.isInstance")
@CheckReturnValue
public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType) 

Source Link

Document

Returns all elements in unfiltered that are of the type desiredType .

Usage

From source file:com.flaptor.indextank.storage.IndexLog.java

public synchronized void appendBuffer(long initialTimestamp, MemoryBuffer buffer)
        throws TException, IOException {
    // filter out empty records but add a warning to the alert log
    Predicate<LogRecord> isNonEmpty = new Predicate<LogRecord>() {
        public boolean apply(LogRecord r) {
            if (!isValidRecord(r)) {
                throw new RuntimeException(String.format(
                        "At least one of the records was missing a docid: code=%s | fields: %s | vars: %s | categories: %s",
                        r.get_index_code(), r.get_fields(), r.get_variables(), r.get_categories()));
            }//w ww.jav  a2 s  .  co m
            if (!r.is_set_docid()) {
                alertLogger.warn("Tried to append an empty record for index %s", r.get_index_code());
                return false;
            }
            return true;
        }
    };

    // write the actual segment
    Segment.createUnsortedSegment(root, getSegmentsPath(), initialTimestamp, Iterators.filter(
            new RecordIterator(null, buffer.protocol, "Buffer for " + this.code + " at " + initialTimestamp),
            isNonEmpty));

    sort(false);
}

From source file:org.eclipse.sirius.business.api.query.DViewQuery.java

/**
 * Get all the EObject following a predicate from all the
 * {@link DRepresentation} inside the {@link DView} ({@link DRepresentation}
 * s are not owned by the {@link DView}).
 * /*  w  w w .j a v a  2 s .  co  m*/
 * @param predicate
 *            predicate used to filter the result
 * @return the result iterator
 */
public Iterator<EObject> getAllContentInRepresentations(final Predicate<? super EObject> predicate) {
    Iterator<EObject> iterator = Collections.emptyIterator();
    List<DRepresentation> allRepresentations = this.getLoadedRepresentations();
    for (DRepresentation dRepresentation : allRepresentations) {
        UnmodifiableIterator<EObject> currentIterator = Iterators.filter(dRepresentation.eAllContents(),
                predicate);
        iterator = Iterators.concat(iterator, currentIterator);
    }
    return iterator;
}

From source file:nz.ac.massey.cs.guery.adapters.blueprints.BlueprintsAdapter.java

@Override
public Iterator<Edge> getInEdges(Vertex vertex, Predicate<? super Edge> filter) {
    return Iterators.filter(this.getInEdges(vertex), filter);
}

From source file:org.eclipse.sirius.diagram.business.internal.migration.GMFLabelStyleMigrationParticipant.java

private void addFontFormatsFromGMFStyle(Diagram gmfDiagram) {
    UnmodifiableIterator<View> iterator = Iterators.filter(gmfDiagram.eAllContents(), View.class);
    while (iterator.hasNext()) {
        View view = iterator.next();
        EObject element = view.getElement();
        if (element instanceof DDiagramElement) {
            org.eclipse.sirius.viewpoint.Style siriusStyle = ((DDiagramElement) element).getStyle();
            Style style = view.getStyle(NotationPackage.eINSTANCE.getFontStyle());
            if (style instanceof FontStyle && siriusStyle instanceof BasicLabelStyle) {
                Set<FontFormat> fontFormatToSet = new HashSet<FontFormat>(
                        ((BasicLabelStyle) siriusStyle).getLabelFormat());
                int initialSize = fontFormatToSet.size();
                if (((FontStyle) style).isStrikeThrough()) {
                    fontFormatToSet.add(FontFormat.STRIKE_THROUGH_LITERAL);
                }/*from w  w w.j a v a2 s. com*/
                if (((FontStyle) style).isUnderline()) {
                    fontFormatToSet.add(FontFormat.UNDERLINE_LITERAL);
                }
                if (initialSize != fontFormatToSet.size()) {
                    FontFormatHelper.setFontFormat(((BasicLabelStyle) siriusStyle).getLabelFormat(),
                            fontFormatToSet);

                    // If the GMF underline and/or strike-through were set
                    // to true, that means the user customized those
                    // features. That was not set in the customFeatures list
                    // since it was not handled by Sirius.
                    String labelFormatFeatureName = ViewpointPackage.Literals.BASIC_LABEL_STYLE__LABEL_FORMAT
                            .getName();
                    if (!((BasicLabelStyle) siriusStyle).getCustomFeatures().contains(labelFormatFeatureName)) {
                        ((BasicLabelStyle) siriusStyle).getCustomFeatures().add(labelFormatFeatureName);
                    }
                }
            }
        }
    }
}

From source file:org.eclipselabs.agrum.services.model.plugin.parser.ModelParser.java

/**
 * To get an iterator on each state of the state machine which possessed at least one outgoing transition with a tick event trigger
 * @param s - the state machine/*from www  .ja va  2s  . c  o  m*/
 * @return the iterator 
 */
private static Iterator<State> tickStateIterator(StateMachine s) {
    Iterator<State> states_iter = StateIterator(s);
    Iterator<State> new_states_iter = Iterators.filter(states_iter,
            new com.google.common.base.Predicate<State>() {
                @Override
                public boolean apply(State arg0) {
                    for (Transition t : arg0.getOutgoings())
                        for (Trigger trg : t.getTriggers()) {
                            if (trg.getEvent().getName().equals(clockTriggerName))
                                return true;
                        }
                    return false;
                }
            });
    return new_states_iter;
}

From source file:fr.gouv.mindef.safran.project.lifecycle.ImporterUtil.java

public static <T extends EObject> List<T> getAllContentsOfType(EObject root, Class<T> type) {
    return Lists.newArrayList(Iterators.filter(root.eAllContents(), type));
}

From source file:qdg.view.EdgeSubMixedGraph.java

@Override
public Iterator<Edge> getIncidentArcIterator(Node node) {
    return Iterators.filter(g.getIncidentArcIterator(node), edgeFilterPredicate);
}

From source file:org.eclipse.elk.core.util.selection.DefaultSelectionIterator.java

/**
 * {@inheritDoc}//  www .ja v a 2  s  .c o m
 */
@Override
protected Iterator<? extends KGraphElement> getChildren(final Object object) {
    // Ensure that the visited set is properly initialized
    if (visited == null) {
        visited = Sets.newHashSet();
    }
    if (object instanceof KEdge) {
        KEdge edge = (KEdge) object;
        final KPort port = followEdgeDirection ? edge.getTargetPort() : edge.getSourcePort();

        if (port == null || visited.contains(port)) {
            // return an empty iterator if no target/source port is configured
            // or if the target/source port has been visited already, in order
            // to break infinite loops
            return Iterators.<KGraphElement>emptyIterator();
        }

        visited.add(port);

        // for each object (kedge) visited by this iterator check all the edges connected to
        // 'port' and visit those edges satisfying the criterion stated above
        Iterator<KEdge> resultEdges = Iterators.filter(port.getEdges().iterator(), new Predicate<KEdge>() {

            public boolean apply(final KEdge input) {
                return followEdgeDirection ? port == input.getSourcePort() : port == input.getTargetPort();
            }
        });

        // If the port should be added to the selection, add it to the result set
        if (addPorts) {
            Iterator<KGraphElement> portIterator = Iterators.singletonIterator((KGraphElement) port);
            return Iterators.concat(portIterator, resultEdges);
        } else {
            return resultEdges;
        }
    } else {
        return Iterators.<KGraphElement>emptyIterator();
    }
}

From source file:org.richfaces.ui.misc.focus.AbstractFocusRenderStrategy.java

/**
 * Returns clientIds of component for which validation has failed and adds form's clientId at the end (as a fallback if
 * there is no invalid component or none of invalid components won't be focusable on the client).
 *///from  w  ww. j a va  2  s .  co m
private String[] getClientIdsWithMessages(FacesContext context, UIForm form) {
    Iterator<String> clientIdsWithMessages = Iterators.filter(context.getClientIdsWithMessages(),
            new Predicate<String>() {
                @Override
                public boolean apply(String input) {
                    return input != null;
                }
            });
    return Iterators.toArray(clientIdsWithMessages, String.class);
}

From source file:org.eclipse.sirius.tree.business.api.interaction.DTreeUserInteraction.java

/**
 * Expand all root items of the DTree.//from ww w .  j  a  v  a  2s  .  c o m
 * 
 * @return this user interaction
 */
public DTreeUserInteraction expand() {
    Iterator<DTreeItem> it = Iterators.filter(Iterators.filter(tree.eAllContents(), DTreeItem.class),
            new Predicate<DTreeItem>() {

                public boolean apply(DTreeItem input) {
                    return !input.isExpanded();
                }
            });
    while (it.hasNext()) {
        new DTreeItemUserInteraction(it.next(), ctx).expand();

    }
    return this;
}