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.ui.business.internal.migration.DiagramRepresentationsFileMigrationParticipantV650.java

/**
 * The existing diagram may have incorrect coordinates on their anchors,
 * resulting in an inconsistent display now. The objective of this automatic
 * migration is to ensure that egdes of the same tree goes through the same
 * branches (ie they have the same anchor on source side or target side
 * depending on the direction of the tree). If this is not the case the
 * command modifies the GMF anchors to {0.5, 0.5}, if all anchors are
 * different or to the unique id if there is only one defined anchor in the
 * tree (other anchors are null).//from  w w w.  j  a va 2s .  c  om
 * 
 * @param view
 *            The view to migrate.
 */
private void fixAnchorsOfGMFTreeEdge(final DView view) {
    // Sort the edges per common source or common target
    Map<View, List<Edge>> edgesSortPerSource = Maps.newHashMap();
    Map<View, List<Edge>> edgesSortPerTarget = Maps.newHashMap();
    Iterator<EObject> viewIterator = Iterators.filter(view.eAllContents(), edgeWithTreeRoutingPredicate);
    while (viewIterator.hasNext()) {
        final EObject next = viewIterator.next();
        if (next instanceof Edge) {
            Edge edge = (Edge) next;
            List<Edge> edgesWithSameSource = edgesSortPerSource.get(edge.getSource());
            if (edgesWithSameSource == null) {
                edgesWithSameSource = Lists.newArrayList();
            }
            edgesWithSameSource.add(edge);
            edgesSortPerSource.put(edge.getSource(), edgesWithSameSource);
            List<Edge> edgesWithSameTarget = edgesSortPerTarget.get(edge.getTarget());
            if (edgesWithSameTarget == null) {
                edgesWithSameTarget = Lists.newArrayList();
            }
            edgesWithSameTarget.add(edge);
            edgesSortPerTarget.put(edge.getTarget(), edgesWithSameTarget);
        }
    }
    // Add the set anchor command if needed (ie if the anchor is
    // different for edges with same source or same target)
    setSameAnchor(edgesSortPerSource, true);
    setSameAnchor(edgesSortPerTarget, false);
}

From source file:org.tzi.use.gui.views.diagrams.DiagramGraph.java

/**
 * Returns an iterator over all visible nodes.
 * @return/* w  ww  .j  a  va 2 s  .  c om*/
 */
public Iterator<PlaceableNode> getVisibleNodesIterator() {
    return Iterators.filter(this.iterator(), new Predicate<PlaceableNode>() {
        @Override
        public boolean apply(PlaceableNode n) {
            return n.isVisible();
        }
    });
}

From source file:org.richfaces.component.AbstractTree.java

protected Iterator<UIComponent> findMatchingTreeNodeComponent(String nodeType, UIComponent parentComponent) {
    Iterator<UIComponent> children = parentComponent.getChildren().iterator();
    if (parentComponent != this) {
        children = Iterators.concat(children, this.getChildren().iterator());
    }/*from  w ww . j  av a 2s  .  c  o m*/

    return Iterators.filter(children, new MatchingTreeNodePredicate(nodeType));
}

From source file:gov.nih.nci.caarray.domain.sample.AbstractBioMaterial.java

/**
 * Return the characteristics with given category in this biomaterial.
 *
 * @param category category// w ww  .j  a v a2  s . c o  m
 * @return the characteristics with given category.
 */
public Set<AbstractCharacteristic> getCharacteristics(final Category category) {
    Set<AbstractCharacteristic> chars = new HashSet<AbstractCharacteristic>();
    Iterators.addAll(chars,
            Iterators.filter(characteristics.iterator(), new Predicate<AbstractCharacteristic>() {
                public boolean apply(AbstractCharacteristic input) {
                    return category.equals(input.getCategory());
                }
            }));

    chars.addAll(getBuiltInCharacteristics(category));
    addUserDefinedCharacteristic(chars, category);

    return chars;
}

From source file:org.eclipse.emf.ecoretools.design.service.DesignServices.java

