private static Iterator<Row> convertToRows(final CellGrouper grouper, final PeekingIterator<LegacyAtom> atoms)
{
return new AbstractIterator<Row>()
{
protected Row computeNext()
{
if (!atoms.hasNext())
return endOfData();
return getNextRow(grouper, atoms);
}
};
}
java类com.google.common.collect.PeekingIterator的实例源码
LegacyLayout.java 文件源码
项目:sstable-adaptor
阅读 20
收藏 0
点赞 0
评论 0
ReorderingEventReader.java 文件源码
项目:tg-eventstore
阅读 24
收藏 0
点赞 0
评论 0
@Override
public Stream<ResolvedEvent> readAllForwards(Position positionExclusive) {
try(Stream<ResolvedEvent> allForwards = underlying.readAllForwards(positionExclusive)) {
PeekingIterator<ResolvedEvent> allForwardsIterator = Iterators.peekingIterator(allForwards.iterator());
if (allForwardsIterator.hasNext() && sortKeyExtractor.apply(allForwardsIterator.peek()).compareTo(cutoffSortKey) < 0) {
allForwards.close();
return bufferedAndSortedReadAllForwards(positionExclusive);
}
return stream(spliteratorUnknownSize(allForwardsIterator, ORDERED), false).onClose(allForwards::close);
}
}
ReorderingEventReader.java 文件源码
项目:tg-eventstore
阅读 21
收藏 0
点赞 0
评论 0
private Stream<ResolvedEvent> bufferedAndSortedReadAllForwards(Position positionExclusive) {
try(Stream<ResolvedEvent> allForwards = underlying.readAllForwards()) {
Iterator<ResolvedEvent> remainder = allForwards.iterator();
PeekingIterator<EventWithSortKey<T>> sortCandidates = Iterators.peekingIterator(
Iterators.transform(remainder, re -> new EventWithSortKey<>(re, sortKeyExtractor.apply(re)))
);
final LinkedList<EventWithSortKey<T>> buffer = new LinkedList<>();
while (sortCandidates.hasNext() && sortCandidates.peek().sortKey.compareTo(cutoffSortKey) < 0) {
buffer.add(sortCandidates.next());
}
if (!sortCandidates.hasNext()) {
return Stream.empty();
}
buffer.sort(Comparator.naturalOrder());
if (!positionExclusive.equals(underlying.emptyStorePosition())) {
Iterator<EventWithSortKey<T>> bufferIterator = buffer.iterator();
while (!bufferIterator.next().event.position().equals(positionExclusive)) {
bufferIterator.remove();
}
bufferIterator.remove();
}
Stream<EventWithSortKey<T>> reorderedEvents = buffer.stream().onClose(buffer::clear);
Stream<EventWithSortKey<T>> eventInTheGap = Stream.of(sortCandidates.peek());
Stream<ResolvedEvent> remainingEvents = stream(spliteratorUnknownSize(remainder, ORDERED), false);
return concat(concat(reorderedEvents, eventInTheGap).map(EventWithSortKey::toResolvedEvent), remainingEvents).onClose(allForwards::close);
}
}
EventShovel.java 文件源码
项目:tg-eventstore
阅读 21
收藏 0
点赞 0
评论 0
private static <T> Iterator<Iterator<T>> batchBy(Iterator<T> it, Function<T, Object> grouping) {
return new Iterator<Iterator<T>>() {
PeekingIterator<T> peekingIterator = peekingIterator(it);
@Override
public boolean hasNext() {
return peekingIterator.hasNext();
}
@Override
public Iterator<T> next() {
return new Iterator<T>() {
private Object currentGroup = grouping.apply(peekingIterator.peek());
private boolean isSameGroup() {
return currentGroup.equals(grouping.apply(peekingIterator.peek()));
}
@Override
public boolean hasNext() {
return peekingIterator.hasNext() && isSameGroup();
}
@Override
public T next() {
if (!isSameGroup()) {
throw new NoSuchElementException();
}
return peekingIterator.next();
}
};
}
};
}
EventStoreMergingIterator.java 文件源码
项目:tg-eventstore
阅读 20
收藏 0
点赞 0
评论 0
private Iterator<EventInIdentifiedStream> getIteratorWhoseHeadIsNext() {
if (iteratorWhoseHeadIsNext != null) {
return iteratorWhoseHeadIsNext;
}
Iterator<PeekingIterator<EventInIdentifiedStream>> streams = underlying.iterator();
while (streams.hasNext()) {
PeekingIterator<EventInIdentifiedStream> eventStream = streams.next();
Instant potentialCutoffTime = clock.instant();
if (eventStream.hasNext()) {
if (cutOffTime != null && eventStream.peek().event.effectiveTimestamp().isAfter(cutOffTime)) {
streams.remove();
} else if (iteratorWhoseHeadIsNext == null || order.compare(eventStream.peek(), iteratorWhoseHeadIsNext.peek()) < 0) {
iteratorWhoseHeadIsNext = eventStream;
}
} else {
streams.remove();
if (this.cutOffTime == null) {
this.cutOffTime = potentialCutoffTime.minus(delay).toEpochMilli();
}
}
}
if (iteratorWhoseHeadIsNext != null) {
long cutoff = this.cutOffTime == null ? clock.instant().minus(delay).toEpochMilli() : this.cutOffTime;
if (iteratorWhoseHeadIsNext.peek().event.effectiveTimestamp().isAfter(cutoff)) {
underlying.clear();
return null;
}
}
return iteratorWhoseHeadIsNext;
}
JavaInputAstVisitor.java 文件源码
项目:javaide
阅读 25
收藏 0
点赞 0
评论 0
/**
* The parser expands multi-variable declarations into separate single-variable declarations. All
* of the fragments in the original declaration have the same start position, so we use that as a
* signal to collect them and preserve the multi-variable declaration in the output.
* <p>
* <p>e.g. {@code int x, y;} is parsed as {@code int x; int y;}.
*/
private List<VariableTree> variableFragments(PeekingIterator<? extends Tree> it, Tree first) {
List<VariableTree> fragments = new ArrayList<>();
if (first.getKind() == VARIABLE) {
int start = getStartPosition(first);
fragments.add((VariableTree) first);
while (it.hasNext()
&& it.peek().getKind() == VARIABLE
&& getStartPosition(it.peek()) == start) {
fragments.add((VariableTree) it.next());
}
}
return fragments;
}
JavadocLexer.java 文件源码
项目:javaide
阅读 25
收藏 0
点赞 0
评论 0
/**
* Where the input has two consecutive line breaks between literals, insert a {@code <p>} tag
* between the literals.
* <p>
* <p>This method must be called after {@link #joinAdjacentLiteralsAndAdjacentWhitespace}, as it
* assumes that adjacent whitespace tokens have already been joined.
*/
private static ImmutableList<Token> inferParagraphTags(List<Token> input) {
ImmutableList.Builder<Token> output = ImmutableList.builder();
for (PeekingIterator<Token> tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) {
if (tokens.peek().getType() == LITERAL) {
output.add(tokens.next());
if (tokens.peek().getType() == WHITESPACE
&& hasMultipleNewlines(tokens.peek().getValue())) {
output.add(tokens.next());
if (tokens.peek().getType() == LITERAL) {
output.add(new Token(PARAGRAPH_OPEN_TAG, "<p>"));
}
}
} else {
// TODO(cpovirk): Or just `continue` from the <p> case and move this out of the `else`?
output.add(tokens.next());
}
}
return output.build();
/*
* Note: We do not want to insert <p> tags inside <pre>. Fortunately, the formatter gets that
* right without special effort on our part. The reason: Line breaks inside a <pre> section are
* of type FORCED_NEWLINE rather than WHITESPACE.
*/
}
PlainSortedMergeIterator.java 文件源码
项目:Elasticsearch
阅读 21
收藏 0
点赞 0
评论 0
public PlainSortedMergeIterator(Iterable<? extends KeyIterable<TKey, TRow>> iterables, final Comparator<? super TRow> itemComparator) {
Comparator<PeekingIterator<TRow>> heapComparator = new Comparator<PeekingIterator<TRow>>() {
@Override
public int compare(PeekingIterator<TRow> o1, PeekingIterator<TRow> o2) {
return itemComparator.compare(o1.peek(), o2.peek());
}
};
queue = new PriorityQueue<>(2, heapComparator);
addIterators(iterables);
}
CompactorScanner.java 文件源码
项目:incubator-omid
阅读 23
收藏 0
点赞 0
评论 0
private void skipToNextColumn(Cell cell, PeekingIterator<Map.Entry<Cell, Optional<Cell>>> iter) {
while (iter.hasNext()
&& CellUtil.matchingFamily(iter.peek().getKey(), cell)
&& CellUtil.matchingQualifier(iter.peek().getKey(), cell)) {
iter.next();
}
}
PZXPulseBlock.java 文件源码
项目:wav2pzx
阅读 21
收藏 0
点赞 0
评论 0
/**
* Return the on-disk PZX format data for the supplied PulseList
* @param pulseList the PulseList to encode into the disk representation
* @return the byte[] with the PZX disk format data
*/
public static byte[] getPZXBlockDiskRepresentation(PulseList pulseList) {
// iterate through the pulse array doing a run length encoding of the number of repeated values
PeekingIterator<Long> iterator = Iterators.peekingIterator(pulseList.getPulseLengths().iterator());
int count;
// We will probably have a similar number of bytes output as source pulses * 2 16 bit values
ArrayList<Byte> output = new ArrayList<>(pulseList.getPulseLengths().size()*4);
// The pulse level is low at start of the block by default. However initial
// pulse of zero duration may be easily used to make it high.
if( pulseList.getFirstPulseLevel() == 1 ) {
PZXEncodeUtils.addBytesFor(0, 1, output);
}
// RLE the pulses found in the block for encoding
while(iterator.hasNext()) {
long pulse = iterator.next();
count = 1;
while(iterator.hasNext() && iterator.peek() == pulse) {
iterator.next();
count += 1;
}
// Write the desired output bytes to the output list
PZXEncodeUtils.addBytesFor(pulse, count, output);
}
return addPZXBlockHeader("PULS", output);
}