微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com.google.common.collect.PeekingIterator的实例源码

项目:sstable-adaptor    文件Bounds.java   
/**
 * 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;
}
项目:javaide    文件JavaInputAstVisitor.java   
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);
        }
    }
}
项目:javaide    文件JavadocLexer.java   
/**
 * Replaces whitespace after a {@code href=...>} token with an "optional link break." This allows
 * us to output either {@code <a href=foo>foo</a>} or {@code <a href=foo>\nfoo</a>},depending on
 * how much space we have left on the line.
 * <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> optionalizeSpacesAfterLinks(List<Token> input) {
    ImmutableList.Builder<Token> output = ImmutableList.builder();

    for (PeekingIterator<Token> tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) {
        if (tokens.peek().getType() == LIteraL && tokens.peek().getValue().matches("^href=[^>]*>")) {
            output.add(tokens.next());

            if (tokens.peek().getType() == WHITESPACE) {
                output.add(new Token(OPTIONAL_LINE_BREAK,tokens.next().getValue()));
            }
        } 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.
 */
}
项目:javaide    文件JavadocLexer.java   
/**
 * Adjust indentation inside `<pre>{@code` blocks.
 * <p>
 * <p>Also trim leading and trailing blank lines,and move the trailing `}` to its own line.
 */
private static ImmutableList<Token> deindentPreCodeBlocks(List<Token> input) {
    ImmutableList.Builder<Token> output = ImmutableList.builder();
    for (PeekingIterator<Token> tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) {
        if (tokens.peek().getType() != PRE_OPEN_TAG) {
            output.add(tokens.next());
            continue;
        }

        output.add(tokens.next());
        List<Token> initialNewlines = new ArrayList<>();
        while (tokens.hasNext() && tokens.peek().getType() == FORCED_NEWLINE) {
            initialNewlines.add(tokens.next());
        }
        if (tokens.peek().getType() != LIteraL
                || !tokens.peek().getValue().matches("[ \t]*[{]@code")) {
            output.addAll(initialNewlines);
            output.add(tokens.next());
            continue;
        }

        deindentPreCodeBlock(output,tokens);
    }
    return output.build();
}
项目:clearwsd    文件SemevalReader.java   
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);
}
项目:Mastering-Mesos    文件Numbers.java   
/**
 * 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();
}
项目:Mastering-Mesos    文件StateManagerImpltest.java   
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.
    }
  }
}
项目:wav2pzx    文件PZXBuilder.java   
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;
}
项目:wav2pzx    文件PZXBuilder.java   
private static PZXDataBlock getPzxDataBlock(PeekingIterator<TapeBlock> iterator,TapeBlock block) {
    long tailLength = getTailLength(iterator);

    List<Long> zeropulseLengths = block.getZeroBit().getpulses();
    List<Long> onepulseLengths = block.getoneBit().getpulses();
    DataBuilder dataBuilder = new DataBuilder();

    ImmutableList<Long> pulseLengths = block.getpulseList().getpulseLengths();
    for (int i = 0; i < pulseLengths.size(); i += 2) {
        ImmutableList<Long> pulses = pulseLengths.subList(i,i + 2);
        if (isspecifiedpulseSequence(zeropulseLengths,pulses)) {
            dataBuilder.addBit(0);
        } else if (isspecifiedpulseSequence(onepulseLengths,pulses)) {
            dataBuilder.addBit(1);
        }
        // FIXME: Some kind of error,fall back to pulseBlock?
    }

    int numBitsInLastByte = dataBuilder.getNumBitsInCurrentByte();
    return new PZXDataBlock(block.getpulseList(),zeropulseLengths,onepulseLengths,tailLength,numBitsInLastByte,dataBuilder.getData());
}
项目:emodb    文件TimeLimitedIteratorTest.java   
@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));
}
项目:emodb    文件AstyanaxEventReaderDAO.java   
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(),sink)) {
            break;
        }
    }
}
项目:xtext-core    文件IndentationAwareCompletionPrefixProvider.java   
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;
}
项目:nomulus    文件RestoreCommitLogsAction.java   
/**
 * 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;
}
项目:presto    文件LocalProperties.java   
/**
 * 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;
}
项目:google-java-format    文件JavaInputAstVisitor.java   
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,canLocalHaveHorizontalAnnotations(fragments.get(0).getModifiers()));
    } else {
      scan(tree,null);
    }
  }
}
项目:google-java-format    文件JavadocLexer.java   
/**
 * Replaces whitespace after a {@code href=...>} token with an "optional link break." This allows
 * us to output either {@code <a href=foo>foo</a>} or {@code <a href=foo>\nfoo</a>},depending on
 * how much space we have left on the line.
 *
 * <p>This method must be called after {@link #joinAdjacentLiteralsAndAdjacentWhitespace},as it
 * assumes that adjacent whitespace tokens have already been joined.
 */
