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.eclipse.sirius.diagram.editor.properties.sections.tool.containerdropdescription.ContainerDropDescriptionContainersPropertySection.java

/**
 * Fetches the list of available values for the feature.
 * //from   w  w w.  jav a2  s . co  m
 * @return The list of available values for the feature.
 */
@Override
protected List getChoiceOfValues() {
    UnmodifiableIterator<org.eclipse.sirius.diagram.description.DragAndDropTargetDescription> filter = Iterators
            .filter(eObject.eResource().getResourceSet().getAllContents(), DragAndDropTargetDescription.class);
    return Lists.newArrayList(filter);
}

From source file:util.ListFolder.java

public List<File> getFiles(String contextPath) {

    // Compare to base context path.
    File path = null;//from   ww  w  .  ja v a2s  .c om
    if (settings != null) {
        String exportPath = settings.getExportPath();
        exportPath += contextPath;
        path = new File(exportPath);

    } else if (workspacePath != null) {
        String exportPath = workspacePath;
        exportPath += contextPath;
        try {
            URI uri = new URI(exportPath);
            path = new File(uri);
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    if (path != null && path.exists() && path.isDirectory()) {
        File[] files = path.listFiles();
        List<File> filesList = Lists.newArrayList(files);
        Collections.sort(filesList, NonModelUtils.fileLastModifiedComparator());
        UnmodifiableIterator<File> filter = Iterators.filter(filesList.iterator(),
                NonModelUtils.nonHiddenFile());
        return Lists.newArrayList(filter);
    } else if (path.isFile()) {

    }
    return Lists.newArrayList();
}

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 completion event trigger
 * @param s - the state machine/* ww w. ja v  a2  s. co m*/
 * @return the iterator
 */
private static Iterator<State> completionStateIterator(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())
                        if (t.getTriggers().isEmpty())
                            return true;
                    return false;
                }
            });
    return new_states_iter;
}

From source file:norbert.mynemo.dataimport.fileformat.input.CkRatingImporter.java

/**
 * Returns an iterator on the ratings.//from   w w w  .  ja v a 2 s . c  o m
 */
