List of usage examples for com.google.common.collect Iterators concat
public static <T> Iterator<T> concat(Iterator<? extends T> a, Iterator<? extends T> b)
From source file:org.apache.beam.sdk.transforms.join.CoGbkResult.java
private <T> void updateUnionTag(final Reiterator<RawUnionValue> tail, final Boolean[] containsTag, int unionTag, final int unionTag0) { @SuppressWarnings("unchecked") final Iterable<T> head = (Iterable<T>) valueMap.get(unionTag); valueMap.set(unionTag, new Iterable<T>() { @Override// www . j av a 2 s. com public Iterator<T> iterator() { return Iterators.concat(head.iterator(), new UnionValueIterator<T>(unionTag0, tail.copy(), containsTag)); } }); }
From source file:org.geogit.api.plumbing.diff.TreeDiffEntryIterator.java
public TreeDiffEntryIterator(@Nullable NodeRef oldTreeRef, @Nullable NodeRef newTreeRef, @Nullable RevTree oldTree, @Nullable RevTree newTree, final boolean reportTrees, final boolean recursive, final ObjectDatabase db) { checkArgument(oldTree != null || newTree != null); this.reportTrees = reportTrees; this.recursive = recursive; this.objectDb = db; this.strategy = resolveStrategy(); if (oldTree != null && newTree != null && oldTree.getId().equals(newTree.getId())) { delegate = Iterators.emptyIterator(); } else if (oldTree == null) { delegate = addRemoveAll(newTreeRef, newTree, ADDED); } else if (newTree == null) { delegate = addRemoveAll(oldTreeRef, oldTree, REMOVED); } else if (!oldTree.buckets().isPresent() && !newTree.buckets().isPresent()) { Strategy itStategy = recursive ? DepthTreeIterator.Strategy.CHILDREN : DepthTreeIterator.Strategy.FEATURES_ONLY; Iterator<NodeRef> left = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, db, itStategy);//from w ww .j a va 2 s .co m Iterator<NodeRef> right = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, db, itStategy); delegate = new ChildrenChildrenDiff(left, right); } else if (oldTree.buckets().isPresent() && newTree.buckets().isPresent()) { delegate = new BucketBucketDiff(oldTreeRef, newTreeRef, oldTree.buckets().get(), newTree.buckets().get()); } else if (newTree.buckets().isPresent()) { checkState(!oldTree.buckets().isPresent()); DepthTreeIterator left = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, objectDb, strategy); DepthTreeIterator rightIterator; rightIterator = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, objectDb, strategy); delegate = new ChildrenChildrenDiff(left, rightIterator); } else { checkState(oldTree.buckets().isPresent()); DepthTreeIterator right = new DepthTreeIterator(newTreeRef.path(), newTreeRef.getMetadataId(), newTree, objectDb, strategy); DepthTreeIterator leftIterator; leftIterator = new DepthTreeIterator(oldTreeRef.path(), oldTreeRef.getMetadataId(), oldTree, objectDb, strategy); delegate = new ChildrenChildrenDiff(leftIterator, right); // delegate = new BucketsChildrenDiff(left, right); } // If the tree has changed its metadata Id, it will not be reported as a diff // up to this point. // We check here that both metadata Id's are identical, and if not, we add the DiffEntry // corresponding to the tree. if (reportTrees && oldTreeRef != null && newTreeRef != null && !oldTreeRef.getMetadataId().equals(newTreeRef.getMetadataId())) { DiffEntry diffEntry = new DiffEntry(oldTreeRef, newTreeRef); UnmodifiableIterator<DiffEntry> iter = Iterators.singletonIterator(diffEntry); delegate = Iterators.concat(delegate, iter); } }
From source file:org.liveSense.core.service.DynamicClassLoader.java
/** * @see java.lang.ClassLoader#getResources(java.lang.String) *///from w w w . j a v a2 s . c o m @Override @SuppressWarnings("unchecked") public Enumeration<URL> getResources(final String name) throws IOException { return Iterators.asEnumeration(Iterators.concat(new EnumerationIterator<URL>(super.getResources(name)), new EnumerationIterator<URL>(getResourcesImpl(name)))); }
From source file:org.carrot2.core.ProcessingComponentSuite.java
/** * Remove components marked as unavailable from the suite. * /* w ww. j ava 2 s.co m*/ * @see ProcessingComponentDescriptor#isComponentAvailable() */ public List<ProcessingComponentDescriptor> removeUnavailableComponents() { ArrayList<ProcessingComponentDescriptor> failed = Lists.newArrayList(); ProcessingComponentDescriptor p; for (Iterator<? extends ProcessingComponentDescriptor> i = Iterators.concat(sources.iterator(), algorithms.iterator()); i.hasNext();) { p = i.next(); if (!p.isComponentAvailable()) { failed.add(p); i.remove(); } } return failed; }
From source file:org.fcrepo.kernel.api.utils.iterators.RdfStream.java
/** * @param newTriples Triples to add./*from ww w . j ava2 s.c o m*/ * @return This object for continued use. */ public RdfStream concat(final Collection<? extends Triple> newTriples) { triples = Iterators.concat(triples, newTriples.iterator()); return this; }
From source file:org.apache.druid.extendedset.intset.ImmutableConciseSet.java
public static ImmutableConciseSet intersection(Iterator<ImmutableConciseSet> sets) { ImmutableConciseSet partialResults = doIntersection(Iterators.limit(sets, CHUNK_SIZE)); while (sets.hasNext()) { final UnmodifiableIterator<ImmutableConciseSet> partialIter = Iterators .singletonIterator(partialResults); partialResults = doIntersection(Iterators.concat(Iterators.limit(sets, CHUNK_SIZE), partialIter)); }//from www. j av a2 s .c o m return partialResults; }
From source file:org.locationtech.geogig.cli.porcelain.Diff.java
/** * Executes the diff command with the specified options. *//* w ww . j a v a 2 s . c o m*/ @Override protected void runInternal(GeogigCLI cli) throws IOException { checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec); checkParameter(!(nogeom && summary), "Only one printing mode allowed"); checkParameter(!(bounds && count), "Only one of --bounds or --count is allowed"); checkParameter(!(cached && refSpec.size() > 1), "--cached allows zero or one ref specs to compare the index with."); GeoGIG geogig = cli.getGeogig(); String oldVersion = resolveOldVersion(); String newVersion = resolveNewVersion(); List<String> paths = removeEmptyPaths(); if (bounds) { DiffBounds diff = geogig.command(DiffBounds.class).setOldVersion(oldVersion).setNewVersion(newVersion) .setCompareIndex(cached); diff.setPathFilters(paths); CoordinateReferenceSystem crs = parseCrs(); if (crs != null) { diff.setCRS(crs); } DiffSummary<BoundingBox, BoundingBox> diffBounds = diff.call(); BoundsDiffPrinter.print(geogig, cli.getConsole(), diffBounds); return; } if (count) { if (oldVersion == null) { oldVersion = Ref.HEAD; } if (newVersion == null) { newVersion = cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD; } DiffCount cdiff = geogig.command(DiffCount.class).setOldVersion(oldVersion).setNewVersion(newVersion); cdiff.setFilter(paths); DiffObjectCount count = cdiff.call(); ConsoleReader console = cli.getConsole(); console.println(String.format("Trees changed: %d, features changed: %,d", count.treeCount(), count.featureCount())); console.flush(); return; } DiffOp diff = geogig.command(DiffOp.class); diff.setOldVersion(oldVersion).setNewVersion(newVersion).setCompareIndex(cached); Iterator<DiffEntry> entries; if (paths.isEmpty()) { entries = diff.setProgressListener(cli.getProgressListener()).call(); } else { entries = Iterators.emptyIterator(); for (String path : paths) { Iterator<DiffEntry> moreEntries = diff.setFilter(path) .setProgressListener(cli.getProgressListener()).call(); entries = Iterators.concat(entries, moreEntries); } } if (!entries.hasNext()) { cli.getConsole().println("No differences found"); return; } DiffPrinter printer; if (summary) { printer = new SummaryDiffPrinter(); } else { printer = new FullDiffPrinter(nogeom, false); } DiffEntry entry; while (entries.hasNext()) { entry = entries.next(); printer.print(geogig, cli.getConsole(), entry); } }
From source file:org.apache.marmotta.kiwi.sparql.builder.model.SQLFragment.java
/** * Build the combined condition clause for this fragment. This will be the empty string when the conditionPosition is JOIN. * @return/* w ww . jav a 2 s. c o m*/ */ @Override public String buildConditionClause() { StringBuilder conditionClause = new StringBuilder(); if (conditionPosition == ConditionPosition.WHERE || conditionPosition == ConditionPosition.HAVING) { for (Iterator<SQLClause> it = Iterators.concat(patterns.iterator(), subqueries.iterator()); it .hasNext();) { SQLClause p = it.next(); // in case we add the condition to the JOIN, build first the conditions for the pattern; otherwise, the // conditions for the pattern will be added to the WHERE clause if (conditionClause.length() > 0) { conditionClause.append("\n AND "); } conditionClause.append(p.buildConditionClause()); } } if (conditionPosition == ConditionPosition.WHERE) { // in case the pattern is the last of the fragment, also add the filter conditions of the fragment // if this is the last pattern of the fragment, add the filter conditions for (Iterator<String> cit = getConditions().iterator(); cit.hasNext();) { String next = cit.next(); if (conditionClause.length() > 0 && next.length() > 0) { conditionClause.append("\n AND "); } conditionClause.append(next); } } return conditionClause.toString(); }
From source file:org.geogit.api.RevTreeImpl.java
@Override public Iterator<Node> children() { Preconditions.checkState(!buckets().isPresent()); final ImmutableList<Node> empty = ImmutableList.of(); return Iterators.concat(trees().or(empty).iterator(), features().or(empty).iterator()); }
From source file:org.locationtech.geogig.storage.impl.PersistedIterable.java
@Override public Iterator<T> iterator() { Iterator<T> iterator = Collections.emptyIterator(); lock.readLock().lock();/* ww w.j ava 2 s. c o m*/ try { final long streamLimit = this.tmpFile == null ? 0L : (Files.exists(this.tmpFile) ? Files.size(this.tmpFile) : 0L); if (streamLimit > 0) { InputStream in; try { in = Files.newInputStream(tmpFile, StandardOpenOption.READ); in = new BufferedInputStream(in, 16 * 1024); in = ByteStreams.limit(in, streamLimit); if (this.compress) { in = new LZFInputStream(in); } DataInputStream dataIn = new DataInputStream(in); StreamIterator<T> streamIt = new StreamIterator<T>(serializer, dataIn); iterator = Iterators.concat(iterator, streamIt); } catch (IOException e) { throw Throwables.propagate(e); } } if (!this.buffer.isEmpty()) { ArrayList<T> buffered = Lists.newArrayList(this.buffer); iterator = Iterators.concat(iterator, buffered.iterator()); } } catch (Exception e) { throw Throwables.propagate(e); } finally { lock.readLock().unlock(); } return iterator; }