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


Java Iterators.peekingIterator方法代碼示例

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


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

示例1: getNonOverlappingBounds

import com.google.common.collect.Iterators; //導入方法依賴的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.Iterators; //導入方法依賴的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: readAllForwards

import com.google.common.collect.Iterators; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:14,代碼來源:ReorderingEventReader.java

示例4: bufferedAndSortedReadAllForwards

import com.google.common.collect.Iterators; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:tim-group,項目名稱:tg-eventstore,代碼行數:36,代碼來源:ReorderingEventReader.java

示例5: Structurizer

import com.google.common.collect.Iterators; //導入方法依賴的package包/類
Structurizer(Iterable<Term> terms) {
	this.terms = Iterators.peekingIterator(Iterators.filter(terms.iterator(), whitespaces));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:Structurizer.java

示例6: visitForLoop

import com.google.common.collect.Iterators; //導入方法依賴的package包/類
@Override
public Void visitForLoop(ForLoopTree node, Void unused) {
    sync(node);
    token("for");
    builder.space();
    token("(");
    builder.open(plusFour);
    builder.open(
            node.getInitializer().size() > 1
                    && node.getInitializer().get(0).getKind() == Tree.Kind.EXPRESSION_STATEMENT
                    ? plusFour
                    : ZERO);
    if (!node.getInitializer().isEmpty()) {
        if (node.getInitializer().get(0).getKind() == VARIABLE) {
            PeekingIterator<StatementTree> it =
                    Iterators.<StatementTree>peekingIterator(node.getInitializer().iterator());
            visitVariables(
                    variableFragments(it, it.next()), DeclarationKind.NONE, Direction.HORIZONTAL);
        } else {
            boolean first = true;
            builder.open(ZERO);
            for (StatementTree t : node.getInitializer()) {
                if (!first) {
                    token(",");
                    builder.breakOp(" ");
                }
                scan(((ExpressionStatementTree) t).getExpression(), null);
                first = false;
            }
            token(";");
            builder.close();
        }
    } else {
        token(";");
    }
    builder.close();
    builder.breakOp(" ");
    if (node.getCondition() != null) {
        scan(node.getCondition(), null);
    }
    token(";");
    if (!node.getUpdate().isEmpty()) {
        builder.breakOp(" ");
        builder.open(node.getUpdate().size() <= 1 ? ZERO : plusFour);
        boolean firstUpdater = true;
        for (ExpressionStatementTree updater : node.getUpdate()) {
            if (!firstUpdater) {
                token(",");
                builder.breakToFill(" ");
            }
            scan(updater.getExpression(), null);
            firstUpdater = false;
        }
        builder.guessToken(";");
        builder.close();
    } else {
        builder.space();
    }
    builder.close();
    token(")");
    visitStatement(
            node.getStatement(),
            CollapseEmptyOrNot.YES,
            AllowLeadingBlankLine.YES,
            AllowTrailingBlankLine.NO);
    return null;
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:68,代碼來源:JavaInputAstVisitor.java

示例7: addBodyDeclarations

import com.google.common.collect.Iterators; //導入方法依賴的package包/類
/**
 * Add a list of declarations.
 */
void addBodyDeclarations(
        List<? extends Tree> bodyDeclarations, BracesOrNot braces, FirstDeclarationsOrNot first0) {
    if (bodyDeclarations.isEmpty()) {
        if (braces.isYes()) {
            builder.space();
            tokenBreakTrailingComment("{", plusTwo);
            builder.blankLineWanted(BlankLineWanted.NO);
            builder.open(ZERO);
            token("}", plusTwo);
            builder.close();
        }
    } else {
        if (braces.isYes()) {
            builder.space();
            tokenBreakTrailingComment("{", plusTwo);
            builder.open(ZERO);
        }
        builder.open(plusTwo);
        boolean first = first0.isYes();
        boolean lastOneGotBlankLineBefore = false;
        PeekingIterator<Tree> it = Iterators.<Tree>peekingIterator(bodyDeclarations.iterator());
        while (it.hasNext()) {
            Tree bodyDeclaration = it.next();
            dropEmptyDeclarations();
            builder.forcedBreak();
            boolean thisOneGetsBlankLineBefore =
                    bodyDeclaration.getKind() != VARIABLE || hasJavaDoc(bodyDeclaration);
            if (first) {
                builder.blankLineWanted(PRESERVE);
            } else if (!first && (thisOneGetsBlankLineBefore || lastOneGotBlankLineBefore)) {
                builder.blankLineWanted(YES);
            }
            markForPartialFormat();

            if (bodyDeclaration.getKind() == VARIABLE) {
                visitVariables(
                        variableFragments(it, bodyDeclaration),
                        DeclarationKind.FIELD,
                        fieldAnnotationDirection(((VariableTree) bodyDeclaration).getModifiers()));
            } else {
                scan(bodyDeclaration, null);
            }
            first = false;
            lastOneGotBlankLineBefore = thisOneGetsBlankLineBefore;
        }
        dropEmptyDeclarations();
        builder.forcedBreak();
        builder.close();
        builder.forcedBreak();
        markForPartialFormat();
        if (braces.isYes()) {
            builder.blankLineWanted(BlankLineWanted.NO);
            token("}", plusTwo);
            builder.close();
        }
    }
}
 
開發者ID:tranleduy2000,項目名稱:javaide,代碼行數:61,代碼來源:JavaInputAstVisitor.java


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