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:org.locationtech.geogig.geotools.geopkg.InterchangeFormat.java

/**
 * Builds a new feature type tree based on the changes in the audit logs.
 * /*from w  w w .  jav  a2s . c  om*/
 * @param store the object store
 * @param currentFeatureTree the original feature tree
 * @param changes all of the changes from the audit log
 * @return the newly built tree
 * @throws SQLException
 */
private RevTree importAuditLog(ObjectStore store, RevTree currentFeatureTree, Iterator<Change> changes,
        Map<String, String> fidMappings, AuditReport report) throws SQLException {

    CanonicalTreeBuilder builder = CanonicalTreeBuilder.create(store, currentFeatureTree);

    progressListener.setProgress(0);

    Function<Change, RevFeature> function = new Function<InterchangeFormat.Change, RevFeature>() {

        private int count = 0;

        @Override
        public RevFeature apply(Change change) {
            progressListener.setProgress(++count);

            @Nullable
            RevFeature feature = change.getFeature();

            String featureId = null;
            if (fidMappings.containsKey(change.getFeautreId())) {
                featureId = fidMappings.get(change.getFeautreId());
            } else {
                featureId = newFeatureId();
                report.addMapping(change.getFeautreId(), featureId);
            }

            ChangeType type = change.getType();
            switch (type) {
            case REMOVED:
                builder.remove(featureId);
                break;
            case ADDED:
            case MODIFIED:
                Node node = Node.create(featureId, feature.getId(), ObjectId.NULL, TYPE.FEATURE,
                        SpatialOps.boundsOf(feature));
                builder.put(node);
                return feature;
            default:
                throw new IllegalStateException();
            }
            return feature;
        }
    };

    Iterator<RevFeature> feautres = Iterators.filter(Iterators.transform(changes, function),
            Predicates.notNull());

    store.putAll(feautres);

    RevTree newTree = builder.build();
    store.put(newTree);
    return newTree;
}

From source file:org.obeonetwork.dsl.uml2.core.api.services.ActivityDiagramServices.java

/**
 * Get all the signals available in the semantic resources.
 *
 * @param element/*  w w  w .ja  va  2 s . c om*/
 *            Semantic element
 * @return All the signals
 */
public List<EObject> getAllSignals(Element element) {
    final List<EObject> signals = Lists.newArrayList();
    final List<org.eclipse.uml2.uml.Package> rootPkgs = getAllAvailableRootPackages(element);
    for (final org.eclipse.uml2.uml.Package pkg : rootPkgs) {
        Iterators.addAll(signals, Iterators.filter(pkg.eAllContents(), Predicates.instanceOf(Signal.class)));
    }

    return signals;
}

From source file:org.apache.uima.lucas.indexer.analysis.AnnotationTokenStream.java

protected Iterator<String> createFeatureValueIterator(FeatureStructure srcFeatureStructure,
        Collection<String> featureNames) {
    List<String> values = new LinkedList<String>();
    Type featureType = srcFeatureStructure.getType();

    if (featureNames.size() == 0)
        values.add(currentAnnotation.getCoveredText());

    for (String featureName : featureNames) {
        Feature feature = featureType.getFeatureByBaseName(featureName);
        if (feature.getRange().isArray()) {
            StringArray fsArray = (StringArray) srcFeatureStructure.getFeatureValue(feature);
            if (featureNames.size() == 1) {
                for (int i = 0; i < fsArray.size(); i++)
                    values.add(fsArray.get(i).toString());
            } else {
                String value = "";
                for (int i = 0; i < fsArray.size(); i++) {
                    value = value.concat(fsArray.get(i).toString());
                    if (i < fsArray.size() - 1)
                        value = value.concat(delimiter);
                }//  w w  w  .  ja v  a 2s .co  m
                values.add(value);
            }
        } else
            values.add(getValueForFeature(srcFeatureStructure, feature,
                    featureFormats.get(feature.getShortName())));
    }
    String value = "";
    if (delimiter != null) {
        for (int i = 0; i < values.size(); i++) {
            if (values.get(i) == null)
                continue;

            value = value.concat(values.get(i));
            if (i < values.size() - 1)
                value = value.concat(delimiter);
        }
        values.clear();
        values.add(value);
    }

    return Iterators.filter(values.iterator(), new NotNullPredicate<String>());
}

From source file:org.geogit.api.plumbing.WriteTree2.java

/**
 * Transforms a {@code Supplier<DiffEntry>} to a {@code Supplier<Node>} with the
 * {@link DiffEntry#getNewObject() new nodes} of entries that represent changes or additions.
 * //w  w  w  .j a  va  2 s.  c  o  m
 * @param strippedPathFilters
 */
