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.java.ast.AstScanner.java

private void parseErrorWalkAndVisit(RecognitionException e, File file) {
    try {//w  w  w .  ja v  a2 s.co m
        // Process the exception
        for (SquidAstVisitor<? extends Grammar> visitor : visitors) {
            visitor.visitFile(null);
        }

        for (AstScannerExceptionHandler astScannerExceptionHandler : astScannerExceptionHandlers) {
            astScannerExceptionHandler.processRecognitionException(e);
        }

        for (SquidAstVisitor<? extends Grammar> visitor : Lists.reverse(visitors)) {
            visitor.leaveFile(null);
        }

    } catch (Exception e2) {
        throw new AnalysisException(getAnalyisExceptionMessage(file), e2);
    }
}

From source file:io.prestosql.metadata.MetadataUtil.java

public static QualifiedObjectName createQualifiedObjectName(Session session, Node node, QualifiedName name) {
    requireNonNull(session, "session is null");
    requireNonNull(name, "name is null");
    if (name.getParts().size() > 3) {
        throw new PrestoException(SYNTAX_ERROR, format("Too many dots in table name: %s", name));
    }//from  www. j  av a2s .  c om

    List<String> parts = Lists.reverse(name.getParts());
    String objectName = parts.get(0);
    String schemaName = (parts.size() > 1) ? parts.get(1)
            : session.getSchema().orElseThrow(() -> new SemanticException(SCHEMA_NOT_SPECIFIED, node,
                    "Schema must be specified when session schema is not set"));
    String catalogName = (parts.size() > 2) ? parts.get(2)
            : session.getCatalog().orElseThrow(() -> new SemanticException(CATALOG_NOT_SPECIFIED, node,
                    "Catalog must be specified when session catalog is not set"));

    return new QualifiedObjectName(catalogName, schemaName, objectName);
}

From source file:edu.buaa.satla.analysis.core.arg.ErrorPathShrinker.java

/** The function shrinkErrorPath gets an targetPath and creates a new Path,
 * with only the important edges of the Path.
 *
 * @param pTargetPath the "long" targetPath
 * @return errorPath the "short" errorPath */
public List<CFAEdge> shrinkErrorPath(ARGPath pTargetPath) {
    List<CFAEdge> targetPath = getEdgesUntilTarget(pTargetPath);

    // create reverse iterator, from lastNode to firstNode
    final Iterator<CFAEdge> revIterator = Lists.reverse(targetPath).iterator();

    // Set for storing the important variables
    importantVars = new HashSet<>();

    // the short Path, the result
    final Deque<CFAEdge> shortErrorPath = new ArrayDeque<>();

    /* if the ErrorNode is inside of a function, the long path (pTargetPath) is not handled
     * until the StartNode, but only until the functionCall.
     * so update the sets of variables and call the PathHandler again until
     * the longPath is completely handled.*/
    while (revIterator.hasNext()) {
        handleEdge(revIterator.next(), shortErrorPath);
    }//from ww  w .  jav  a  2  s  . co m

    // TODO assertion disabled, until we can track all pointers completely
    // assert importantVars.isEmpty() : "some variables are never declared: " + importantVars;

    return ImmutableList.copyOf(shortErrorPath);
}

From source file:kmworks.dsltools.rrd.SVGRenderingVisitor.java

public void renderSequence(RRSequence that, RenderingParams params) {
    final Point origin = params.getOrigin();
    List<ElementNode> children = params.isReverseSequence() ? Lists.reverse(that.getChildren())
            : that.getChildren();/*w  w w.  ja  v  a  2 s  . c  om*/
    Point contOrigin = move(origin, new Point(RRSequence.INDENT, 0));
    Point childOrigin = origin;
    int maxChunkHeight = 0;

    for (ElementNode child : children) {
        child.accept(this, params.copyOf().setOrigin(childOrigin));
        if (child.getHeight() > maxChunkHeight) {
            maxChunkHeight = child.getHeight();
        }
        if (that.isTopLevel()) {
            if (child.getAttribute("linebreakAfter") != null) {
                final Point contExit = move(childOrigin, child.getExit());
                r.drawArrowRight(contExit.x + 4, contExit.y);
                r.drawLine(contExit.x, contExit.y, 4 + contExit.x, contExit.y);
                contOrigin = move(contOrigin, new Point(0, maxChunkHeight));
                final Point contEnter = move(contOrigin, child.getEnter()); // eigentlich schon nextChild
                r.drawArrowRight(contEnter.x, contEnter.y);
                childOrigin = contOrigin;
                maxChunkHeight = 0;
            } else {
                childOrigin = move(childOrigin, child.nextHorOrigin());
            }
        } else {
            childOrigin = move(childOrigin, child.nextHorOrigin());
        }
    }
}

From source file:alexiil.node.core.NodeGraph.java

/** Pushes the requests up the list of nodes from bottom up. Returns something? Does it even need to? */
private void propagateOutputRequests() {
    int i = nodes.size();
    for (INode node : Lists.reverse(nodes)) {
        System.out.println("Request START " + --i);
        node.askForElements();//from ww  w . j a va 2s. c o m
        for (GraphConnection<?> conn : node.getInputs().values()) {
            if (conn.getRequestedElements() > 0) {
                GraphConnection<?> out = conn.connectedOutput;
                int max = out.getRequestedElements();
                for (GraphConnection<?> conn2 : out.connectedInputs) {
                    max = Math.max(max, conn2.getRequestedElements());
                }
                out.requestUpTo(max);
            }
        }
    }
}

From source file:net.sf.qualitytest.blueprint.configuration.ImmutableBlueprintConfiguration.java

