use of com.google.common.collect.AbstractIterator in project jackrabbit-oak by apache.
the class ChildNodeStateProvider method children.
Iterator<NodeStateEntry> children(boolean preferred) {
PeekingIterator<NodeStateEntry> pitr = Iterators.peekingIterator(entries.iterator());
if (!pitr.hasNext()) {
return emptyIterator();
}
// Skip till current entry
while (pitr.hasNext() && !pitr.peek().getPath().equals(path)) {
pitr.next();
}
// Skip past the current find
checkState(pitr.hasNext() && path.equals(pitr.next().getPath()), "Did not found path [%s] in leftover iterator. Possibly node state accessed " + "after main iterator has moved past it", path);
// Prepare an iterator to fetch all child node paths i.e. immediate and there children
return new AbstractIterator<NodeStateEntry>() {
@Override
protected NodeStateEntry computeNext() {
while (pitr.hasNext() && isAncestor(path, pitr.peek().getPath())) {
NodeStateEntry nextEntry = pitr.next();
String nextEntryPath = nextEntry.getPath();
if (isImmediateChild(nextEntryPath)) {
String nextEntryName = PathUtils.getName(nextEntryPath);
if (preferred && !preferredPathElements.contains(nextEntryName)) {
return endOfData();
}
return nextEntry;
}
}
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project jackrabbit-oak by apache.
the class FlatFileStore method createBaseIterator.
private Iterator<NodeStateEntry> createBaseIterator() {
LineIterator itr = new LineIterator(createReader(storeFile, compressionEnabled));
closer.register(itr::close);
return new AbstractIterator<NodeStateEntry>() {
@Override
protected NodeStateEntry computeNext() {
if (itr.hasNext()) {
return convert(itr.nextLine());
}
// End of iterator then close it
LineIterator.closeQuietly(itr);
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project atlasdb by palantir.
the class InMemoryKeyValueService method getRangeInternal.
private <T> ClosableIterator<RowResult<T>> getRangeInternal(TableReference tableRef, final RangeRequest range, final ResultProducer<T> resultProducer) {
ConcurrentNavigableMap<Key, byte[]> tableMap = getTableMap(tableRef).entries;
if (range.isReverse()) {
tableMap = tableMap.descendingMap();
}
if (range.getStartInclusive().length != 0) {
if (range.isReverse()) {
Cell startCell = Cells.createLargestCellForRow(range.getStartInclusive());
tableMap = tableMap.tailMap(new Key(startCell, Long.MIN_VALUE));
} else {
Cell startCell = Cells.createSmallestCellForRow(range.getStartInclusive());
tableMap = tableMap.tailMap(new Key(startCell, Long.MIN_VALUE));
}
}
if (range.getEndExclusive().length != 0) {
if (range.isReverse()) {
Cell endCell = Cells.createLargestCellForRow(range.getEndExclusive());
tableMap = tableMap.headMap(new Key(endCell, Long.MAX_VALUE));
} else {
Cell endCell = Cells.createSmallestCellForRow(range.getEndExclusive());
tableMap = tableMap.headMap(new Key(endCell, Long.MAX_VALUE));
}
}
final PeekingIterator<Entry<Key, byte[]>> it = Iterators.peekingIterator(tableMap.entrySet().iterator());
return ClosableIterators.wrap(new AbstractIterator<RowResult<T>>() {
@Override
protected RowResult<T> computeNext() {
while (true) {
if (!it.hasNext()) {
return endOfData();
}
ImmutableSortedMap.Builder<byte[], T> result = ImmutableSortedMap.orderedBy(UnsignedBytes.lexicographicalComparator());
Key key = it.peek().getKey();
byte[] row = key.row;
Iterator<Entry<Key, byte[]>> cellIter = takeCell(it, key);
collectValueForTimestamp(key.col, cellIter, result, range, resultProducer);
while (it.hasNext()) {
if (!it.peek().getKey().matchesRow(row)) {
break;
}
key = it.peek().getKey();
cellIter = takeCell(it, key);
collectValueForTimestamp(key.col, cellIter, result, range, resultProducer);
}
SortedMap<byte[], T> columns = result.build();
if (!columns.isEmpty()) {
return RowResult.create(row, columns);
}
}
}
});
}
use of com.google.common.collect.AbstractIterator in project incubator-gobblin by apache.
the class HiveDatasetFinder method getDatasetsIterator.
@Override
public Iterator<HiveDataset> getDatasetsIterator() throws IOException {
return new AbstractIterator<HiveDataset>() {
private Iterator<DbAndTable> tables = getTables().iterator();
@Override
protected HiveDataset computeNext() {
while (this.tables.hasNext()) {
DbAndTable dbAndTable = this.tables.next();
try (AutoReturnableObject<IMetaStoreClient> client = HiveDatasetFinder.this.clientPool.getClient()) {
Table table = client.get().getTable(dbAndTable.getDb(), dbAndTable.getTable());
Config datasetConfig = getDatasetConfig(table);
if (ConfigUtils.getBoolean(datasetConfig, HIVE_DATASET_IS_BLACKLISTED_KEY, DEFAULT_HIVE_DATASET_IS_BLACKLISTED_KEY)) {
continue;
}
if (HiveDatasetFinder.this.eventSubmitter.isPresent()) {
SlaEventSubmitter.builder().datasetUrn(dbAndTable.toString()).eventSubmitter(HiveDatasetFinder.this.eventSubmitter.get()).eventName(DATASET_FOUND).build().submit();
}
return createHiveDataset(table, datasetConfig);
} catch (IllegalArgumentException e) {
Throwables.propagate(e);
} catch (Throwable t) {
log.error(String.format("Failed to create HiveDataset for table %s.%s", dbAndTable.getDb(), dbAndTable.getTable()), t);
if (HiveDatasetFinder.this.eventSubmitter.isPresent()) {
SlaEventSubmitter.builder().datasetUrn(dbAndTable.toString()).eventSubmitter(HiveDatasetFinder.this.eventSubmitter.get()).eventName(DATASET_ERROR).additionalMetadata(FAILURE_CONTEXT, t.toString()).build().submit();
}
}
}
return endOfData();
}
};
}
use of com.google.common.collect.AbstractIterator in project guava by google.
the class DirectedGraphConnections method incidentEdgeIterator.
@Override
public Iterator<EndpointPair<N>> incidentEdgeIterator(N thisNode) {
checkNotNull(thisNode);
Iterator<EndpointPair<N>> resultWithDoubleSelfLoop;
if (orderedNodeConnections == null) {
resultWithDoubleSelfLoop = Iterators.concat(Iterators.transform(predecessors().iterator(), (N predecessor) -> EndpointPair.ordered(predecessor, thisNode)), Iterators.transform(successors().iterator(), (N successor) -> EndpointPair.ordered(thisNode, successor)));
} else {
resultWithDoubleSelfLoop = Iterators.transform(orderedNodeConnections.iterator(), (NodeConnection<N> connection) -> {
if (connection instanceof NodeConnection.Succ) {
return EndpointPair.ordered(thisNode, connection.node);
} else {
return EndpointPair.ordered(connection.node, thisNode);
}
});
}
AtomicBoolean alreadySeenSelfLoop = new AtomicBoolean(false);
return new AbstractIterator<EndpointPair<N>>() {
@Override
@CheckForNull
protected EndpointPair<N> computeNext() {
while (resultWithDoubleSelfLoop.hasNext()) {
EndpointPair<N> edge = resultWithDoubleSelfLoop.next();
if (edge.nodeU().equals(edge.nodeV())) {
if (!alreadySeenSelfLoop.getAndSet(true)) {
return edge;
}
} else {
return edge;
}
}
return endOfData();
}
};
}
Aggregations