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


Java PeekingIterator.peek方法代碼示例

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


在下文中一共展示了PeekingIterator.peek方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例2: 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

示例3: 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

示例4: getPZXBlockDiskRepresentation

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
    * 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);
}
 
開發者ID:fmeunier,項目名稱:wav2pzx,代碼行數:34,代碼來源:PZXPulseBlock.java

示例5: getPilotBlock

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private TapeBlock getPilotBlock(PulseList thisBlockPulses, PeekingIterator<Optional<Pair<BlockType, PulseList>>> iterator) {
    // For unknown, check the next block for being a pilot if it is a one pulse pilot candidate to merge with this
    // block as the data block processor can leave an additional block prior to the main pilot block that has some
    // of the associated pilot pulses
    PulseList newBlockPulses = thisBlockPulses;
    Optional<Pair<BlockType, PulseList>> nextPair = iterator.hasNext() ? iterator.peek() : empty();
    if (thisBlockPulses.getPulseLengths().size() == 1 &&
            isaPilotCandidate(thisBlockPulses.getPulseLengths().get(0)) &&
            nextPair.isPresent() && nextPair.get().getKey() == BlockType.PILOT) {
        iterator.next();
        newBlockPulses = new PulseList(thisBlockPulses, nextPair.get().getValue());
    }
    return processPulseBlock(newBlockPulses);
}
 
開發者ID:fmeunier,項目名稱:wav2pzx,代碼行數:15,代碼來源:TapeBlockListBuilder.java

示例6: gatherAndSend

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
 * Gather {@link MonitoredItemNotification}s and send them using {@code service}, if present.
 *
 * @param iterator a {@link PeekingIterator} over the current {@link BaseMonitoredItem}s.
 * @param service  a {@link ServiceRequest}, if available.
 */
private void gatherAndSend(PeekingIterator<BaseMonitoredItem<?>> iterator,
                           Optional<ServiceRequest<PublishRequest, PublishResponse>> service) {

    if (service.isPresent()) {
        List<UaStructure> notifications = Lists.newArrayList();

        while (notifications.size() < maxNotificationsPerPublish && iterator.hasNext()) {
            BaseMonitoredItem<?> item = iterator.peek();

            boolean gatheredAllForItem = gather(item, notifications, maxNotificationsPerPublish);

            if (gatheredAllForItem && iterator.hasNext()) {
                iterator.next();
            }
        }

        moreNotifications = iterator.hasNext();

        sendNotifications(service.get(), notifications);

        if (moreNotifications) {
            gatherAndSend(iterator, Optional.ofNullable(publishQueue().poll()));
        }
    } else {
        if (moreNotifications) {
            publishQueue().addSubscription(this);
        }
    }
}
 
開發者ID:eclipse,項目名稱:milo,代碼行數:36,代碼來源:Subscription.java