private static ImmutableList<Token> optionalizeSpacesAfterLinks(List<Token> input) {
  ImmutableList.Builder<Token> output = ImmutableList.builder();

  for (PeekingIterator<Token> tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) {
    if (tokens.peek().getType() == LIteraL && tokens.peek().getValue().matches("^href=[^>]*>")) {
      output.add(tokens.next());

      if (tokens.peek().getType() == WHITESPACE) {
        output.add(new Token(OPTIONAL_LINE_BREAK,tokens.next().getValue()));
      }
    } 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.
   */
}
项目:google-java-format    文件JavadocLexer.java   
/**
 * Adjust indentation inside `<pre>{@code` blocks.
 *
 * <p>Also trim leading and trailing blank lines,and move the trailing `}` to its own line.
 */
private static ImmutableList<Token> deindentPreCodeBlocks(List<Token> input) {
  ImmutableList.Builder<Token> output = ImmutableList.builder();
  for (PeekingIterator<Token> tokens = peekingIterator(input.iterator()); tokens.hasNext(); ) {
    if (tokens.peek().getType() != PRE_OPEN_TAG) {
      output.add(tokens.next());
      continue;
    }

    output.add(tokens.next());
    List<Token> initialNewlines = new ArrayList<>();
    while (tokens.hasNext() && tokens.peek().getType() == FORCED_NEWLINE) {
      initialNewlines.add(tokens.next());
    }
    if (tokens.peek().getType() != LIteraL
        || !tokens.peek().getValue().matches("[ \t]*[{]@code")) {
      output.addAll(initialNewlines);
      output.add(tokens.next());
      continue;
    }

    deindentPreCodeBlock(output,tokens);
  }
  return output.build();
}
项目:kylin    文件SortMergedPartitionResultIterator.java   
@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;
}
项目:scylla-tools-java    文件Bounds.java   
/**
 * 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,endBound.right));
    }

    return nonOverlappingBounds;
}
项目:scylla-tools-java    文件CounterMutation.java   
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(),cfs);
    }
}
项目:error-prone    文件AbstractExpectedExceptionChecker.java   
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);
}
项目:jg2p    文件GroupingIterable.java   
@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;
    }
  };
}
项目:glowroot    文件TraceCommonService.java   
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();
}
项目:glowroot    文件MutableProfile.java   
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);
        }
    }
}
项目:bouncestorage    文件BounceService.java   
private void processpolicy(BouncePolicy policy) {
    logger.info("processing policy {} {}",policy.getClass(),status.container);

    ListContainerOptions options = new ListContainerOptions().recursive();

    PeekingIterator<StorageMetadata> destinationIterator = Iterators.peekingIterator(
            Utils.crawlBlobStore(policy.getDestination(),container,options).iterator());
    PeekingIterator<StorageMetadata> sourceIterator = Iterators.peekingIterator(
            Utils.crawlBlobStore(policy,options).iterator());

    policy.prepareBounce(container);
    StreamSupport.stream(Spliterators.spliteratorUnkNownSize(
            new ReconcileIterator(sourceIterator,destinationIterator),Spliterator.CONCURRENT),true)
            .filter(p -> p.getRight() == null || !WriteBackPolicy.isSwiftSegmentBlob(p.getRight().getName()))
            .forEach((p) -> {
                BounceStorageMetadata sourceObject = p.getLeft();
                StorageMetadata destinationObject = p.getRight();

                reconcileObject(policy,sourceObject,destinationObject);
            });
}
项目:lsmtree    文件MergingIterator.java   
@Override
protected Generation.Entry<K,V> computeNext() {
    if (heap.isEmpty()) {
        return endOfData();
    }

    PeekingIterator<EntryAndGenerationId<K,V>> first = heap.poll();
    EntryAndGenerationId<K,V> ret = first.next();
    if (first.hasNext()) {
        temp.add(first);
    }
    while (!heap.isEmpty() && keyComparator.compare(ret.entry.getKey(),heap.peek().peek().entry.getKey()) == 0) {
        PeekingIterator<EntryAndGenerationId<K,V>> iter = heap.poll();
        iter.next();
        if (iter.hasNext()) {
            temp.add(iter);
        }
    }
    heap.addAll(temp);
    temp.clear();
    return ret.entry;
}
项目:closure-stylesheets    文件FixupFontDeclarations.java   
/**
 * Computes the suffix of {@code xs} starting at the first node for which
 * {@code p} fails.
 *
 * {@code Iterables.concat(takeWhile(xs,p),dropWhile(xs,p)) = xs}
 */
