Example usage for com.google.common.collect Lists reverse

List of usage examples for com.google.common.collect Lists reverse

Introduction

In this page you can find the example usage for com.google.common.collect Lists reverse.

Prototype

@CheckReturnValue
public static <T> List<T> reverse(List<T> list) 

Source Link

Document

Returns a reversed view of the specified list.

Usage

From source file:org.sonar.php.checks.ArgumentWithDefaultValueNotLastCheck.java

/**
 * <p>Return list of parameter nodes that are not declared at the end.</p>
 * <p/>/*  w ww.  j  ava  2  s.  c  om*/
 * Example: $p2 will be returned.
 * <pre>function f($p1, $p2 = 1, $p3, $p4 = 4) {...}</pre>
 */
private static List<ParameterTree> getParametersToMove(ParameterListTree parameterList) {
    List<ParameterTree> parametersToMove = Lists.newArrayList();
    boolean metParamWithoutDefault = false;

    for (ParameterTree param : Lists.reverse(parameterList.parameters())) {
        boolean hasDefault = param.initValue() != null;

        if (!hasDefault && !metParamWithoutDefault) {
            metParamWithoutDefault = true;
        } else if (hasDefault && metParamWithoutDefault) {
            parametersToMove.add(param);
        }
    }

    return Lists.reverse(parametersToMove);
}

From source file:com.salesforce.grpc.contrib.interceptor.AggregateClientInterceptor.java

@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method,
        CallOptions callOptions, Channel next) {
    // reverse the interceptors list so that the last interceptor to call is the most nested interceptor
    for (ClientInterceptor interceptor : Lists.reverse(interceptors)) {
        next = new InterceptorChannel(next, interceptor);
    }//w w w  .  j a  va 2  s. c  om

    return next.newCall(method, callOptions);
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.layout.SequenceGraphicalHelper.java

/**
 * Finds and returns the EventEnd which corresponds to the first event
 * graphically above the specified Y coordinate in a diagram.
 * /*from   w  ww. j  a v a2 s.c  o  m*/
 * @param diagram
 *            the diagram.
 * @param y
 *            the Y coordinate (in logical space)
 * @return the EventEnd which corresponds to the first event above Y.
 */
public static EventEnd getEndBefore(SequenceDDiagram diagram, int y) {
    VerticalPositionFunction vpf = new VerticalPositionFunction(diagram);
    for (EventEnd end : Lists.reverse(diagram.getGraphicalOrdering().getEventEnds())) {
        int pos = vpf.apply(end);
        if (pos != VerticalPositionFunction.INVALID_POSITION && pos <= y) {
            return end;
        }
    }
    return null;
}

From source file:com.salesforce.grpc.contrib.interceptor.AggregateServerInterceptor.java

@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers,
        ServerCallHandler<ReqT, RespT> next) {
    // reverse the interceptors list so that the last interceptor to call is the most nested interceptor
    for (ServerInterceptor interceptor : Lists.reverse(interceptors)) {
        next = new InterceptorServerCallHandler<>(next, interceptor);
    }//from  w w  w .  j a  v a  2 s .com

    return next.startCall(call, headers);
}

From source file:de.marx_labs.utilities.common.searchtree.MapSearchTree.java

@Override
public Set<T> newest(int size) {
    // SortedMap<Long, T> matchMap = this.tailMap(lastKey(), true);

    Long key = lastKey();/*  w  w w. j av a 2  s. co m*/
    Set<T> matches = new LinkedHashSet<T>();
    for (int i = 0; i < size; i++) {
        matches.add(get(key));
        key = lowerKey(key);

        if (key == null) {
            break;
        }
    }

    List<T> reverseList = Lists.reverse(Lists.newArrayList(matches));

    return Sets.newLinkedHashSet(reverseList);
    // return matches;
}

From source file:com.twitter.graphjet.demo.TopNodes.java