private Set<EClass> getInternalEClasses(DSemanticDiagram diagram) {
    Set<EClass> result = Sets.newLinkedHashSet();
    Iterator<DNodeList> it = Iterators.filter(diagram.eAllContents(), DNodeList.class);
    while (it.hasNext()) {
        DNodeList dec = it.next();/*  ww w .j  a  va 2s.com*/
        if (dec.getTarget() instanceof EClass) {
            if (dec.getActualMapping() != null
                    && CLASS_DIAGRAM_CLASS_MAPPINGID.equals(dec.getActualMapping().getName())) {
                result.add((EClass) dec.getTarget());
            }
        }
    }
    return result;
}

From source file:org.locationtech.geogig.remote.AbstractMappedRemoteRepo.java

/**
 * This function takes all of the changes introduced by the specified commit and filters them
 * based on the repository filter. It then uses the filtered results to construct a new commit
 * that is the descendant of commits that the original's parents are mapped to.
 * //w  w w. j  ava2  s . c o m
 * @param commitId the commit id of the original, non-sparse commit
 * @param allowEmpty allow the function to create an empty sparse commit
 */
private void fetchSparseCommit(ObjectId commitId, boolean allowEmpty) {

    Optional<RevObject> object = getObject(commitId);
    if (object.isPresent() && object.get().getType().equals(TYPE.COMMIT)) {
        RevCommit commit = (RevCommit) object.get();

        FilteredDiffIterator changes = getFilteredChanges(commit);

        GraphDatabase graphDatabase = localRepository.graphDatabase();
        ObjectDatabase objectDatabase = localRepository.objectDatabase();
        graphDatabase.put(commit.getId(), commit.getParentIds());

        RevTree rootTree = RevTree.EMPTY;

        if (commit.getParentIds().size() > 0) {
            // Map this commit to the last "sparse" commit in my ancestry
            ObjectId mappedCommit = graphDatabase.getMapping(commit.getParentIds().get(0));
            graphDatabase.map(commit.getId(), mappedCommit);
            Optional<ObjectId> treeId = localRepository.command(ResolveTreeish.class).setTreeish(mappedCommit)
                    .call();
            if (treeId.isPresent()) {
                rootTree = localRepository.getTree(treeId.get());
            }

        } else {
            graphDatabase.map(commit.getId(), ObjectId.NULL);
        }

        Iterator<DiffEntry> it = Iterators.filter(changes, new Predicate<DiffEntry>() {
            @Override
            public boolean apply(DiffEntry e) {
                return true;
            }
        });

        if (it.hasNext()) {
            // Create new commit
            WriteTree writeTree = localRepository.command(WriteTree.class)
                    .setOldRoot(Suppliers.ofInstance(rootTree))
                    .setDiffSupplier(Suppliers.ofInstance((Iterator<DiffEntry>) it));

            ObjectId newTreeId = writeTree.call();

            CommitBuilder builder = new CommitBuilder(commit);
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (ObjectId parentCommitId : commit.getParentIds()) {
                newParents.add(graphDatabase.getMapping(parentCommitId));
            }
            builder.setParentIds(newParents);
            builder.setTreeId(newTreeId);

            RevCommit mapped = builder.build();
            objectDatabase.put(mapped);

            if (changes.wasFiltered()) {
                graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");
            }

            graphDatabase.map(mapped.getId(), commit.getId());
            // Replace the old mapping with the new commit Id.
            graphDatabase.map(commit.getId(), mapped.getId());
        } else if (allowEmpty) {
            CommitBuilder builder = new CommitBuilder(commit);
            List<ObjectId> newParents = new LinkedList<ObjectId>();
            for (ObjectId parentCommitId : commit.getParentIds()) {
                newParents.add(graphDatabase.getMapping(parentCommitId));
            }
            builder.setParentIds(newParents);
            builder.setTreeId(rootTree.getId());
            builder.setMessage(PLACEHOLDER_COMMIT_MESSAGE);

            RevCommit mapped = builder.build();
            objectDatabase.put(mapped);

            graphDatabase.setProperty(mapped.getId(), GraphDatabase.SPARSE_FLAG, "true");

            graphDatabase.map(mapped.getId(), commit.getId());
            // Replace the old mapping with the new commit Id.
            graphDatabase.map(commit.getId(), mapped.getId());
        } else {
            // Mark the mapped commit as sparse, since it wont have these changes
            graphDatabase.setProperty(graphDatabase.getMapping(commit.getId()), GraphDatabase.SPARSE_FLAG,
                    "true");
        }
    }
}

From source file:org.apache.kylin.rest.service.ProjectService.java

