本文整理匯總了Java中com.google.common.collect.PeekingIterator.next方法的典型用法代碼示例。如果您正苦於以下問題:Java PeekingIterator.next方法的具體用法?Java PeekingIterator.next怎麽用?Java PeekingIterator.next使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.PeekingIterator
的用法示例。
在下文中一共展示了PeekingIterator.next方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getNonOverlappingBounds
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
* Retrieves non-overlapping bounds for the list of input bounds
*
* Assume we have the following bounds
* (brackets representing left/right bound):
* [ ] [ ] [ ] [ ]
* [ ] [ ]
* This method will return the following bounds:
* [ ] [ ]
*
* @param bounds unsorted bounds to find overlaps
* @return the non-overlapping bounds
*/
public static <T extends RingPosition<T>> Set<Bounds<T>> getNonOverlappingBounds(Iterable<Bounds<T>> bounds)
{
ArrayList<Bounds<T>> sortedBounds = Lists.newArrayList(bounds);
Collections.sort(sortedBounds, new Comparator<Bounds<T>>()
{
public int compare(Bounds<T> o1, Bounds<T> o2)
{
return o1.left.compareTo(o2.left);
}
});
Set<Bounds<T>> nonOverlappingBounds = Sets.newHashSet();
PeekingIterator<Bounds<T>> it = Iterators.peekingIterator(sortedBounds.iterator());
while (it.hasNext())
{
Bounds<T> beginBound = it.next();
Bounds<T> endBound = beginBound;
while (it.hasNext() && endBound.right.compareTo(it.peek().left) >= 0)
endBound = it.next();
nonOverlappingBounds.add(new Bounds<>(beginBound.left, endBound.right));
}
return nonOverlappingBounds;
}
示例2: visitStatements
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void visitStatements(List<? extends StatementTree> statements) {
boolean first = true;
PeekingIterator<StatementTree> it =
Iterators.<StatementTree>peekingIterator(statements.iterator());
dropEmptyDeclarations();
while (it.hasNext()) {
StatementTree tree = it.next();
builder.forcedBreak();
if (!first) {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
markForPartialFormat();
first = false;
List<VariableTree> fragments = variableFragments(it, tree);
if (!fragments.isEmpty()) {
visitVariables(
fragments,
DeclarationKind.NONE,
canLocalHaveHorizontalAnnotations(fragments.get(0).getModifiers()));
} else {
scan(tree, null);
}
}
}
示例3: nextTree
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private InstanceParsePair<NlpFocus<DepNode, DepTree>> nextTree(PeekingIterator<NlpFocus<DepNode,
DepTree>> iterator) {
if (!iterator.hasNext()) {
return null;
}
List<NlpFocus<DepNode, DepTree>> instances = new ArrayList<>();
NlpFocus<DepNode, DepTree> current = iterator.next();
DepTree tree = current.sequence();
instances.add(current);
while (iterator.hasNext()) {
current = iterator.peek();
if (tree.index() == current.sequence().index()) {
instances.add(iterator.next());
continue;
}
break;
}
return new InstanceParsePair<>(instances, (DefaultDepTree) tree);
}
示例4: toRanges
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
* Converts a set of integers into a set of contiguous closed ranges that equally represent the
* input integers.
* <p>
* The resulting ranges will be in ascending order.
* <p>
* TODO(wfarner): Change this to return a canonicalized RangeSet.
*
* @param values Values to transform to ranges.
* @return Closed ranges with identical members to the input set.
*/
public static Set<Range<Integer>> toRanges(Iterable<Integer> values) {
ImmutableSet.Builder<Range<Integer>> builder = ImmutableSet.builder();
PeekingIterator<Integer> iterator =
Iterators.peekingIterator(Sets.newTreeSet(values).iterator());
// Build ranges until there are no numbers left.
while (iterator.hasNext()) {
// Start a new range.
int start = iterator.next();
int end = start;
// Increment the end until the range is non-contiguous.
while (iterator.hasNext() && iterator.peek() == end + 1) {
end++;
iterator.next();
}
builder.add(Range.closed(start, end));
}
return builder.build();
}
示例5: expectStateTransitions
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void expectStateTransitions(
String taskId,
ScheduleStatus initial,
ScheduleStatus next,
ScheduleStatus... others) {
List<ScheduleStatus> statuses = ImmutableList.<ScheduleStatus>builder()
.add(initial)
.add(next)
.add(others)
.build();
PeekingIterator<ScheduleStatus> it = Iterators.peekingIterator(statuses.iterator());
while (it.hasNext()) {
ScheduleStatus cur = it.next();
try {
eventSink.post(matchStateChange(taskId, cur, it.peek()));
} catch (NoSuchElementException e) {
// Expected.
}
}
}
示例6: getPzxBlock
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private static PZXBlock getPzxBlock(PeekingIterator<TapeBlock> iterator) {
TapeBlock block = iterator.next();
PulseList blockPulseList = block.getPulseList();
PZXBlock pzxBlock = new PZXNullBlock();
switch (block.getBlockType()) {
case UNKNOWN:
// TODO if this is the beginning of the tape and followed by a pilot discard
// TODO if this is about a second after a data block with a tail but before a pulse block use a pause block?
pzxBlock = new PZXPulseBlock(blockPulseList);
break;
case PILOT:
pzxBlock = getPzxPulseBlock(iterator, blockPulseList);
break;
case SYNC_CANDIDATE:
pzxBlock = new PZXPulseBlock(blockPulseList);
break;
case DATA:
pzxBlock = getPzxDataBlock(iterator, block);
break;
case TAIL_CANDIDATE:
pzxBlock = new PZXPulseBlock(blockPulseList);
break;
}
return pzxBlock;
}
示例7: testExpirationTime
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
@Test
public void testExpirationTime() {
long start = System.currentTimeMillis();
Iterator<Long> unlimitedIter = countForever();
PeekingIterator<Long> limitedIter = TimeLimitedIterator.create(unlimitedIter, Duration.millis(10), 0);
long previous = -1;
while (limitedIter.hasNext()) {
long next = limitedIter.next();
assertEquals(next, previous + 1);
previous = next;
}
long stop = System.currentTimeMillis();
long elapsed = stop - start;
assertTrue(elapsed >= 10);
assertTrue(elapsed < 100); // be fairly relaxed about the upper bound to avoid spurious test failures on slow machines.
assertEquals(unlimitedIter.next(), (previous + 1));
}
示例8: readAll
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
void readAll(String channel, SlabFilter filter, EventSink sink, ConsistencyLevel consistency) {
// PeekingIterator is needed so that we can look ahead and see the next slab Id
PeekingIterator<Column<ByteBuffer>> manifestColumns = Iterators.peekingIterator(executePaginated(
_keyspace.prepareQuery(ColumnFamilies.MANIFEST, consistency)
.getKey(channel)
.withColumnRange(new RangeBuilder().setLimit(50).build())
.autoPaginate(true)).iterator());
while (manifestColumns.hasNext()) {
Column<ByteBuffer> manifestColumn = manifestColumns.next();
ByteBuffer slabId = manifestColumn.getName();
ByteBuffer nextSlabId = manifestColumns.hasNext() ? manifestColumns.peek().getName() : null;
boolean open = manifestColumn.getBooleanValue();
if (filter != null && !filter.accept(slabId, open, nextSlabId)) {
continue;
}
if (!readSlab(channel, slabId, new SlabCursor(), open, sink)) {
break;
}
}
}
示例9: createReversedLeafIterator
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private PeekingIterator<ILeafNode> createReversedLeafIterator(INode root, INode candidate, LinkedList<ILeafNode> sameGrammarElement) {
EObject grammarElement = null;
PeekingIterator<ILeafNode> iterator = Iterators.peekingIterator(Iterators.filter(root.getAsTreeIterable().reverse().iterator(), ILeafNode.class));
// traverse until we find the current candidate
while(iterator.hasNext()) {
ILeafNode next = iterator.next();
if (candidate.equals(next)) {
break;
} else if (next.getTotalLength() == 0) {
EObject otherGrammarElement = tryGetGrammarElementAsRule(next);
if (grammarElement == null) {
grammarElement = otherGrammarElement;
}
if (otherGrammarElement.equals(grammarElement)) {
sameGrammarElement.add(next);
} else {
sameGrammarElement.removeLast();
}
}
}
return iterator;
}
示例10: restoreOneTransaction
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
* Restore the contents of one transaction to Datastore.
*
* <p>The objects to delete are listed in the {@link CommitLogManifest}, which will be the first
* object in the iterable. The objects to save follow, each as a {@link CommitLogMutation}. We
* restore by deleting the deletes and recreating the saves from their proto form. We also save
* the commit logs themselves back to Datastore, so that the commit log system itself is
* transparently restored alongside the data.
*
* @return the manifest, for use in restoring the {@link CommitLogBucket}.
*/
private CommitLogManifest restoreOneTransaction(PeekingIterator<ImmutableObject> commitLogs) {
final CommitLogManifest manifest = (CommitLogManifest) commitLogs.next();
Result<?> deleteResult = deleteAsync(manifest.getDeletions());
List<Entity> entitiesToSave = Lists.newArrayList(ofy().save().toEntity(manifest));
while (commitLogs.hasNext() && commitLogs.peek() instanceof CommitLogMutation) {
CommitLogMutation mutation = (CommitLogMutation) commitLogs.next();
entitiesToSave.add(ofy().save().toEntity(mutation));
entitiesToSave.add(EntityTranslator.createFromPbBytes(mutation.getEntityProtoBytes()));
}
saveRaw(entitiesToSave);
try {
deleteResult.now();
} catch (Exception e) {
retrier.callWithRetry(
() -> deleteAsync(manifest.getDeletions()).now(), RuntimeException.class);
}
return manifest;
}
示例11: visitStatements
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void visitStatements(List<? extends StatementTree> statements) {
boolean first = true;
PeekingIterator<StatementTree> it = Iterators.peekingIterator(statements.iterator());
dropEmptyDeclarations();
while (it.hasNext()) {
StatementTree tree = it.next();
builder.forcedBreak();
if (!first) {
builder.blankLineWanted(BlankLineWanted.PRESERVE);
}
markForPartialFormat();
first = false;
List<VariableTree> fragments = variableFragments(it, tree);
if (!fragments.isEmpty()) {
visitVariables(
fragments,
DeclarationKind.NONE,
canLocalHaveHorizontalAnnotations(fragments.get(0).getModifiers()));
} else {
scan(tree, null);
}
}
}
示例12: updateForRow
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void updateForRow(PeekingIterator<PartitionUpdate.CounterMark> markIter, Row row, ColumnFamilyStore cfs)
{
int cmp = 0;
// If the mark is before the row, we have no value for this mark, just consume it
while (markIter.hasNext() && (cmp = compare(markIter.peek().clustering(), row.clustering(), cfs)) < 0)
markIter.next();
if (!markIter.hasNext())
return;
while (cmp == 0)
{
PartitionUpdate.CounterMark mark = markIter.next();
Cell cell = mark.path() == null ? row.getCell(mark.column()) : row.getCell(mark.column(), mark.path());
if (cell != null)
{
updateWithCurrentValue(mark, CounterContext.instance().getLocalClockAndCount(cell.value()), cfs);
markIter.remove();
}
if (!markIter.hasNext())
return;
cmp = compare(markIter.peek().clustering(), row.clustering(), cfs);
}
}
示例13: scanBlock
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
Description scanBlock(MethodTree tree, BlockTree block, VisitorState state) {
PeekingIterator<? extends StatementTree> it =
Iterators.peekingIterator(block.getStatements().iterator());
while (it.hasNext() && !MATCHER.matches(it.peek(), state)) {
it.next();
}
List<Tree> expectations = new ArrayList<>();
while (it.hasNext() && MATCHER.matches(it.peek(), state)) {
expectations.add(it.next());
}
if (expectations.isEmpty()) {
return NO_MATCH;
}
Deque<StatementTree> suffix = new ArrayDeque<>();
StatementTree failure = null;
Iterators.addAll(suffix, it);
if (!suffix.isEmpty() && FAIL_MATCHER.matches(suffix.peekLast(), state)) {
failure = suffix.removeLast();
}
return handleMatch(tree, state, expectations, ImmutableList.copyOf(suffix), failure);
}
示例14: iterator
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
@Override
public Iterator<List<T>> iterator() {
final PeekingIterator<T> iter = Iterators.peekingIterator(delegate.iterator());
return new AbstractIterator<List<T>>() {
@Override
protected List<T> computeNext() {
if (!iter.hasNext()) {
return endOfData();
}
ArrayList<T> result = Lists.newArrayList();
T last = iter.next();
result.add(last);
while (iter.hasNext() && equiv.equivalent(last, iter.peek())) {
last = iter.next(); // get peeked value
result.add(last);
}
return result;
}
};
}
示例15: writeEntries
import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private static void writeEntries(JsonGenerator jg, List<Trace.Entry> entries)
throws IOException {
jg.writeStartArray();
PeekingIterator<Trace.Entry> i = Iterators.peekingIterator(entries.iterator());
while (i.hasNext()) {
Trace.Entry entry = i.next();
int depth = entry.getDepth();
jg.writeStartObject();
writeJson(entry, jg);
int nextDepth = i.hasNext() ? i.peek().getDepth() : 0;
if (nextDepth > depth) {
jg.writeArrayFieldStart("childEntries");
} else if (nextDepth < depth) {
jg.writeEndObject();
for (int j = depth; j > nextDepth; j--) {
jg.writeEndArray();
jg.writeEndObject();
}
} else {
jg.writeEndObject();
}
}
jg.writeEndArray();
}