@Override
public Iterator<MynemoRating> iterator() {
    Iterator<CkRating> ckRatingIterator;
    try {
        ckRatingIterator = new CkRatingFile(ratingFilepath).iterator();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return new ConverterIterator(Iterators.filter(ckRatingIterator, new HasCorrespondingImdbId()));
}

From source file:org.eclipse.sirius.diagram.editor.properties.sections.tool.reconnectedgedescription.ReconnectEdgeDescriptionMappingsPropertySection.java

/**
 * Fetches the list of available values for the feature.
 * /* ww  w  .ja v a2  s. c o  m*/
 * @return The list of available values for the feature.
 */
@Override
protected List getChoiceOfValues() {
    UnmodifiableIterator<EdgeMapping> filter = Iterators
            .filter(eObject.eResource().getResourceSet().getAllContents(), EdgeMapping.class);
    return Lists.newArrayList(filter);
}

From source file:org.eclipse.emf.compare.scope.FilterComparisonScope.java

/**
 * {@inheritDoc}//from www .ja va 2s.co m
 * <p>
 * This default implementation will only return the {@link Resource}s directly contained by
 * {@link ResourceSet} which match the {@link #resourceSetContentFilter} predicate.
 * </p>
 * 
 * @see org.eclipse.emf.compare.scope.IComparisonScope#getCoveredResources(org.eclipse.emf.ecore.resource.ResourceSet)
 */
public Iterator<? extends Resource> getCoveredResources(ResourceSet resourceSet) {
    if (resourceSet == null) {
        return Iterators.emptyIterator();
    }

    final Iterator<Resource> allResources = resourceSet.getResources().iterator();
    final Iterator<Resource> filter = Iterators.filter(allResources, resourceSetContentFilter);
    return Iterators.unmodifiableIterator(filter);
}

From source file:org.fcrepo.kernel.rdf.impl.PropertiesRdfContext.java

private Iterator<Triple> triplesFromProperties(final javax.jcr.Node n) throws RepositoryException {
    LOGGER.trace("Creating triples for node: {}", n);
    final UnmodifiableIterator<Property> nonBinaryProperties = Iterators
            .filter(new PropertyIterator(n.getProperties()), not(isInternalProperty));

    final UnmodifiableIterator<Property> nonBinaryPropertiesCopy = Iterators
            .filter(new PropertyIterator(n.getProperties()), not(isInternalProperty));

    return Iterators.concat(new ZippingIterator<>(Iterators.transform(nonBinaryProperties, property2values),
            Iterators.transform(nonBinaryPropertiesCopy, property2triple)));

}

From source file:org.polarsys.reqcycle.styling.ui.providers.StylingContentProvider.java

@Override
public Object[] getElements(Object inputElement) {
    if (inputElement instanceof NavigatorRoot) {
        predicates = ((NavigatorRoot) inputElement).getPredicates();
        scopes = ((NavigatorRoot) inputElement).getScopes();
        reqFilter = ((NavigatorRoot) inputElement).getFilter();
        displayType = ((NavigatorRoot) inputElement).getDisplay();

        switch (displayType) {
        case FILTERBYNAME:
            if ((reqFilter != null) && (!reqFilter.equals(""))) {
                final Pattern p = Pattern.compile(".*" + reqFilter + ".*", Pattern.DOTALL);
                final Predicate<Object> attPredicate = new Predicate<Object>() {
                    @Override/*  w w  w  .  j a  va 2 s  . co  m*/
                    public boolean apply(Object arg0) {
                        if (arg0 instanceof Requirement) {
                            Requirement req = (Requirement) arg0;
                            return req.getId() != null && p.matcher(req.getId()).matches();
                        }
                        return true;
                    }
                };
                return Iterators.toArray(
                        Iterators.filter(((NavigatorRoot) inputElement).getSources().iterator(), attPredicate),
                        Object.class);
            } else {
                List<RequirementSource> sources = ((NavigatorRoot) inputElement).getSources();
                return sources.toArray();
            }
        case FILTERBYPREDICATE:
            if (predicates.size() == 1) {
                IPredicate predicate = predicates.get(0);

                return Iterators
                        .toArray(Iterators.filter(((NavigatorRoot) inputElement).getSources().iterator(),
                                new PPredicate(predicate)), Object.class);
            } else {
                List<RequirementSource> sources = ((NavigatorRoot) inputElement).getSources();
                return sources.toArray();
            }
        case ORDERBYPREDICATE:
            if (predicates.size() != 0) {
                return predicates.toArray();
            } else {
                List<RequirementSource> sources = ((NavigatorRoot) inputElement).getSources();
                return sources.toArray();
            }
        case ORDERBYSCOPE:
            if (scopes.size() != 0) {
                return scopes.toArray();
            } else {
                List<RequirementSource> sources = ((NavigatorRoot) inputElement).getSources();
                return sources.toArray();
            }
        case REQONLY:
        case NONE:
        default:
            List<RequirementSource> sources = ((NavigatorRoot) inputElement).getSources();
            return sources.toArray();
        }
    }
    return null;
}

From source file:org.locationtech.geogig.api.porcelain.AddOp.java

/**
 * Stages the object addressed by {@code pathFilter}, or all unstaged objects if
 * {@code pathFilter == null} to be added, if it is/they are marked as an unstaged change. Does
 * nothing otherwise./*ww  w  .ja v  a  2s  .  c o  m*/
 * <p>
 * To stage changes not yet staged, a diff tree walk is performed using the current staged
 * {@link RevTree} as the old object and the current unstaged {@link RevTree} as the new object.
 * Then all the differences are traversed and the staged tree is updated with the changes
 * reported by the diff walk (neat).
 * </p>
 * 
 * @param progress the progress listener for this process
 * @param pathFilter the filter to use
 */
public void stage(final ProgressListener progress, final @Nullable String pathFilter) {

    // short cut for the case where the index is empty and we're staging all changes in the
    // working tree, so it's just a matter of updating the index ref to working tree RevTree id
    if (null == pathFilter && !index().getStaged(null).hasNext() && !updateOnly
            && index().countConflicted(null) == 0) {
        progress.started();
        Optional<ObjectId> workHead = command(RevParse.class).setRefSpec(Ref.WORK_HEAD).call();
        if (workHead.isPresent()) {
            command(UpdateRef.class).setName(Ref.STAGE_HEAD).setNewValue(workHead.get()).call();
        }
        progress.setProgress(100f);
        progress.complete();
        return;
    }

    final long numChanges = workingTree().countUnstaged(pathFilter).count();

    Iterator<DiffEntry> unstaged = workingTree().getUnstaged(pathFilter);

    if (updateOnly) {
        unstaged = Iterators.filter(unstaged, new Predicate<DiffEntry>() {
            @Override
            public boolean apply(@Nullable DiffEntry input) {
                // HACK: avoid reporting changed trees
                if (input.isChange() && input.getOldObject().getType().equals(TYPE.TREE)) {
                    return false;
                }
                return input.getOldObject() != null;
            }
        });
    }

    index().stage(progress, unstaged, numChanges);

    List<Conflict> conflicts = index().getConflicted(pathFilter);
    ConflictsDatabase conflictsDatabase = conflictsDatabase();
    for (Conflict conflict : conflicts) {
        // if we are staging unmerged files, the conflict should get solved. However, if the
        // working index object is the same as the staging area one (for instance, after running
        // checkout --ours), it will not be reported by the getUnstaged method. We solve that
        // here.
        conflictsDatabase.removeConflict(null, conflict.getPath());
    }
}

From source file:org.apache.cassandra.db.compaction.LazilyCompactedRow.java

public LazilyCompactedRow(CompactionController controller, List<? extends OnDiskAtomIterator> rows) {
    super(rows.get(0).getKey());
    this.rows = rows;
    this.controller = controller;
    indexer = controller.cfs.indexManager.gcUpdaterFor(key);

    // Combine top-level tombstones, keeping the one with the highest markedForDeleteAt timestamp.  This may be
    // purged (depending on gcBefore), but we need to remember it to properly delete columns during the merge
    maxRowTombstone = DeletionTime.LIVE;
    for (OnDiskAtomIterator row : rows) {
        DeletionTime rowTombstone = row.getColumnFamily().deletionInfo().getTopLevelDeletion();
        if (maxRowTombstone.compareTo(rowTombstone) < 0)
            maxRowTombstone = rowTombstone;
    }//from w  w w .  ja v a  2s  .co  m

    emptyColumnFamily = ArrayBackedSortedColumns.factory.create(controller.cfs.metadata);
    emptyColumnFamily.delete(maxRowTombstone);
    if (!maxRowTombstone.isLive() && maxRowTombstone.markedForDeleteAt < getMaxPurgeableTimestamp())
        emptyColumnFamily.purgeTombstones(controller.gcBefore);

    reducer = new Reducer();
    merger = Iterators.filter(
            MergeIterator.get(rows, emptyColumnFamily.getComparator().onDiskAtomComparator(), reducer),
            Predicates.notNull());
}