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.eclipse.sirius.editor.tree.tools.internal.menu.TreeWizardMenuBuilder.java
private Option<EAttribute> lookForEditableName(EClass eClassToStartFrom) { Iterator<EAttribute> it = Iterators.filter(eClassToStartFrom.getEAllAttributes().iterator(), new Predicate<EAttribute>() { public boolean apply(EAttribute input) { return "name".equals(input.getName()) && "EString".equals(input.getEType().getName()); }//from ww w . j a v a 2 s. co m }); if (it.hasNext()) { return Options.newSome(it.next()); } else { return Options.newNone(); } }
From source file:org.eclipse.sirius.diagram.ui.tools.internal.actions.repair.DiagramRepairParticipant.java
/** * Remove elements with isCreatedElement sets to true. Store data about the * other./*from w w w .j av a 2 s . c om*/ * * @param view * @return the list of elements that can be safety removed. */ private List<EObject> computeElementsToDeleteOrDeletedElements(final DView view) { final List<EObject> toBeRemoved = Lists.newArrayList(); lostNodesByDelete.clear(); lostEdgesByDelete.clear(); // If an element has its mapping configured with isCreatedElements sets // to true, it will be removed and then recreated by diagram refresh. // But an element with isCreated sets to false won't be recreated by // refresh. Another process will recreate them after. final Iterator<DDiagramElement> viewIterator = Iterators.filter(view.eAllContents(), DDiagramElement.class); while (viewIterator.hasNext()) { final DDiagramElement diagElement = viewIterator.next(); if (new DiagramElementMappingQuery(diagElement.getDiagramElementMapping()) .isSynchronizedAndCreateElement(diagElement)) { toBeRemoved.add(diagElement); } else { if (LostElementFactory.isCompleteDiagramElement(diagElement)) { final DiagramKey diagramKey = DiagramKey.createDiagramKey(diagElement.getParentDiagram()); if (diagElement instanceof AbstractDNode) { createLostNodeData(diagramKey, diagElement); } else if (diagElement instanceof DEdge) { createLostEdgeData(diagramKey, diagElement); } } } } return toBeRemoved; }
From source file:org.locationtech.geogig.plumbing.WriteTree2.java
private RevTree applyChanges(@Nullable final NodeRef leftTreeRef, @Nullable final NodeRef rightTreeRef) { Preconditions.checkArgument(leftTreeRef != null || rightTreeRef != null, "either left or right tree shall be non null"); final ObjectDatabase repositoryDatabase = objectDatabase(); final String treePath = rightTreeRef == null ? leftTreeRef.path() : rightTreeRef.path(); final Set<String> strippedPathFilters = stripParentAndFiltersThatDontApply(this.pathFilters, treePath); // find the diffs that apply to the path filters final ObjectId leftTreeId = leftTreeRef == null ? RevTree.EMPTY_TREE_ID : leftTreeRef.getObjectId(); final ObjectId rightTreeId = rightTreeRef == null ? RevTree.EMPTY_TREE_ID : rightTreeRef.getObjectId(); final RevTree currentLeftTree = repositoryDatabase.getTree(leftTreeId); final CanonicalTreeBuilder builder = CanonicalTreeBuilder.create(repositoryDatabase, currentLeftTree); // create the new trees taking into account all the nodes DiffTree diffs = command(DiffTree.class).setRecursive(false).setReportTrees(false).setOldTree(leftTreeId) .setNewTree(rightTreeId).setPathFilter(new ArrayList<>(strippedPathFilters)).setCustomFilter(null); try (AutoCloseableIterator<DiffEntry> sourceIterator = diffs.get()) { Iterator<DiffEntry> updatedIterator = sourceIterator; if (!strippedPathFilters.isEmpty()) { final Set<String> expected = Sets.newHashSet(strippedPathFilters); updatedIterator = Iterators.filter(updatedIterator, new Predicate<DiffEntry>() { @Override//from w ww .ja v a 2 s. c o m public boolean apply(DiffEntry input) { boolean applies; if (input.isDelete()) { applies = expected.contains(input.oldName()); } else { applies = expected.contains(input.newName()); } return applies; } }); } for (; updatedIterator.hasNext();) { final DiffEntry diff = updatedIterator.next(); if (diff.isDelete()) { builder.remove(diff.oldName()); } else { NodeRef newObject = diff.getNewObject(); Node node = newObject.getNode(); builder.put(node); } } } final RevTree newTree = builder.build(); repositoryDatabase.put(newTree); return newTree; }
From source file:org.locationtech.geogig.repository.impl.WorkingTreeImpl.java
@Override public ObjectId insert(Iterator<FeatureInfo> featureInfos, ProgressListener progress) { checkArgument(featureInfos != null); checkArgument(progress != null);//from w w w . j av a 2 s .c o m final RevTree currentWorkHead = getTree(); final Map<String, NodeRef> currentTrees = Maps .newHashMap(Maps.uniqueIndex(getFeatureTypeTrees(), (nr) -> nr.path())); Map<String, CanonicalTreeBuilder> parentBuilders = new HashMap<>(); progress.setProgress(0); final AtomicLong p = new AtomicLong(); Function<FeatureInfo, RevFeature> treeBuildingTransformer = (fi) -> { final String parentPath = NodeRef.parentPath(fi.getPath()); final String fid = NodeRef.nodeFromPath(fi.getPath()); @Nullable ObjectId metadataId = fi.getFeatureTypeId(); CanonicalTreeBuilder parentBuilder = getTreeBuilder(currentTrees, parentBuilders, parentPath, metadataId); if (fi.isDelete()) { if (parentBuilder != null) { parentBuilder.remove(fid); } return null; } Preconditions.checkState(parentBuilder != null); RevFeature feature = fi.getFeature(); NodeRef parentRef = currentTrees.get(parentPath); Preconditions.checkNotNull(parentRef); if (fi.getFeatureTypeId().equals(parentRef.getMetadataId())) { metadataId = ObjectId.NULL;// use the parent's default } ObjectId oid = feature.getId(); Envelope bounds = SpatialOps.boundsOf(feature); Node featureNode = Node.create(fid, oid, metadataId, TYPE.FEATURE, bounds); parentBuilder.put(featureNode); progress.setProgress(p.incrementAndGet()); return feature; }; Iterator<RevFeature> features = Iterators.transform(featureInfos, treeBuildingTransformer); features = Iterators.filter(features, Predicates.notNull()); features = Iterators.filter(features, (f) -> !progress.isCanceled()); Stopwatch insertTime = Stopwatch.createStarted(); indexDatabase.putAll(features); insertTime.stop(); if (progress.isCanceled()) { return currentWorkHead.getId(); } progress.setDescription(String.format("%,d features inserted in %s", p.get(), insertTime)); UpdateTree updateTree = context.command(UpdateTree.class).setRoot(currentWorkHead); parentBuilders.forEach((path, builder) -> { final NodeRef oldTreeRef = currentTrees.get(path); progress.setDescription(String.format("Building final tree %s...", oldTreeRef.name())); Stopwatch treeTime = Stopwatch.createStarted(); final RevTree newFeatureTree = builder.build(); treeTime.stop(); progress.setDescription( String.format("%,d features tree built in %s", newFeatureTree.size(), treeTime)); final NodeRef newTreeRef = oldTreeRef.update(newFeatureTree.getId(), SpatialOps.boundsOf(newFeatureTree)); updateTree.setChild(newTreeRef); }); final RevTree newWorkHead = updateTree.call(); return updateWorkHead(newWorkHead.getId()); }
From source file:org.apache.uima.lucas.indexer.analysis.AnnotationTokenStream.java
protected void initializeIterators() { annotationIterator = Iterators.filter(jCas.getAnnotationIndex(annotationType).iterator(), new NotNullPredicate<Annotation>()); if (!annotationIterator.hasNext()) { featureStructureIterator = Iterators.emptyIterator(); featureValueIterator = Iterators.emptyIterator(); return;// w ww. ja va2 s. c o m } currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator(currentAnnotation, featurePath); if (!featureStructureIterator.hasNext()) { featureValueIterator = Iterators.emptyIterator(); return; } FeatureStructure featureStructure = featureStructureIterator.next(); featureValueIterator = createFeatureValueIterator(featureStructure, featureNames); }
From source file:org.locationtech.geogig.storage.postgresql.PGObjectStore.java
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override//from w ww .jav a 2s .com public <T extends RevObject> Iterator<T> getAll(Iterable<ObjectId> ids, BulkOpListener listener, Class<T> type) { checkNotNull(ids, "ids is null"); checkNotNull(listener, "listener is null"); checkNotNull(type, "type is null"); checkState(isOpen(), "Database is closed"); config.checkRepositoryExists(); final Set<ObjectId> queryIds = ids instanceof Set ? (Set<ObjectId>) ids : Sets.newHashSet(ids); ImmutableMap<ObjectId, byte[]> cached = byteCache.getAllPresent(queryIds); Iterator<T> hits = Collections.emptyIterator(); Iterator<T> stream = Collections.emptyIterator(); if (!cached.isEmpty()) { Map<ObjectId, T> cachedObjects = Maps.transformEntries(cached, (id, bytes) -> { RevObject o = encoder.decode(id, bytes); if (type.isAssignableFrom(o.getClass())) { listener.found(id, Integer.valueOf(bytes.length)); return type.cast(o); } listener.notFound(id); return null; }); hits = Iterators.filter(cachedObjects.values().iterator(), Predicates.notNull()); } if (queryIds.size() > cached.size()) { Set<ObjectId> misses = Sets.difference(queryIds, cached.keySet()); stream = new GetAllIterator(dataSource, misses.iterator(), type, listener, this); } return Iterators.concat(hits, stream); }
From source file:com.blogspot.jabelarminecraft.movinglightsource.proxy.CommonProxy.java
protected void addSpawnAllBiomes(EntityLiving parEntity, int parChance, int parMinGroup, int parMaxGroup) { /*/*from w ww .j a v a 2 s .com*/ * 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:com.rcpcompany.uibindings.bindings.xtext.xtext.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. * /*from w w w. j av a2s .co m*/ * @param support * the decoration support to configure */ private void configureSourceViewerDecorationSupport(SourceViewerDecorationSupport support) { final Iterator<AnnotationPreference> e = Iterators .filter(myAnnotationPreferences.getAnnotationPreferences().iterator(), AnnotationPreference.class); while (e.hasNext()) { support.setAnnotationPreference(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 (myCharacterPairMatcher != null) { support.setCharacterPairMatcher(myCharacterPairMatcher); support.setMatchingCharacterPainterPreferenceKeys(BracketMatchingPreferencesInitializer.IS_ACTIVE_KEY, BracketMatchingPreferencesInitializer.COLOR_KEY); } }
From source file:org.eclipse.sirius.editor.tree.tools.internal.menu.TreeWizardMenuBuilder.java
public EClassHierarchy(ResourceSet resourceSet) { Set<EClass> allClasses = Sets .newLinkedHashSet(Lists.newArrayList(Iterators.filter(resourceSet.getAllContents(), EClass.class))); Set<EClass> somebodyIsExtendingMe = Sets.newLinkedHashSet(); for (EClass eClass : allClasses) { // TODO open a popup to allow selection of types to browse.. if (!"DiagramImportDescription".equals(eClass.getName())) { somebodyIsExtendingMe.addAll(eClass.getEAllSuperTypes()); }/*from www . j a va 2 s . c o m*/ } Collection<? extends EClass> leaves = Sets.difference(allClasses, somebodyIsExtendingMe); for (EClass leaf : leaves) { mostSpecific.put(leaf, leaf); Iterator<EClass> it = leaf.getEAllSuperTypes().iterator(); while (it.hasNext()) { EClass next = it.next(); mostSpecific.put(next, leaf); } } }
From source file:org.obeonetwork.dsl.uml2.design.api.services.ActivityDiagramServices.java
/** * Get all the operations available in the semantic resources. * * @param eObj// w w w . j a va 2 s . c o m * Semantic element * @return All the operations */ private List<EObject> getAllOperations(Element element) { final List<EObject> operations = Lists.newArrayList(); final List<org.eclipse.uml2.uml.Package> rootPkgs = getAllAvailableRootPackages(element); final Predicate<EObject> predicate = new Predicate<EObject>() { public boolean apply(EObject eObj) { return eObj instanceof Operation && (((Operation) eObj).getMethods() == null || ((Operation) eObj).getMethods().size() == 0); } }; for (final org.eclipse.uml2.uml.Package pkg : rootPkgs) { Iterators.addAll(operations, Iterators.filter(pkg.eAllContents(), predicate)); } return operations; }