當前位置: 首頁>>代碼示例>>Java>>正文


Java PeekingIterator.hasNext方法代碼示例

本文整理匯總了Java中com.google.common.collect.PeekingIterator.hasNext方法的典型用法代碼示例。如果您正苦於以下問題:Java PeekingIterator.hasNext方法的具體用法?Java PeekingIterator.hasNext怎麽用?Java PeekingIterator.hasNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.common.collect.PeekingIterator的用法示例。


在下文中一共展示了PeekingIterator.hasNext方法的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;
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:39,代碼來源:Bounds.java

示例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);
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:25,代碼來源:JavaInputAstVisitor.java

示例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);
}
 
開發者ID:clearwsd,項目名稱:clearwsd,代碼行數:20,代碼來源:SemevalReader.java

示例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();
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:34,代碼來源:Numbers.java

示例5: 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));
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:19,代碼來源:TimeLimitedIteratorTest.java

示例6: 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;
        }
    }
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:22,代碼來源:AstyanaxEventReaderDAO.java

示例7: 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;
}
 
開發者ID:google,項目名稱:nomulus,代碼行數:30,代碼來源:RestoreCommitLogsAction.java

示例8: match

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
 * Attempt to match the desired properties to a sequence of known properties.
 * <p>
 * Returns a list of the same length as the original. Entries are:
 * - Optional.empty(): the property was satisfied completely
 * - non-empty: the (simplified) property that was not satisfied
 */
public static <T> List<Optional<LocalProperty<T>>> match(List<LocalProperty<T>> actuals, List<LocalProperty<T>> desired)
{
    // After normalizing actuals, each symbol should only appear once
    PeekingIterator<LocalProperty<T>> actualIterator = peekingIterator(normalizeAndPrune(actuals).iterator());

    Set<T> constants = new HashSet<>();
    boolean consumeMoreActuals = true;
    List<Optional<LocalProperty<T>>> result = new ArrayList<>(desired.size());
    for (LocalProperty<T> desiredProperty : desired) {
        while (consumeMoreActuals && actualIterator.hasNext() && desiredProperty.isSimplifiedBy(actualIterator.peek())) {
            constants.addAll(actualIterator.next().getColumns());
        }
        Optional<LocalProperty<T>> simplifiedDesired = desiredProperty.withConstants(constants);
        consumeMoreActuals &= !simplifiedDesired.isPresent(); // Only continue processing actuals if all previous desired properties were fully satisfied
        result.add(simplifiedDesired);
    }
    return result;
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:26,代碼來源:LocalProperties.java

示例9: 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);
    }
  }
}
 
開發者ID:google,項目名稱:google-java-format,代碼行數:24,代碼來源:JavaInputAstVisitor.java

示例10: next

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
@Override
public GTRecord next() {
    if (!hasNext()) {
        throw new NoSuchElementException();
    }
    // get smallest record
    PeekingIterator<GTRecord> it = heap.poll();
    // WATCH OUT! record got from PartitionResultIterator.next() may changed later,
    // so we must make a shallow copy of it.
    record.shallowCopyFrom(it.next());

    if (it.hasNext()) {
        heap.offer(it);
    }

    return record;
}
 
開發者ID:apache,項目名稱:kylin,代碼行數:18,代碼來源:SortMergedPartitionResultIterator.java

示例11: 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);
    }
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:26,代碼來源:CounterMutation.java

示例12: 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);
}
 
開發者ID:google,項目名稱:error-prone,代碼行數:22,代碼來源:AbstractExpectedExceptionChecker.java

示例13: 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;
    }
  };
}
 
開發者ID:steveash,項目名稱:jg2p,代碼行數:21,代碼來源:GroupingIterable.java

示例14: 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();
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:25,代碼來源:TraceCommonService.java

示例15: merge

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void merge(List<Profile.ProfileNode> flatNodes,
        List<ProfileNode> destinationRootNodes) {
    destinationStack.push(destinationRootNodes);
    PeekingIterator<Profile.ProfileNode> i =
            Iterators.peekingIterator(flatNodes.iterator());
    while (i.hasNext()) {
        Profile.ProfileNode flatNode = i.next();
        int destinationDepth = destinationStack.size() - 1;
        for (int j = 0; j < destinationDepth - flatNode.getDepth(); j++) {
            // TODO optimize: faster way to pop multiple elements at once
            destinationStack.pop();
        }
        ProfileNode destinationNode = mergeOne(flatNode, destinationStack.getFirst());
        if (i.hasNext() && i.peek().getDepth() > flatNode.getDepth()) {
            destinationStack.push(destinationNode.childNodes);
        }
    }
}
 
開發者ID:glowroot,項目名稱:glowroot,代碼行數:19,代碼來源:MutableProfile.java


注:本文中的com.google.common.collect.PeekingIterator.hasNext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。