public List<ProjectInstance> getReadableProjects(final String projectName) {
    List<ProjectInstance> readableProjects = new ArrayList<ProjectInstance>();

    //list all projects first
    List<ProjectInstance> projectInstances = getProjectManager().listAllProjects();

    for (ProjectInstance projectInstance : projectInstances) {

        if (projectInstance == null) {
            continue;
        }/*from  w ww . j av a 2  s .com*/

        boolean hasProjectPermission = false;
        try {
            hasProjectPermission = aclUtil.hasProjectReadPermission(projectInstance);
        } catch (AccessDeniedException e) {
            //ignore to continue
        }

        if (!hasProjectPermission) {
            List<CubeInstance> cubeInstances = cubeService.listAllCubes(projectInstance.getName());

            for (CubeInstance cubeInstance : cubeInstances) {
                if (cubeInstance == null) {
                    continue;
                }

                try {
                    aclUtil.hasCubeReadPermission(cubeInstance);
                    hasProjectPermission = true;
                    break;
                } catch (AccessDeniedException e) {
                    //ignore to continue
                }
            }
        }
        if (hasProjectPermission) {
            readableProjects.add(projectInstance);
        }

    }

    if (!Strings.isEmpty(projectName)) {
        readableProjects = Lists
                .newArrayList(Iterators.filter(readableProjects.iterator(), new Predicate<ProjectInstance>() {
                    @Override
                    public boolean apply(@Nullable ProjectInstance input) {
                        return input.getName().equals(projectName);
                    }
                }));
    }

    return readableProjects;
}

From source file:com.textocat.textokit.io.brat.AutoBratUimaMappingFactory.java

private Type searchTypeByBaseName(String baseName) {
    @SuppressWarnings("unchecked")
    Iterator<Type> iter = Iterators.filter(ts.getTypeIterator(), Predicates
            .and(asList(annotationTypePredicate, typeBaseNamePredicate(baseName), namespacePredicate)));
    Type result = null;//  w  ww.j  ava  2 s .c  om
    if (iter.hasNext()) {
        result = iter.next();
        if (iter.hasNext()) {
            throw new IllegalStateException(String
                    .format("There are at least two types with target basename: %s, %s", result, iter.next()));
        }
    }
    return result;
}

From source file:com.github.rinde.opt.localsearch.Swaps.java

static <C, T> Iterator<Swap<T>> oneItemSwapIterator(Schedule<C, T> schedule, IntList startIndices, T item,
        int fromRow) {
    final IntList indices = indices(schedule.routes.get(fromRow), item);
    final ImmutableList.Builder<Iterator<Swap<T>>> iteratorBuilder = ImmutableList.builder();

    Range<Integer> range;/*from www . j a  va2s  .  c om*/
    if (indices.size() == 1) {
        range = Range.closedOpen(fromRow, fromRow + 1);
    } else {
        range = Range.closedOpen(0, schedule.routes.size());
    }

    for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); i++) {
        int rowSize = schedule.routes.get(i).size();
        if (fromRow == i) {
            rowSize -= indices.size();
        }
        Iterator<IntList> it = new InsertionIndexGenerator(indices.size(), rowSize, startIndices.getInt(i));
        // filter out swaps that have existing result
        if (fromRow == i) {
            it = Iterators.filter(it, Predicates.not(Predicates.equalTo(indices)));
        }
        iteratorBuilder.add(Iterators.transform(it, new IndexToSwapTransform<T>(item, fromRow, i)));
    }
    return Iterators.concat(iteratorBuilder.build().iterator());
}

From source file:org.eclipse.elk.core.service.LayoutConfigurationManager.java

/**
 * Create a layout configurator and initialize it with the option values from the given layout
 * configuration store provider./*from ww  w  . j a v  a  2 s .c o m*/
 */
public <T> LayoutConfigurator createConfigurator(final LayoutMapping layoutMapping) {
    LayoutConfigurator result = new LayoutConfigurator();
    if (configProvider != null) {
        configureElement(layoutMapping.getLayoutGraph(), layoutMapping, result);
        Iterator<KGraphElement> allElements = Iterators.filter(layoutMapping.getLayoutGraph().eAllContents(),
                KGraphElement.class);
        while (allElements.hasNext()) {
            KGraphElement element = allElements.next();
            configureElement(element, layoutMapping, result);
        }
    }
    return result;
}