Example usage for com.google.common.collect Streams findLast

List of usage examples for com.google.common.collect Streams findLast

Introduction

In this page you can find the example usage for com.google.common.collect Streams findLast.

Prototype

public static OptionalDouble findLast(DoubleStream stream) 

Source Link

Document

Returns the last element of the specified stream, or OptionalDouble#empty if the stream is empty.

Usage

From source file:com.google.errorprone.bugpatterns.argumentselectiondefects.NamedParameterComment.java

/**
 * Determine the kind of match we have between the comments on this argument and the formal
 * parameter name.//from   w w w .j av a 2  s  .co  m
 */
static MatchType match(Commented<ExpressionTree> actual, String formal) {
    Optional<Comment> lastBlockComment = Streams
            .findLast(actual.beforeComments().stream().filter(c -> c.getStyle() == CommentStyle.BLOCK));

    if (lastBlockComment.isPresent()) {
        Matcher m = PARAMETER_COMMENT_PATTERN.matcher(Comments.getTextFromComment(lastBlockComment.get()));
        if (m.matches()) {
            return m.group(1).equals(formal) ? MatchType.EXACT_MATCH : MatchType.BAD_MATCH;
        }
    }

    if (Stream.concat(actual.beforeComments().stream(), actual.afterComments().stream())
            .map(Comments::getTextFromComment)
            .anyMatch(comment -> Arrays.asList(comment.split("[^a-zA-Z0-9_]+")).contains(formal))) {
        return MatchType.APPROXIMATE_MATCH;
    }

    return MatchType.NOT_ANNOTATED;
}

From source file:com.google.errorprone.bugpatterns.android.WakelockReleasedDangerously.java

private ClassTree getTopLevelClass(VisitorState state) {
    return (ClassTree) Streams
            .findLast(Streams.stream(state.getPath().iterator()).filter((Tree t) -> t.getKind() == Kind.CLASS))
            .orElseThrow(() -> new IllegalArgumentException("No enclosing class found"));
}

From source file:com.google.errorprone.bugpatterns.LambdaFunctionalInterface.java

private static ClassTree getTopLevelClassTree(VisitorState state) {
    return (ClassTree) Streams
            .findLast(Streams.stream(state.getPath().iterator()).filter((Tree t) -> t.getKind() == Kind.CLASS))
            .orElseThrow(() -> new IllegalArgumentException("No enclosing class found"));
}