@Nullable
@Override//from w  w w.  j a v a2s .c o  m
@Throws(IllegalNullArgumentException.class)
public CreationStrategy<?> findCreationStrategyForMethod(@Nonnull final Method method) {
    Check.notNull(method, "method");

    for (final StrategyPair entry : Lists.reverse(mapping)) {
        if (entry.getKey().matchesByMethod(method)) {
            return entry.getValue();
        }
    }

    return null;
}

From source file:org.opendaylight.controller.sal.connect.netconf.NetconfDeviceTwoPhaseCommitTransaction.java

private CompositeNode createEditStructure(InstanceIdentifier dataPath, Optional<String> operation,
        Optional<CompositeNode> lastChildOverride) {
    List<PathArgument> path = dataPath.getPath();
    List<PathArgument> reversed = Lists.reverse(path);
    CompositeNode previous = null;// ww w .j a  v a 2s . co  m
    boolean isLast = true;
    for (PathArgument arg : reversed) {
        CompositeNodeBuilder<ImmutableCompositeNode> builder = ImmutableCompositeNode.builder();
        builder.setQName(arg.getNodeType());
        Map<QName, Object> predicates = Collections.emptyMap();
        if (arg instanceof NodeIdentifierWithPredicates) {
            predicates = ((NodeIdentifierWithPredicates) arg).getKeyValues();
        }
        for (Entry<QName, Object> entry : predicates.entrySet()) {
            builder.addLeaf(entry.getKey(), entry.getValue());
        }

        if (isLast) {
            if (operation.isPresent()) {
                builder.setAttribute(NETCONF_OPERATION_QNAME, operation.get());
            }
            if (lastChildOverride.isPresent()) {
                List<Node<?>> children = lastChildOverride.get().getChildren();
                for (Node<?> child : children) {
                    if (!predicates.containsKey(child.getKey())) {
                        builder.add(child);
                    }
                }

            }
        } else {
            builder.add(previous);
        }
        previous = builder.toInstance();
        isLast = false;
    }
    return ImmutableCompositeNode.create(NETCONF_CONFIG_QNAME, ImmutableList.<Node<?>>of(previous));
}

From source file:io.crate.planner.node.PlanNodeStreamerVisitor.java

@Override
public Void visitCollectNode(CollectNode node, Context context) {
    // get aggregations, if any
    List<Aggregation> aggregations = ImmutableList.of();
    List<Projection> projections = Lists.reverse(node.projections());
    for (Projection projection : projections) {
        if (projection.projectionType() == ProjectionType.AGGREGATION) {
            aggregations = ((AggregationProjection) projection).aggregations();
            break;
        } else if (projection.projectionType() == ProjectionType.GROUP) {
            aggregations = ((GroupProjection) projection).values();
            break;
        }//from  w  w  w .j  av  a 2  s . co m
    }

    int aggIdx = 0;
    Aggregation aggregation;
    for (DataType outputType : node.outputTypes()) {
        if (outputType == null || outputType == UndefinedType.INSTANCE) {
            // get streamer for aggregation result
            try {
                aggregation = aggregations.get(aggIdx);
                if (aggregation != null) {
                    context.outputStreamers.add(
                            resolveStreamer(aggregation, aggregation.toStep(), context.ramAccountingContext));
                }
            } catch (IndexOutOfBoundsException e) {
                // assume this is an unknown column
                context.outputStreamers.add(UndefinedType.INSTANCE.streamer());
            }
            aggIdx++;
        } else {
            // get streamer for outputType
            context.outputStreamers.add(outputType.streamer());
        }
    }
    return null;
}

From source file:com.huawei.streaming.cql.semanticanalyzer.parser.context.ArithmeticStarExpressionContext.java

/**
 * binary?/*from   ww  w  .j  a  v a 2  s .  com*/
 *  logicExpressionAnd (KW_OR logicExpressionAnd)*
 * ???
 * @return
 * @throws SemanticAnalyzerException 
 */
private ExpressionDescribe createBinaryExpression(List<Schema> schemas) throws SemanticAnalyzerException {
    //??
    //????????????
    Iterator<String> operatorIterator = Lists.reverse(operator).iterator();
    if (!operatorIterator.hasNext()) {
        return null;
    }

    BinaryExpression bexp = BinaryExpressionRegistry.getBinaryExpressionByName(operatorIterator.next());
    BinaryExpressionDesc bexpdesc = new BinaryExpressionDesc(bexp);

    List<BaseExpressionParseContext> rightArguments = Lists.newLinkedList();
    rightArguments.addAll(fieldExpressions);
    BaseExpressionParseContext rightArgument = rightArguments.remove(rightArguments.size() - 1);

    bexpdesc.getArgExpressions().add(createBinaryExpressionDesc(rightArguments, schemas, operatorIterator));
    bexpdesc.getArgExpressions().add(rightArgument.createExpressionDesc(schemas));
    return bexpdesc;
}

From source file:org.sonar.javascript.checks.DeadStoreCheck.java

private void checkBlock(BlockLiveness blockLiveness, Usages usages) {
    Set<Symbol> live = blockLiveness.liveOut;

    for (Tree element : Lists.reverse(blockLiveness.block.elements())) {
        Usage usage = blockLiveness.usageByElement.get(element);

        if (isWrite(usage)) {

            Symbol symbol = symbol(usage);
            if (!live.contains(symbol) && !usages.hasUsagesInNestedFunctions(symbol)
                    && !usages.isNeverRead(symbol)) {
                addIssue(element, symbol);
            }/*from   www . j  a  v a 2 s . co m*/
            live.remove(symbol);

        } else if (isRead(usage)) {
            live.add(symbol(usage));
        }
    }
}