/**
 * Returns the top <i>k</i> nodes encountered by this heap.
 *
 * @return the top <i>k</i> nodes encountered by this heap.
 *//*from   www  . ja  va  2  s. c  o m*/
public List<NodeValueEntry> getNodes() {
    NodeValueEntry e;
    final List<NodeValueEntry> entries = new ArrayList<>(queue.size());
    while ((e = queue.poll()) != null) {
        entries.add(e);
    }

    return Lists.reverse(entries);
}

From source file:org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultVisitedArtifactResults.java

@Override
public SelectedArtifactResults select(Spec<? super ComponentIdentifier> componentFilter,
        VariantSelector selector) {// ww  w .  jav  a2 s . c  o  m
    if (artifactsById.isEmpty()) {
        return NoArtifactResults.INSTANCE;
    }

    List<ResolvedArtifactSet> resolvedArtifactSets = new ArrayList<ResolvedArtifactSet>(artifactsById.size());
    for (ArtifactSet artifactSet : artifactsById) {
        ResolvedArtifactSet resolvedArtifacts = artifactSet.select(componentFilter, selector);
        resolvedArtifactSets.add(resolvedArtifacts);
    }

    if (sortOrder == ResolutionStrategy.SortOrder.DEPENDENCY_FIRST) {
        resolvedArtifactSets = Lists.reverse(resolvedArtifactSets);
    }

    ResolvedArtifactSet composite = CompositeResolvedArtifactSet.of(resolvedArtifactSets);
    return new DefaultSelectedArtifactResults(sortOrder, composite, resolvedArtifactSets);
}

From source file:ninja.lifecycle.LifecycleRegister.java

public void stop() {
    if (!started.get()) {
        throw new FailedDisposeException("Ninja service is not started!");
    }//  ww w  . java  2 s.com
    List<Target> toDispose = new ArrayList<Target>(this.disposables);
    started.set(false);
    disposables.clear();
    // Sort the beans to dispose
    Collections.sort(toDispose);
    for (Target target : Lists.reverse(toDispose)) {
        try {
            invokeTarget(target);
        } catch (Exception e) {
            log.warn("Error stopping service", e);
        }
    }
}

From source file:com.google.currysrc.processors.BaseJavadocTagClasses.java

@Override
public final void process(Context context, CompilationUnit cu) {
    final List<AbstractTypeDeclaration> toHide = Lists.newArrayList();
    cu.accept(new ASTVisitor() {
        @Override//from   www .j  av  a2s .  co  m
        public boolean visit(TypeDeclaration node) {
            return visitAbstract(node);
        }

        @Override
        public boolean visit(EnumDeclaration node) {
            return visitAbstract(node);
        }

        private boolean visitAbstract(AbstractTypeDeclaration node) {
            if (mustTag(node)) {
                toHide.add(node);
            }
            return false;
        }
    });
    ASTRewrite rewrite = context.rewrite();
    for (AbstractTypeDeclaration node : Lists.reverse(toHide)) {
        JavadocUtils.addJavadocTag(rewrite, node, tagText);
    }
}

From source file:com.android.icu4j.srcgen.TagMatchingDeclarations.java

@Override
public void process(Context context, CompilationUnit cu) {
    List<BodyDeclaration> matchingNodes = Lists.newArrayList();
    // This is inefficient but it is very simple.
    for (BodyDeclarationLocator locator : locatorList) {
        BodyDeclaration bodyDeclaration = locator.find(cu);
        if (bodyDeclaration != null) {
            matchingNodes.add(bodyDeclaration);
        }//from   www. j a v  a  2 s .  c  o m
    }
    // Tackle nodes in reverse order to avoid messing up the ASTNode offsets.
    Collections.sort(matchingNodes, new StartPositionComparator());
    ASTRewrite rewrite = context.rewrite();
    for (BodyDeclaration bodyDeclaration : Lists.reverse(matchingNodes)) {
        JavadocUtils.addJavadocTag(rewrite, bodyDeclaration, tagComment);
    }
}