private Supplier<Iterator<Node>> asNodeSupplierOfNewContents(final Supplier<Iterator<DiffEntry>> supplier,
        final List<String> strippedPathFilters) {

    final Function<DiffEntry, Node> newNodes = new Function<DiffEntry, Node>() {
        @Override
        public Node apply(DiffEntry diffEntry) {
            return diffEntry.getNewObject().getNode();
        }
    };

    // filters DiffEntries that are not to be moved from index to objects (i.e. DELETE entries)
    final Predicate<DiffEntry> movableFilter = new Predicate<DiffEntry>() {
        final Set<String> expected = Sets.newHashSet(strippedPathFilters);

        @Override
        public boolean apply(DiffEntry e) {
            if (DiffEntry.ChangeType.REMOVED.equals(e.changeType())) {
                return false;
            }
            if (!expected.isEmpty() && !expected.contains(e.newPath())) {
                return false;
            }
            return true;
        }
    };

    return Suppliers.compose(new Function<Iterator<DiffEntry>, Iterator<Node>>() {
        @Override
        public Iterator<Node> apply(Iterator<DiffEntry> input) {
            Iterator<DiffEntry> onlyChanges = Iterators.filter(input, movableFilter);
            Iterator<Node> movableNodes = Iterators.transform(onlyChanges, newNodes);
            return movableNodes;
        }
    }, supplier);
}

From source file:com.blogspot.jabelarminecraft.blocksmith.proxy.CommonProxy.java

protected void addSpawnAllBiomes(EntityLiving parEntity, int parChance, int parMinGroup, int parMaxGroup) {

    /*/*from  w  w w .  ja v  a 2s.c o m*/
     *  For the biome type you can use an list, but unfortunately the built-in biomeList contains
     * null entries and will crash, so you need to clean up that list.
     * diesieben07 suggested the following code to remove the nulls and create list of all biomes
     */
    BiomeGenBase[] allBiomes = Iterators.toArray(
            Iterators.filter(Iterators.forArray(BiomeGenBase.getBiomeGenArray()), Predicates.notNull()),
            BiomeGenBase.class);
    for (int i = 0; i < allBiomes.length; i++) {
        EntityRegistry.addSpawn(parEntity.getClass(), parChance, parMinGroup, parMaxGroup,
                EnumCreatureType.CREATURE, allBiomes[i]); //change the values to vary the spawn rarity, biome, etc.              
    }
}

From source file:org.eclipse.sirius.business.api.repair.SiriusRepairProcess.java

/**
 * Inform model. The DAnalysis must reference all semantic root elements to
 * correctly resolved the SessionManager.getSession(semanticElement).
 * /*  www  .j a  va  2 s  .  c o  m*/
 * @param view
 *            {@link DView} to inform
 */
private void informModel(final DView view) {
    if (view.eContainer() instanceof DAnalysis) {
        DAnalysis analysis = (DAnalysis) view.eContainer();
        // Add all semantic root elements pointed by the target of all
        // DSemanticDecorator of this representation (except if they are the
        // main model of a referenced analysis).
        DAnalysisSessionHelper.updateModelsReferences(analysis,
                Iterators.filter(view.eAllContents(), DSemanticDecorator.class));
    }
}

From source file:com.netxforge.netxstudio.screens.xtext.embedded.EmbeddedXtextEditor.java

/**
 * Configures the decoration support for this editor's source viewer.
 * Subclasses may override this method, but should call their superclass'
 * implementation at some point.// w w  w. java2  s  .  co  m
 * 
 * @param support
 *            the decoration support to configure
 */
private void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) {

    Iterator<AnnotationPreference> e = Iterators
            .filter(fAnnotationPreferences.getAnnotationPreferences().iterator(), AnnotationPreference.class);
    while (e.hasNext())
        support.setAnnotationPreference((AnnotationPreference) e.next());

    support.setCursorLinePainterPreferenceKeys(
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR);
    support.setMarginPainterPreferenceKeys(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR,
            AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLUMN);
    // support.setSymbolicFontName(getFontPropertyPreferenceKey());

    if (characterPairMatcher != null) {
        support.setCharacterPairMatcher(characterPairMatcher);
        support.setMatchingCharacterPainterPreferenceKeys(BracketMatchingPreferencesInitializer.IS_ACTIVE_KEY,
                BracketMatchingPreferencesInitializer.COLOR_KEY);
    }
}

From source file:org.apache.calcite.sql.SqlUtil.java

/**
 * @see Glossary#SQL99 SQL:1999 Part 2 Section 9.4
 *///  w  ww . j  ava 2s .  c om
