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.eclipselabs.agrum.services.model.plugin.parser.ModelParser.java
/** * To get an iterator on each outgoing transition of a state, which possessed a tick event as trigger * @param s - the state//from w ww . j av a 2 s . c o m * @return the iterator */ private static Iterator<Transition> tickTransitionIterator(State s) { Predicate<Object> allTransitions = Predicates.instanceOf(Transition.class); Iterator<Transition> transitions = Iterators.filter(s.getOutgoings().listIterator(), allTransitions); transitions = Iterators.filter(transitions, new com.google.common.base.Predicate<Transition>() { @Override public boolean apply(Transition arg0) { for (Trigger trg : arg0.getTriggers()) { if (trg.getEvent().getName().equals(clockTriggerName)) return true; } return false; } }); return transitions; }
From source file:com.yahoo.yqlplus.api.types.Annotations.java
@Override public Iterator<Map.Entry<String, Object>> iterator() { // we don't expect much use of this final Set<String> seen = Sets.newTreeSet(); return Iterators.filter(Iterators.concat(annotations.entrySet().iterator(), parent.iterator()), new Predicate<Map.Entry<String, Object>>() { @Override//from w ww .j av a 2s . c o m public boolean apply(Map.Entry<String, Object> input) { return seen.add(input.getKey()); } }); }
From source file:org.openengsb.ui.common.util.MethodUtil.java
public static Map<String, PropertyEditor> getRelevantProperties(final Object bean) throws IntrospectionException { Class<?> beanClass = bean.getClass(); BeanInfo beanInfo = Introspector.getBeanInfo(beanClass); PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors(); Iterator<PropertyDescriptor> propertyIterator = Iterators.forArray(propertyDescriptors); Iterator<PropertyDescriptor> filtered = Iterators.filter(propertyIterator, new Predicate<PropertyDescriptor>() { @Override//from ww w .java 2s . c om public boolean apply(PropertyDescriptor input) { if (!input.getPropertyType().equals(String.class)) { return false; } Method writeMethod = input.getWriteMethod(); if (writeMethod == null) { return false; } return Modifier.isPublic(writeMethod.getModifiers()); } }); Map<String, PropertyEditor> result = Maps.newHashMap(); while (filtered.hasNext()) { PropertyDescriptor descriptor = filtered.next(); result.put(descriptor.getName(), descriptor.createPropertyEditor(bean)); } return result; }
From source file:org.eclipse.xtext.nodemodel.impl.AbstractNode.java
@Override public Iterable<ILeafNode> getLeafNodes() { return new Iterable<ILeafNode>() { @Override/*from w w w. jav a2 s .c om*/ public Iterator<ILeafNode> iterator() { return Iterators.filter(basicIterator(), ILeafNode.class); } }; }
From source file:br.com.caelum.vraptor.http.route.DefaultRouter.java
public <T> String urlFor(Class<T> type, Method method, Object... params) { Iterator<Route> matches = Iterators.filter(routes.iterator(), Filters.canHandle(type, method)); if (matches.hasNext()) { try {/*from w w w . ja v a 2 s . co m*/ return matches.next().urlFor(type, method, params); } catch (Exception e) { throw new VRaptorException( "The selected route is invalid for redirection: " + type.getName() + "." + method.getName(), e); } } throw new RouteNotFoundException( "The selected route is invalid for redirection: " + type.getName() + "." + method.getName()); }
From source file:org.fcrepo.kernel.impl.rdf.impl.NodeTypeRdfContext.java
/** * Convert a NodeType into an RDF stream by capturing the supertypes, node * definitions, and property definitions of the type as RDFS triples. * * @param nodeType the node type/*from www.jav a 2 s .c o m*/ * @throws RepositoryException if repository exception occurred */ public NodeTypeRdfContext(final NodeType nodeType) throws RepositoryException { super(); final Node nodeTypeResource = getResource(nodeType).asNode(); final String nodeTypeName = nodeType.getName(); LOGGER.trace("Adding triples for nodeType: {} with URI: {}", nodeTypeName, nodeTypeResource.getURI()); concat(Collections2.transform(copyOf(nodeType.getDeclaredSupertypes()), new Function<NodeType, Triple>() { @Override public Triple apply(final NodeType input) { final Node supertypeNode; try { supertypeNode = getResource(input).asNode(); LOGGER.trace("Adding triple for nodeType: {} with subclass: {}", nodeTypeName, supertypeNode.getURI()); return create(nodeTypeResource, subClassOf.asNode(), supertypeNode); } catch (final RepositoryException e) { throw propagate(e); } } })); concat(Iterators .concat(Iterators.transform( Iterators.filter(forArray(nodeType.getDeclaredChildNodeDefinitions()), not(isWildcardResidualDefinition)), new NodeDefinitionToTriples(nodeTypeResource)))); concat(Iterators .concat(Iterators.transform( Iterators.filter(forArray(nodeType.getDeclaredPropertyDefinitions()), not(isWildcardResidualDefinition)), new PropertyDefinitionToTriples(nodeTypeResource)))); concat(create(nodeTypeResource, type.asNode(), Class.asNode()), create(nodeTypeResource, label.asNode(), createLiteral(nodeTypeName))); }
From source file:org.locationtech.geogig.geotools.plumbing.ExportDiffOp.java
/** * Executes the export operation using the parameters that have been specified. * //from w w w . j a v a 2s .c o m * @return a FeatureCollection with the specified features */ @Override protected SimpleFeatureStore _call() { final SimpleFeatureStore targetStore = getTargetStore(); final String refspec = old ? oldRef : newRef; final RevTree rootTree = resolveRootTree(refspec); final NodeRef typeTreeRef = resolTypeTreeRef(refspec, path, rootTree); final ObjectId defaultMetadataId = typeTreeRef.getMetadataId(); final ProgressListener progressListener = getProgressListener(); progressListener.started(); progressListener.setDescription("Exporting diffs for path '" + path + "'... "); FeatureCollection<SimpleFeatureType, SimpleFeature> asFeatureCollection = new BaseFeatureCollection<SimpleFeatureType, SimpleFeature>() { @Override public FeatureIterator<SimpleFeature> features() { Iterator<DiffEntry> diffs = command(DiffOp.class).setOldVersion(oldRef).setNewVersion(newRef) .setFilter(path).call(); final Iterator<SimpleFeature> plainFeatures = getFeatures(diffs, old, objectDatabase(), defaultMetadataId, progressListener); Iterator<Optional<Feature>> transformed = Iterators.transform(plainFeatures, ExportDiffOp.this.function); Iterator<SimpleFeature> filtered = Iterators .filter(Iterators.transform(transformed, new Function<Optional<Feature>, SimpleFeature>() { @Override public SimpleFeature apply(Optional<Feature> input) { return (SimpleFeature) (input.isPresent() ? input.get() : null); } }), Predicates.notNull()); return new DelegateFeatureIterator<SimpleFeature>(filtered); } }; // add the feature collection to the feature store final Transaction transaction; if (transactional) { transaction = new DefaultTransaction("create"); } else { transaction = Transaction.AUTO_COMMIT; } try { targetStore.setTransaction(transaction); try { targetStore.addFeatures(asFeatureCollection); transaction.commit(); } catch (final Exception e) { if (transactional) { transaction.rollback(); } Throwables.propagateIfInstanceOf(e, GeoToolsOpException.class); throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } finally { transaction.close(); } } catch (IOException e) { throw new GeoToolsOpException(e, StatusCode.UNABLE_TO_ADD); } progressListener.complete(); return targetStore; }
From source file:org.geogit.remote.BinaryPackedObjects.java
/** * Find commits which should be previsited to avoid resending objects that are already on the * receiving end. A commit should be previsited if: * <ul>/*from ww w .j av a 2s. c om*/ * <li>It is not going to be visited, and * <li>It is the immediate ancestor of a commit which is going to be previsited. * </ul> * */ private ImmutableList<ObjectId> scanForPrevisitList(List<ObjectId> want, List<ObjectId> have, Deduplicator deduplicator) { /* * @note Implementation note: To find the previsit list, we just iterate over all the * commits that will be visited according to our want and have lists. Any parents of commits * in this traversal which are part of the 'have' list will be in the previsit list. */ Iterator<RevCommit> willBeVisited = Iterators.filter( // PostOrderIterator.rangeOfCommits(want, have, database, deduplicator), // RevCommit.class); ImmutableSet.Builder<ObjectId> builder = ImmutableSet.builder(); while (willBeVisited.hasNext()) { RevCommit next = willBeVisited.next(); List<ObjectId> parents = new ArrayList<ObjectId>(next.getParentIds()); parents.retainAll(have); builder.addAll(parents); } return ImmutableList.copyOf(builder.build()); }
From source file:org.eclipse.sirius.editor.tools.internal.presentation.ViewpoitnDependenciesSelectionDialog.java
private Option<Set<URI>> selectViewpoints(Shell shell, EAttribute attribute, String title, String message) { List<URI> available = getAvailableViewpointsURIs(); available.remove(new ViewpointQuery(viewpoint).getViewpointURI().get()); Collections.sort(available, Ordering.usingToString()); List<URI> selected = getSelectedSiriusURIs(viewpoint, attribute); ListSelectionDialog lsd = new ListSelectionDialog(shell, available, new SiriusURIContentProvider(), new LabelProvider(), message); lsd.setInitialElementSelections(selected); lsd.setTitle(title);/*from w ww . j av a2s. co m*/ if (lsd.open() == Window.OK) { Set<URI> result = ImmutableSet.copyOf(Iterators.filter(Iterators.forArray(lsd.getResult()), URI.class)); return Options.newSome(result); } else { return Options.newNone(); } }
From source file:org.eclipse.sirius.diagram.ui.internal.refresh.listeners.NotationVisibilityUpdater.java
@Override public Command transactionAboutToCommit(final ResourceSetChangeEvent event) throws RollbackException { Command cmd = null;/*from www .j a v a2s.c o m*/ Map<View, Boolean> viewsToUpdate = new HashMap<View, Boolean>(); boolean removeHideNote = DiagramUIPlugin.getPlugin().getPreferenceStore().getBoolean( SiriusDiagramUiInternalPreferencesKeys.PREF_REMOVE_HIDE_NOTE_WHEN_ANNOTED_ELEMENT_HIDDEN_OR_REMOVE .name()); for (Notification notification : event.getNotifications()) { if (notification.getNotifier() instanceof DDiagramElement) { DDiagramElement dDiagramElement = (DDiagramElement) notification.getNotifier(); View referencingView = getReferencingView(dDiagramElement); if (referencingView != null) { if (notification.getFeature() == DiagramPackage.eINSTANCE.getDDiagramElement_Visible()) { viewsToUpdate.put(referencingView, Boolean.valueOf(notification.getNewBooleanValue())); if (removeHideNote) { Set<View> allViewsToHide = new HashSet<View>(); allContentsViewsVisibilityScope(referencingView, allViewsToHide, viewsToUpdate); Iterators.filter(referencingView.eAllContents(), View.class); final Iterator<View> allContents = Iterators.filter(referencingView.eAllContents(), View.class); while (allContents.hasNext()) { final Object next = allContents.next(); allContentsViewsVisibilityScope((View) next, allViewsToHide, viewsToUpdate); } for (View view : allViewsToHide) { viewsToUpdate.put(view, notification.getNewBooleanValue()); } } } else if (notification.getFeature() == DiagramPackage.eINSTANCE.getDEdge_IsFold()) { viewsToUpdate.put(referencingView, !Boolean.valueOf(notification.getNewBooleanValue())); } else if (notification.getFeature() == DiagramPackage.eINSTANCE .getDDiagramElement_GraphicalFilters()) { List<View> correspondingLabelView = lookForCorrespondingLabelView(dDiagramElement); if (notification.getOldValue() instanceof HideLabelFilter) { for (View view : correspondingLabelView) { viewsToUpdate.put(view, Boolean.TRUE); } } else if (notification.getNewValue() instanceof HideLabelFilter) { for (View view : correspondingLabelView) { viewsToUpdate.put(view, Boolean.FALSE); } } } } } } if (!viewsToUpdate.isEmpty()) { cmd = new VisibilityUpdateCommand(session.getTransactionalEditingDomain(), viewsToUpdate); } return cmd; }