示例7: streamingIterator

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private static <T> Iterator<T> streamingIterator(Iterator<T> iterator) {
    // Force the calculation of at least the first item in the iterator so that, if an exception occurs, we find
    // out before writing the HTTP response code & headers.  Otherwise we will at best report a 500 error instead
    // of applying Jersey exception mappings and maybe returning a 400 error etc.
    PeekingIterator<T> peekingIterator = Iterators.peekingIterator(iterator);
    if (peekingIterator.hasNext()) {
        peekingIterator.peek();
    }

    return new LoggingIterator<>(peekingIterator, _log);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:12,代碼來源:BlobStoreResource1.java

示例8: streamingIterator

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private static <T> Iterator<T> streamingIterator(Iterator<T> iterator, BooleanParam debug) {
    // If debugging, sort the individual json objects so they're easier to understand in a browser
    iterator = optionallyOrdered(iterator, debug);

    // Force the calculation of at least the first item in the iterator so that, if an exception occurs, we find
    // out before writing the HTTP response code & headers.  Otherwise we will at best report a 500 error instead
    // of applying Jersey exception mappings and maybe returning a 400 error etc.
    PeekingIterator<T> peekingIterator = Iterators.peekingIterator(iterator);
    if (peekingIterator.hasNext()) {
        peekingIterator.peek();
    }

    return new LoggingIterator<>(peekingIterator, _log);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:15,代碼來源:DataStoreResource1.java

示例9: streamingIterator

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private static <T> Iterator<T> streamingIterator(InputStream in, TypeReference<T> typeReference) {
    PeekingIterator<T> iter = new JsonStreamingArrayParser<>(in, typeReference);

    // Fetch the first element in the result stream immediately, while still wrapped by the Ostrich retry logic.
    // If we can't get the first element then Ostrich should retry immediately.  If we fail to get subsequent
    // elements then clients must catch JsonStreamingEOFException and deal with it themselves.  They are highly
    // encouraged to use the DataStoreStreaming class which handles the restart logic automatically.
    if (iter.hasNext()) {
        iter.peek();
    }

    return iter;
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:14,代碼來源:EntityHelper.java

示例10: collectLeafsWithSameOffset

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private LinkedList<ILeafNode> collectLeafsWithSameOffset(ILeafNode candidate, PeekingIterator<ILeafNode> iterator) {
	LinkedList<ILeafNode> sameOffset = Lists.newLinkedList();
	sameOffset.add(candidate);
	int offset = candidate.getTotalOffset();
	while(iterator.hasNext()) {
		ILeafNode peek = iterator.peek();
		if (peek.getTotalOffset() == offset) {
			sameOffset.add(peek);
			iterator.next();
		} else {
			break;
		}
	}
	return sameOffset;
}
 
開發者ID:eclipse,項目名稱:xtext-core,代碼行數:16,代碼來源:IndentationAwareCompletionPrefixProvider.java

示例11: getFullRecursionKeysIterator

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
@SuppressWarnings("GuardedBy")
private Iterator<FDate> getFullRecursionKeysIterator(final FDate from) {
    final Iterator<FDate> iterator = newFullRecursionKeysIterator(from);
    if (iterator == null) {
        firstRecursionKey = null;
        return null;
    }
    final PeekingIterator<FDate> peekingIterator = Iterators.peekingIterator(iterator);
    try {
        firstRecursionKey = peekingIterator.peek();
        final TimeRange timeRange = new TimeRange(firstRecursionKey, from);
        if (timeRange.getDuration().intValue(FTimeUnit.YEARS) > 1) {
            largeRecalculationsCount++;
            if (largeRecalculationsCount % LARGE_RECALCULATION_WARNING_THRESHOLD == 0) {
                //CHECKSTYLE:OFF
                LOG.warn(
                        "{}: Recalculating recursively for the {}. time over more than a year [{}]. If this happens too often this might have a negative impact on performance.",
                        parent, timeRange, largeRecalculationsCount);
                //CHECKSTYLE:ON
            }
        }
        return peekingIterator;
    } catch (final NoSuchElementException e) {
        firstRecursionKey = null;
        return null;
    }
}
 
開發者ID:subes,項目名稱:invesdwin-util,代碼行數:28,代碼來源:ARecursiveHistoricalCacheQuery.java

示例12: stripLeadingConstants

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
public static <T> List<LocalProperty<T>> stripLeadingConstants(List<? extends LocalProperty<T>> properties)
{
    PeekingIterator<? extends LocalProperty<T>> iterator = peekingIterator(properties.iterator());
    while (iterator.hasNext() && iterator.peek() instanceof ConstantProperty) {
        iterator.next();
    }
    return ImmutableList.copyOf(iterator);
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:9,代碼來源:LocalProperties.java

示例13: extractLeadingConstants

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
public static <T> Set<T> extractLeadingConstants(List<? extends LocalProperty<T>> properties)
{
    ImmutableSet.Builder<T> builder = ImmutableSet.builder();
    PeekingIterator<? extends LocalProperty<T>> iterator = peekingIterator(properties.iterator());
    while (iterator.hasNext() && iterator.peek() instanceof ConstantProperty) {
        builder.add(((ConstantProperty<T>) iterator.next()).getColumn());
    }
    return builder.build();
}
 
開發者ID:y-lan,項目名稱:presto,代碼行數:10,代碼來源:LocalProperties.java

示例14: fetchNextIterator

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
private void fetchNextIterator() {
    Iterator<T> it = nextIterator();
    if (it != null && it.hasNext()) {
        PeekingIterator<T> pIt = Iterators.peekingIterator(it);
        if (!iterators.isEmpty()
                &&  comparator.compare(pIt.peek(), lastPeek) < 0) {
            throw new IllegalStateException(description() + " First element of next iterator must be greater than previous iterator");
        }
        lastPeek = pIt.peek();
        iterators.add(pIt);
        adjustLast();
    }
}
 
開發者ID:denismo,項目名稱:jackrabbit-dynamodb-store,代碼行數:14,代碼來源:MergeSortedIterators.java

示例15: mergeSorted

import com.google.common.collect.PeekingIterator; //導入方法依賴的package包/類
/**
 * Merges already-sorted sections, reading only two values into memory
 * at a time.
 */
public final void mergeSorted() {
    List<SectionIterator> iters = new ArrayList<SectionIterator>();
    for (Dex d : dexs) {
        iters.add(new SectionIterator(d, indexMaps.get(d)));
    }
    getSection(contentsOut).off = out.getPosition();

    int outCount = 0;

    PeekingIterator<UnsortedValue> sorted = Iterators.peekingIterator(
        Iterators.mergeSorted(iters, Ordering.natural()));
    while (sorted.hasNext()) {
        UnsortedValue uValue = sorted.peek();
        // Consume all equivalent values, but only write one.
        // We use .compareTo() == 0 instead of .equals() because some of the value
        // types don't implement .equals().
        while (sorted.hasNext() && uValue.value.compareTo(sorted.peek().value) == 0) {
            uValue = sorted.next();
            updateIndex(uValue.offset, uValue.indexMap, uValue.index, outCount);
        }
        write(uValue.value);
        outCount++;
    }

    getSection(contentsOut).size = outCount;
}
 
開發者ID:saleehk,項目名稱:buck-cutom,代碼行數:31,代碼來源:DexMerger.java


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