private <T> Iterable<T> dropWhile(
    final Iterable<T> xs,final Predicate<? super T> p) {
  return new Iterable<T>() {
    @Override
    public Iterator<T> iterator() {
      PeekingIterator<T> xsi = Iterators.peekingIterator(xs.iterator());
      while (xsi.hasNext()) {
        if (p.apply(xsi.peek())) {
          break;
        }
        xsi.next();
      }
      return xsi;
    }
  };
}
项目:OpenModsLib    文件Evaluator.java   
private static List<String> parseMacroArgList(PeekingIterator<Token> tokens) {
    final Token firstToken = expectTokens(tokens,TokenType.SYMBOL,TokenType.RIGHT_BRACKET);

    final List<String> args = Lists.newArrayList();
    if (firstToken.type == TokenType.RIGHT_BRACKET) {
        Preconditions.checkState(firstToken.value.equals(")"),"Unexpected bracket: '%s'",firstToken.value);
        return args;
    }

    args.add(firstToken.value);

    while (true) {
        final Token token = expectTokens(tokens,TokenType.SEParaTOR,TokenType.RIGHT_BRACKET);
        if (token.type == TokenType.RIGHT_BRACKET) {
            Preconditions.checkState(token.value.equals(")"),token.value);
            break;
        }

        final String arg = expectToken(tokens,TokenType.SYMBOL);
        args.add(arg);
    }
    return args;
}
项目:OpenModsLib    文件EvaluatorFactory.java   
@Override
public IModifierStateTransition<Node> getStateForModifier(String modifier) {
    if (MODIFIER_OP.equals(modifier)) {
        return new SingleStateTransition.ForModifier<Node>() {

            @Override
            public Node createRootNode(Node child) {
                return child;
            }

            @Override
            public Node parseSymbol(IParserState<Node> state,PeekingIterator<Token> input) {
                Preconditions.checkState(input.hasNext(),"Unexpected end out input");
                final Token token = input.next();
                Preconditions.checkState(token.type == TokenType.OPERATOR,"Unexpected token,expected operator,got %s",token);
                NodeOp operator = OPERATORS.getoperator(token.value,OperatorArity.BINARY);
                if (operator == null) operator = OPERATORS.getoperator(token.value,OperatorArity.UNARY);
                if (operator == null) throw new IllegalArgumentException("UnkNown operator: " + token.value);
                return new Node(operator);
            }

        };
    } else {
        throw new UnsupportedOperationException("Modifier: " + modifier);
    }
}
项目:sstable-adaptor    文件LegacyLayout.java   
private static Row getNextRow(CellGrouper grouper,PeekingIterator<? extends LegacyAtom> cells)
{
    if (!cells.hasNext())
        return null;

    grouper.reset();
    while (cells.hasNext() && grouper.addAtom(cells.peek()))
    {
        // We've added the cell already in the grouper,so just skip it
        cells.next();
    }
    return grouper.getRow();
}
项目:sstable-adaptor    文件LegacyLayout.java   
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);
        }
    };
}
项目:tg-eventstore    文件ReorderingEventReader.java   
@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);
    }
}
项目:tg-eventstore    文件ReorderingEventReader.java   
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,false);

        return concat(concat(reorderedEvents,eventInTheGap).map(EventWithSortKey::toResolvedEvent),remainingEvents).onClose(allForwards::close);
    }
}
项目:tg-eventstore    文件EventShovel.java   
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();
                }
            };
        }
    };
}
项目:tg-eventstore    文件EventStoreMergingIterator.java   
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;
}
项目:javaide    文件JavaInputAstVisitor.java   
/**
 * 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;
}
项目:javaide    文件JavadocLexer.java   
/**
 * 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.
 */
}
项目:Elasticsearch    文件PlainSortedMergeIterator.java   
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);
    }
项目:incubator-omid    文件CompactorScanner.java   
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();
    }
}
项目:wav2pzx    文件PZXpulseBlock.java   
/**
    * 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);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。