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.geogit.cli.porcelain.Diff.java
/** * Executes the diff command with the specified options. *//*from w w w . j a va2 s . c om*/ @Override protected void runInternal(GeogitCLI cli) throws IOException { checkParameter(refSpec.size() <= 2, "Commit list is too long :%s", refSpec); checkParameter(!(nogeom && summary), "Only one printing mode allowed"); GeoGIT geogit = cli.getGeogit(); DiffOp diff = geogit.command(DiffOp.class); String oldVersion = resolveOldVersion(); String newVersion = resolveNewVersion(); 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(geogit, cli.getConsole(), entry); } }
From source file:org.locationtech.geogig.cli.porcelain.FormatPatch.java
/** * Executes the format-patch command with the specified options. *///from w w w. j av a 2s . c om @Override protected void runInternal(GeogigCLI cli) throws IOException { checkParameter(refSpec.size() < 3, "Commit list is too long :%s", refSpec); GeoGIG geogig = cli.getGeogig(); checkParameter(file != null, "Patch file not specified"); DiffOp diff = geogig.command(DiffOp.class).setReportTrees(true); String oldVersion = resolveOldVersion(); String newVersion = resolveNewVersion(); 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; } Patch patch = geogig.command(CreatePatchOp.class).setDiffs(entries).call(); FileOutputStream fos = new FileOutputStream(file); OutputStreamWriter out = new OutputStreamWriter(fos, "UTF-8"); PatchSerializer.write(out, patch); }
From source file:io.druid.java.util.common.guava.FunctionalIterator.java
public FunctionalIterator<T> concat(Iterator<T>... toConcat) { if (toConcat.length == 1) { return new FunctionalIterator<>(Iterators.concat(delegate, toConcat[0])); }/* w w w .j av a 2 s .co m*/ return new FunctionalIterator<>(Iterators.concat(delegate, Iterators.concat(toConcat))); }
From source file:org.sonar.javascript.model.implementations.statement.CaseClauseTreeImpl.java
@Override public Iterator<Tree> childrenIterator() { return Iterators.concat(Iterators.singletonIterator(expression), statements.iterator()); }
From source file:ru.parallel.octotron.reactions.PreparedResponseFactory.java
private void FillSurround(PreparedResponse prepared_response, ModelEntity entity) { ModelLinkList links = new ModelLinkList(); ModelObjectList objects = new ModelObjectList(); if (entity.GetType() == EModelType.LINK) { ModelLink link = (ModelLink) entity; links.add(link);/*from w w w .java2 s.com*/ objects.add(link.Source()); objects.add(link.Target()); } else if (entity.GetType() == EModelType.OBJECT) { ModelObject object = (ModelObject) entity; links = links.append(object.GetInLinks()); links = links.append(object.GetOutLinks()); objects = objects.append(object.GetInNeighbors()).Uniq(); objects = objects.append(object.GetOutNeighbors()).Uniq(); } Iterator<ModelEntity> it = Iterators.concat(links.iterator(), objects.iterator()); while (it.hasNext()) { ModelEntity surround = it.next(); for (PreparedResponse surround_responses : surround.GetPreparedResponses()) { Map<String, Object> map = surround_responses.GetShortRepresentation(); map.remove("surround"); prepared_response.surround.add(map); } } }
From source file:org.apache.cassandra.db.PartitionColumns.java
public Iterator<ColumnDefinition> iterator() { return Iterators.concat(statics.iterator(), regulars.iterator()); }
From source file:org.geogit.osm.internal.OSMMapOp.java
@Override public RevTree call() { checkNotNull(mapping);// w w w.java 2 s. com long staged = getIndex().countStaged(null).getCount(); long unstaged = getWorkTree().countUnstaged(null).getCount(); Preconditions.checkState((staged == 0 && unstaged == 0), "You must have a clean working tree and index to perform a mapping."); ObjectId oldTreeId = getWorkTree().getTree().getId(); Iterator<Feature> nodes; if (mapping.canUseNodes()) { nodes = getFeatures("WORK_HEAD:node"); } else { nodes = Iterators.emptyIterator(); } Iterator<Feature> ways; if (mapping.canUseWays()) { ways = getFeatures("WORK_HEAD:way"); } else { ways = Iterators.emptyIterator(); } Iterator<Feature> iterator = Iterators.concat(nodes, ways); if (iterator.hasNext()) { FeatureMapFlusher insertsByParent = new FeatureMapFlusher(getWorkTree()); while (iterator.hasNext()) { Feature feature = iterator.next(); Optional<MappedFeature> newFeature = mapping.map(feature); if (newFeature.isPresent()) { String path = newFeature.get().getPath(); SimpleFeature sf = (SimpleFeature) newFeature.get().getFeature(); insertsByParent.put(path, sf); } } insertsByParent.flushAll(); ObjectId newTreeId = getWorkTree().getTree().getId(); // If the mapping generates the same mapped features that already exist, we do nothing if (!newTreeId.equals(oldTreeId)) { command(AddOp.class).call(); command(CommitOp.class).setMessage(message).call(); command(WriteOSMMappingEntries.class).setMapping(mapping) .setMappingLogEntry(new OSMMappingLogEntry(oldTreeId, newTreeId)).call(); } } return getWorkTree().getTree(); }
From source file:org.geogit.cli.plumbing.DiffTree.java
/** * Executes the diff-tree command with the specified options. *///from w ww . ja v a 2 s.c o m @Override protected void runInternal(GeogitCLI cli) throws IOException { if (refSpec.size() > 2) { throw new CommandFailedException("Tree refspecs list is too long :" + refSpec); } GeoGIT geogit = cli.getGeogit(); org.geogit.api.plumbing.DiffTree diff = geogit.command(org.geogit.api.plumbing.DiffTree.class); String oldVersion = resolveOldVersion(); String newVersion = resolveNewVersion(); diff.setOldVersion(oldVersion).setNewVersion(newVersion); Iterator<DiffEntry> diffEntries; if (paths.isEmpty()) { diffEntries = diff.setProgressListener(cli.getProgressListener()).call(); } else { diffEntries = Iterators.emptyIterator(); for (String path : paths) { Iterator<DiffEntry> moreEntries = diff.setFilterPath(path) .setProgressListener(cli.getProgressListener()).call(); diffEntries = Iterators.concat(diffEntries, moreEntries); } } DiffEntry diffEntry; while (diffEntries.hasNext()) { diffEntry = diffEntries.next(); StringBuilder sb = new StringBuilder(); String path = diffEntry.newPath() != null ? diffEntry.newPath() : diffEntry.oldPath(); if (describe) { sb.append(diffEntry.changeType().toString().charAt(0)).append(' ').append(path).append(LINE_BREAK); if (diffEntry.changeType() == ChangeType.MODIFIED) { FeatureDiff featureDiff = geogit.command(DiffFeature.class) .setNewVersion(Suppliers.ofInstance(diffEntry.getNewObject())) .setOldVersion(Suppliers.ofInstance(diffEntry.getOldObject())).call(); Map<PropertyDescriptor, AttributeDiff> diffs = featureDiff.getDiffs(); HashSet<PropertyDescriptor> diffDescriptors = Sets.newHashSet(diffs.keySet()); NodeRef noderef = diffEntry.changeType() != ChangeType.REMOVED ? diffEntry.getNewObject() : diffEntry.getOldObject(); RevFeatureType featureType = geogit.command(RevObjectParse.class) .setObjectId(noderef.getMetadataId()).call(RevFeatureType.class).get(); Optional<RevObject> obj = geogit.command(RevObjectParse.class).setObjectId(noderef.objectId()) .call(); RevFeature feature = (RevFeature) obj.get(); ImmutableList<Optional<Object>> values = feature.getValues(); ImmutableList<PropertyDescriptor> descriptors = featureType.sortedDescriptors(); int idx = 0; for (PropertyDescriptor descriptor : descriptors) { if (diffs.containsKey(descriptor)) { AttributeDiff ad = diffs.get(descriptor); sb.append(ad.getType().toString().charAt(0) + " " + descriptor.getName().toString() + LINE_BREAK); if (!ad.getType().equals(TYPE.ADDED)) { Object value = ad.getOldValue().orNull(); sb.append(TextValueSerializer.asString(Optional.fromNullable(value))); sb.append(LINE_BREAK); } if (!ad.getType().equals(TYPE.REMOVED)) { Object value = ad.getNewValue().orNull(); sb.append(TextValueSerializer.asString(Optional.fromNullable(value))); sb.append(LINE_BREAK); } diffDescriptors.remove(descriptor); } else { sb.append("U ").append(descriptor.getName().toString()).append(LINE_BREAK); sb.append(TextValueSerializer.asString(values.get(idx))).append(LINE_BREAK); } idx++; } for (PropertyDescriptor descriptor : diffDescriptors) { AttributeDiff ad = diffs.get(descriptor); sb.append(ad.getType().toString().charAt(0) + " " + descriptor.getName().toString() + LINE_BREAK); if (!ad.getType().equals(TYPE.ADDED)) { Object value = ad.getOldValue().orNull(); sb.append(TextValueSerializer.asString(Optional.fromNullable(value))); sb.append(LINE_BREAK); } if (!ad.getType().equals(TYPE.REMOVED)) { Object value = ad.getNewValue().orNull(); sb.append(TextValueSerializer.asString(Optional.fromNullable(value))); sb.append(LINE_BREAK); } } } else { NodeRef noderef = diffEntry.changeType() == ChangeType.ADDED ? diffEntry.getNewObject() : diffEntry.getOldObject(); RevFeatureType featureType = geogit.command(RevObjectParse.class) .setObjectId(noderef.getMetadataId()).call(RevFeatureType.class).get(); Optional<RevObject> obj = geogit.command(RevObjectParse.class).setObjectId(noderef.objectId()) .call(); RevFeature feature = (RevFeature) obj.get(); ImmutableList<Optional<Object>> values = feature.getValues(); int i = 0; for (Optional<Object> value : values) { sb.append(diffEntry.changeType().toString().charAt(0)); sb.append(' '); sb.append(featureType.sortedDescriptors().get(i).getName().toString()); sb.append(LINE_BREAK); sb.append(TextValueSerializer.asString(value)); sb.append(LINE_BREAK); i++; } sb.append(LINE_BREAK); } sb.append(LINE_BREAK); } else { sb.append(path).append(' '); sb.append(diffEntry.oldObjectId().toString()); sb.append(' '); sb.append(diffEntry.newObjectId().toString()); } cli.getConsole().println(sb.toString()); } }
From source file:sg.atom.utils._beta.functional.FunctionalIterator.java
public FunctionalIterator<T> concat(Iterator<Iterator<T>> toConcat) { return new FunctionalIterator<T>(Iterators.concat(delegate, Iterators.concat(toConcat))); }
From source file:org.opendaylight.yangtools.yang.parser.stmt.rfc6020.StmtNamespaceContext.java
@Override public Iterator<String> getPrefixes(final String namespaceURI) { // Ensures underlying map remains constant return Iterators.unmodifiableIterator( Iterators.concat(ctx.getAllFromNamespace(URIStringToImpPrefix.class).values().iterator(), URIToPrefixMap.values().iterator())); }