List of usage examples for com.google.common.collect Iterators filter
@SuppressWarnings("unchecked") @GwtIncompatible("Class.isInstance") @CheckReturnValue public static <T> UnmodifiableIterator<T> filter(Iterator<?> unfiltered, Class<T> desiredType)
From source file:org.obeonetwork.dsl.uml2.design.services.ActivityServices.java
/** * Get all the signals available in the semantic resources. * // w w w . j a v a 2s .c om * @param eObj * Semantic element * @return All the signals */ public List<EObject> getAllSignals(Element element) { List<EObject> signals = Lists.newArrayList(); UMLServices umlServices = new UMLServices(); List<org.eclipse.uml2.uml.Package> rootPkgs = umlServices.getAllAvailableRootPackages(element); for (org.eclipse.uml2.uml.Package pkg : rootPkgs) { Iterators.addAll(signals, Iterators.filter(pkg.eAllContents(), Predicates.instanceOf(Signal.class))); } return signals; }
From source file:org.fcrepo.kernel.modeshape.FedoraResourceImpl.java
@SuppressWarnings("unchecked") private void removeEmptyFragments() { try {/*w w w . j ava 2 s .c o m*/ if (node.hasNode("#")) { for (final Iterator<Node> hashNodes = node.getNode("#").getNodes(); hashNodes.hasNext();) { final Node n = hashNodes.next(); final Iterator<Property> userProps = Iterators.filter((Iterator<Property>) n.getProperties(), p -> !isManagedPredicate.test(propertyConverter.convert(p))); if (!userProps.hasNext()) { LOGGER.debug("Removing empty hash URI node: {}", n.getName()); n.remove(); } } } } catch (final RepositoryException ex) { throw new RepositoryRuntimeException("Error removing empty fragments", ex); } }
From source file:org.elasticsearch.test.InternalTestCluster.java
/** * Ensures that at most <code>n</code> are up and running. * If less nodes that <code>n</code> are running this method * will not start any additional nodes.//from w w w .j a va 2s . c o m */ public synchronized void ensureAtMostNumDataNodes(int n) throws IOException { int size = numDataNodes(); if (size <= n) { return; } // prevent killing the master if possible and client nodes final Iterator<NodeAndClient> values = n == 0 ? nodes.values().iterator() : Iterators.filter(nodes.values().iterator(), Predicates.and(new DataNodePredicate(), Predicates.not(new MasterNodePredicate(getMasterName())))); final Iterator<NodeAndClient> limit = Iterators.limit(values, size - n); logger.info("changing cluster size from {} to {}, {} data nodes", size(), n + numSharedClientNodes, n); Set<NodeAndClient> nodesToRemove = new HashSet<>(); while (limit.hasNext()) { NodeAndClient next = limit.next(); nodesToRemove.add(next); removeDisruptionSchemeFromNode(next); next.close(); } for (NodeAndClient toRemove : nodesToRemove) { nodes.remove(toRemove.name); } if (!nodesToRemove.isEmpty() && size() > 0) { assertNoTimeout(client().admin().cluster().prepareHealth() .setWaitForNodes(Integer.toString(nodes.size())).get()); } }
From source file:org.eclipse.sirius.diagram.ui.internal.refresh.GMFHelper.java
/** * Returns a new Point representing the bottom right point of all bounds of * children of this Node. Useful for Node with size of -1x-1 to be more * accurate (but it is still not necessarily the same size that draw2d). * /*from w w w. ja v a 2 s . com*/ * @param node * the node whose bottom right corner is to compute. * * @return Point at the bottom right of the rectangle */ public static Point getBottomRight(Node node) { int right = 0; int bottom = 0; for (Iterator<Node> children = Iterators.filter(node.getChildren().iterator(), Node.class); children .hasNext(); /* */) { Node child = children.next(); // The bordered nodes is ignored if (!(new NodeQuery(node).isBorderedNode())) { Rectangle bounds = getBounds(child); Point bottomRight = bounds.getBottomRight(); if (bottomRight.x > right) { right = bottomRight.x; } if (bottomRight.y > bottom) { bottom = bottomRight.y; } } } return new Point(right, bottom); }
From source file:org.obeonetwork.dsl.sysml.design.services.SysMLServices.java
/** * Get all valid elements in session.//from w w w . j ava 2 s .com * * @param cur * Current element * @param validForDiagram * Predicate * @return List of valid elements */ private List<EObject> allValidSessionElements(EObject cur, Predicate<EObject> validForDiagram) { Session found = SessionManager.INSTANCE.getSession(cur); List<EObject> result = Lists.newArrayList(); if (found != null) { for (Resource res : found.getSemanticResources()) { Iterators.addAll(result, Iterators.filter(res.getAllContents(), validForDiagram)); } } return result; }
From source file:org.apache.cassandra.cql3.statements.SelectStatement.java
private Iterator<Cell> applySliceRestriction(final Iterator<Cell> cells, final QueryOptions options) throws InvalidRequestException { final CellNameType type = cfm.comparator; final CellName excludedStart = makeExclusiveSliceBound(Bound.START, type, options); final CellName excludedEnd = makeExclusiveSliceBound(Bound.END, type, options); return Iterators.filter(cells, new Predicate<Cell>() { public boolean apply(Cell c) { // For dynamic CF, the column could be out of the requested bounds (because we don't support strict bounds internally (unless // the comparator is composite that is)), filter here return !((excludedStart != null && type.compare(c.name(), excludedStart) == 0) || (excludedEnd != null && type.compare(c.name(), excludedEnd) == 0)); }// www.ja va 2 s .c om }); }
From source file:org.obeonetwork.dsl.sysml.design.services.SysMLServices.java
/** * Get all valid attributes of a class./*from ww w. ja va 2 s. c o m*/ * * @param cur * Current element * @param validForDiagram * Predicate * @return List of valid elements */ private List<EObject> allValidAttributes(Class cur, Predicate<EObject> validForDiagram) { List<EObject> result = Lists.newArrayList(); Iterators.addAll(result, Iterators.filter(cur.getAttributes().iterator(), validForDiagram)); return result; }
From source file:org.tzi.use.gui.views.diagrams.behavior.communicationdiagram.CommunicationDiagram.java
/** * @param helper// ww w . j a va 2 s . c o m * @param version * @param ap */ private void restoreCommunicationEdges(PersistHelper helper, int version, AutoPilot ap) { try { // Restore edges ap.selectXPath("./edge[@type='Communication Edge']"); try { while (ap.evalXPath() != -1) { String edgeName = helper.getElementStringValue("name"); Iterator<CommunicationDiagramEdge> iter = Iterators.filter(fGraph.edgeIterator(), CommunicationDiagramEdge.class); //FIXME: ber alle edges laufen und dann XPAth auswerten sollte schneller sein while (iter.hasNext()) { EdgeBase edge = iter.next(); if (edge.getName().equals(edgeName)) { edge.restorePlacementInfo(helper, version); break; } } } } catch (XPathEvalException e) { fLog.append(e.getMessage()); } catch (NavException e) { fLog.append(e.getMessage()); } } catch (XPathParseException e) { fLog.append(e.getMessage()); } }
From source file:org.locationtech.geogig.repository.WorkingTree.java
/** * Inserts the given {@code features} into the working tree, using the {@code treePathResolver} * function to determine to which tree each feature is added. * //from w ww . j a v a 2 s . c om * @param treePathResolver a function that determines the path of the tree where each feature * node is stored * @param features the features to insert, possibly of different schema and targetted to * different tree paths * @param listener a progress listener * @param insertedTarget if provided, all nodes created will be added to this list. Beware of * possible memory implications when inserting a lot of features. * @param collectionSize if given, used to determine progress and notify the {@code listener} * @return the total number of inserted features */ public void insert(final Function<Feature, String> treePathResolver, Iterator<? extends Feature> features, final ProgressListener listener, @Nullable final List<Node> insertedTarget, @Nullable final Integer collectionSize) { checkArgument(collectionSize == null || collectionSize.intValue() > -1); final int nTreeThreads = Math.max(2, Runtime.getRuntime().availableProcessors() / 2); final ExecutorService treeBuildingService = Executors.newFixedThreadPool(nTreeThreads, new ThreadFactoryBuilder().setNameFormat("WorkingTree-tree-builder-%d").build()); final WorkingTreeInsertHelper insertHelper; insertHelper = new WorkingTreeInsertHelper(context, getTree(), treePathResolver, treeBuildingService); UnmodifiableIterator<? extends Feature> filtered = Iterators.filter(features, new Predicate<Feature>() { @Override public boolean apply(Feature feature) { if (listener.isCanceled()) { return false; } if (feature instanceof FeatureToDelete) { insertHelper.remove((FeatureToDelete) feature); return false; } else { return true; } } }); Iterator<RevObject> objects = Iterators.transform(filtered, new Function<Feature, RevObject>() { private int count; @Override public RevFeature apply(Feature feature) { final RevFeature revFeature = RevFeatureBuilder.build(feature); ObjectId id = revFeature.getId(); final Node node = insertHelper.put(id, feature); if (insertedTarget != null) { insertedTarget.add(node); } count++; if (collectionSize == null) { listener.setProgress(count); } else { listener.setProgress((float) (count * 100) / collectionSize.intValue()); } return revFeature; } }); try { listener.started(); indexDatabase.putAll(objects); if (listener.isCanceled()) { return; } listener.setDescription("Building trees for " + new TreeSet<String>(insertHelper.getTreeNames())); Stopwatch sw = Stopwatch.createStarted(); Map<NodeRef, RevTree> trees = insertHelper.buildTrees(); listener.setDescription(String.format("Trees built in %s", sw.stop())); for (Map.Entry<NodeRef, RevTree> treeEntry : trees.entrySet()) { if (!listener.isCanceled()) { NodeRef treeRef = treeEntry.getKey(); RevTree newFeatureTree = treeEntry.getValue(); String treePath = treeRef.path(); ObjectId newRootTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()) .setChildPath(treePath).setMetadataId(treeRef.getMetadataId()).setTree(newFeatureTree) .call(); updateWorkHead(newRootTree); } } listener.complete(); } finally { treeBuildingService.shutdownNow(); } }
From source file:fr.obeo.intent.specification.parser.SpecificationParser.java
/** * Get a named element defined in the specification. * //from w ww .j a va 2 s .com * @param elementName * Name of the element to search * @param type * Type of the element * @return Named element or null if does not exist in the current * specification */ @SuppressWarnings("rawtypes") private NamedElement getNamedElement(final String elementName, final Class type) { UnmodifiableIterator<EObject> it = Iterators.filter(specification.eAllContents(), new Predicate<EObject>() { public boolean apply(EObject eObject) { if (eObject != null && eObject instanceof NamedElement && type.getSimpleName().equals(eObject.eClass().getName())) { return elementName.equals(((NamedElement) eObject).getName()); } return false; } }); if (it.hasNext()) { return (NamedElement) it.next(); } return null; }