private static Iterator<SqlOperator> filterRoutinesByTypePrecedence(SqlSyntax sqlSyntax,
        Iterator<SqlOperator> routines, List<RelDataType> argTypes) {
    if (sqlSyntax != SqlSyntax.FUNCTION) {
        return routines;
    }

    List<SqlFunction> sqlFunctions = Lists.newArrayList(Iterators.filter(routines, SqlFunction.class));

    for (final Ord<RelDataType> argType : Ord.zip(argTypes)) {
        final RelDataTypePrecedenceList precList = argType.e.getPrecedenceList();
        final RelDataType bestMatch = bestMatch(sqlFunctions, argType.i, precList);
        if (bestMatch != null) {
            sqlFunctions = Lists.newArrayList(Iterables.filter(sqlFunctions, new PredicateImpl<SqlFunction>() {
                public boolean test(SqlFunction function) {
                    final List<RelDataType> paramTypes = function.getParamTypes();
                    if (paramTypes == null) {
                        return false;
                    }
                    final RelDataType paramType = paramTypes.get(argType.i);
                    return precList.compareTypePrecedence(paramType, bestMatch) >= 0;
                }
            }));
        }
    }
    //noinspection unchecked
    return (Iterator) sqlFunctions.iterator();
}

From source file:org.eclipse.sirius.tests.sample.migration.design.Draw2dToSiriusModelTransformer.java

@SuppressWarnings("unchecked")
private ContainerRepresentation getMigrationContainerRepresentation(IDiagramListEditPart diagramListEditPart) {
    ContainerRepresentation containerRepresentation = MigrationmodelerFactory.eINSTANCE
            .createContainerRepresentation();
    containerRepresentation.setMappingId(getMappingId(diagramListEditPart));
    org.eclipse.sirius.tests.sample.migration.migrationmodeler.ContainerStyle containerStyle = MigrationmodelerFactory.eINSTANCE
            .createContainerStyle();//from  w  ww .  j  a v a2s . c  om
    containerRepresentation.setOwnedStyle(containerStyle);
    updateLabelStyle(containerStyle, diagramListEditPart);
    updateBorderedStyle(containerStyle, diagramListEditPart);
    Object model = diagramListEditPart.getModel();
    if (model instanceof org.eclipse.gmf.runtime.notation.Node) {
        org.eclipse.gmf.runtime.notation.Node node = (org.eclipse.gmf.runtime.notation.Node) model;
        if (node.getLayoutConstraint() instanceof Size) {
            Size size = (Size) node.getLayoutConstraint();
            if (size.getWidth() == -1 || size.getHeight() == -1) {
                containerRepresentation.setAutoSized(true);
            }
        }
    }
    updateLayout(containerRepresentation, diagramListEditPart.getFigure());

    List<?> children = new ArrayList<Object>(diagramListEditPart.getChildren());
    Iterator<ResizableCompartmentEditPart> compart = Iterators
            .filter(diagramListEditPart.getChildren().iterator(), ResizableCompartmentEditPart.class);
    if (compart.hasNext()) {
        ResizableCompartmentEditPart compartmentEditPart = compart.next();
        children.addAll(compartmentEditPart.getChildren());
    }
    Iterable<IAbstractDiagramNodeEditPart> filter = Iterables.filter(children,
            IAbstractDiagramNodeEditPart.class);
    for (IAbstractDiagramNodeEditPart childEditPart : filter) {
        EObject targetSemanticElement = childEditPart.resolveTargetSemanticElement();
        if (targetSemanticElement instanceof Node && childEditPart instanceof IDiagramNodeEditPart) {
            Node subNode = (Node) targetSemanticElement;
            IDiagramNodeEditPart childNodeEditPart = (IDiagramNodeEditPart) childEditPart;
            NodeRepresentation nodeRepresentation = getMigrationNodeRepresentation(childNodeEditPart);
            subNode.getNodeRepresentations().add(nodeRepresentation);
        } else if (targetSemanticElement instanceof Bordered) {
            Bordered subBordered = (Bordered) targetSemanticElement;
            BorderedRepresentation borderedRepresentation = getMigrationBorderedRepresentation(childEditPart);
            subBordered.getBorderedRepresentations().add(borderedRepresentation);
        } else if (targetSemanticElement instanceof Container) {
            Container subContainer = (Container) targetSemanticElement;
            ContainerRepresentation subContainerRepresentation = null;
            if (childEditPart instanceof IDiagramContainerEditPart) {
                subContainerRepresentation = getMigrationContainerRepresentation(
                        (IDiagramContainerEditPart) childEditPart);
            } else if (childEditPart instanceof IDiagramListEditPart) {
                subContainerRepresentation = getMigrationContainerRepresentation(
                        (IDiagramListEditPart) childEditPart);
            }
            if (subContainerRepresentation != null) {
                subContainer.getContainerRepresentations().add(subContainerRepresentation);
            }
        }
    }

    return containerRepresentation;
}

From source file:games.stendhal.server.entity.Entity.java

/**
 * an iterator over slots/*from   ww  w.  j a  v  a 2s.  co m*/
 *
 * @param slotTypes slot types to include in the iteration
 * @return Iterator
 */
public Iterator<RPSlot> slotIterator(Slots slotTypes) {
    Predicate<RPSlot> p = new SlotNameInList(slotTypes.getNames());
    return Iterators.filter(slotsIterator(), p);
}