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:com.google.template.soy.parsepasses.RewriteGenderMsgsVisitor.java

@Override
protected void visitMsgNode(MsgNode msg) {

    List<ExprRootNode> genderExprs = msg.getAndRemoveGenderExprs();
    if (genderExprs == null) {
        return; // not a msg that this pass should rewrite
    }//from  www.j  a  v  a  2 s  . c o m

    // Check that 'genders' attribute and 'select' command are not used together.
    if (msg.getChild(0) instanceof MsgSelectNode) {
        errorReporter.report(msg.getChild(0).getSourceLocation(), GENDER_AND_SELECT_NOT_ALLOWED);
    }

    // If plural msg, check that there are max 2 genders.
    if (msg.getChild(0) instanceof MsgPluralNode && genderExprs.size() > 2) {
        errorReporter.report(msg.getSourceLocation(), MORE_THAN_TWO_GENDER_EXPRS);
    }

    // ------ Do the rewrite. ------

    // Note: We process the genders in reverse order so that the first listed gender will end up
    // being the outermost 'select' level.
    genderExprs = Lists.reverse(genderExprs);

    Checkpoint checkpoint = errorReporter.checkpoint();
    List<String> baseSelectVarNames = MsgSubstUnitBaseVarNameUtils.genNoncollidingBaseNamesForExprs(
            ExprRootNode.unwrap(genderExprs), FALLBACK_BASE_SELECT_VAR_NAME, errorReporter);
    if (errorReporter.errorsSince(checkpoint)) {
        return; // To prevent an IndexOutOfBoundsException below.
    }

    for (int i = 0; i < genderExprs.size(); i++) {
        ExprRootNode genderExpr = genderExprs.get(i);
        String baseSelectVarName = baseSelectVarNames.get(i);

        // Check whether the generated base name would be the same (both for the old naive algorithm
        // and the new algorithm). If so, then there's no need to specify the baseSelectVarName.
        if (MsgSubstUnitBaseVarNameUtils
                .genNaiveBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME)
                .equals(baseSelectVarName)
                && MsgSubstUnitBaseVarNameUtils
                        .genShortestBaseNameForExpr(genderExpr.getRoot(), FALLBACK_BASE_SELECT_VAR_NAME)
                        .equals(baseSelectVarName)) {
            baseSelectVarName = null;
        }

        splitMsgForGender(msg, genderExpr, baseSelectVarName);
    }
}

From source file:com.google.gerrit.server.notedb.rebuild.EventList.java

String getTag() {
    for (E e : Lists.reverse(list)) {
        if (e.tag != null) {
            return e.tag;
        }
    }
    return null;
}

From source file:org.opendaylight.yangtools.yang.data.api.StackedYangInstanceIdentifier.java

@Override
public List<PathArgument> getPathArguments() {
    StackedPathArguments ret = tryPathArguments();
    if (ret == null) {
        final List<PathArgument> stack = new ArrayList<>();
        YangInstanceIdentifier current = this;
        do {/*  w w  w  .j  av a2 s  .c o  m*/
            Verify.verify(current instanceof StackedYangInstanceIdentifier);
            final StackedYangInstanceIdentifier stacked = (StackedYangInstanceIdentifier) current;
            stack.add(stacked.getLastPathArgument());
            current = stacked.getParent();
        } while (current.tryPathArguments() == null);

        ret = new StackedPathArguments(current, Lists.reverse(stack));
        pathArguments = ret;
    }

    return ret;
}

From source file:de.monticore.codegen.mc2cd.TransformationHelper.java

public static Optional<String> getUsageName(ASTNode root, ASTNode successor) {
    List<ASTNode> intermediates = ASTNodes.getIntermediates(root, successor);
    for (ASTNode ancestor : Lists.reverse(intermediates)) {
        if (ancestor instanceof ASTConstantGroup) {
            return Optional.ofNullable(((ASTConstantGroup) ancestor).getUsageName().orElse(null));
        }/*from w w  w .j ava2s . co  m*/
        if (ancestor instanceof ASTNonTerminal) {
            return Optional.ofNullable(((ASTNonTerminal) ancestor).getUsageName().orElse(null));
        }
        if (ancestor instanceof ASTNonTerminalSeparator) {
            return Optional.ofNullable(((ASTNonTerminalSeparator) ancestor).getUsageName().orElse(null));
        }
        if (ancestor instanceof ASTTerminal) {
            return Optional.ofNullable(((ASTTerminal) ancestor).getUsageName().orElse(null));
        }
        if (ancestor instanceof ASTAttributeInAST) {
            return ((ASTAttributeInAST) ancestor).getName();
        }
    }
    return Optional.empty();
}

From source file:com.facebook.buck.cxx.UntrackedHeaderReporterWithShowIncludes.java

/**
 * @return a list of headers that represents a chain of includes ending in a particular header.
 *//*w w  w .  j  a  v a2  s  . c  o  m*/
private List<Path> getPathToUntrackedHeader(List<String> includeLines, Path header) {
    // We parse the tree structure linearly by maintaining a stack of the current active parents.
    Stack<Path> active_parents = new Stack<Path>();
    for (String line : includeLines) {
        int currentDeepLevel = countCharAtTheBeginning(line, ' ') - 1;
        Preconditions.checkState(currentDeepLevel <= active_parents.size(),
                "Error parsing dependency file for %s", prettyPrintFileName(inputPath, true));
        while (currentDeepLevel < active_parents.size()) {
            active_parents.pop();
        }
        Path currentHeader = filesystem.resolve(line.trim()).normalize();
        currentHeader = headerPathNormalizer.getAbsolutePathForUnnormalizedPath(currentHeader)
                .orElse(currentHeader);
        active_parents.push(currentHeader);
        if (currentHeader.equals(header)) {
            return Lists.reverse(active_parents);
        }
    }
    return Collections.singletonList(header);
}

From source file:org.nuxeo.runtime.test.runner.FeaturesRunner.java

/**
 * @since 5.6/* www  . j a va2s.c  o m*/
 */
public <T extends Annotation> T getConfig(Class<T> type) {
    List<T> configs = new ArrayList<>();
    T annotation = scanner.getAnnotation(getTargetTestClass(), type);
    if (annotation != null) {
        configs.add(annotation);
    }
    loader.apply(Direction.BACKWARD, new Callable() {
        @Override
        public void call(Holder holder) throws Exception {
            // TODO Auto-generated method stub

        }
    });
    for (FeaturesLoader.Holder each : Lists.reverse(loader.holders)) {
        annotation = scanner.getAnnotation(each.type, type);
        if (annotation != null) {
            configs.add(annotation);
        }
    }
    return Defaults.of(type, configs);
}

From source file:com.github.tomakehurst.wiremock.recording.Recorder.java

public SnapshotRecordResult takeSnapshot(List<ServeEvent> serveEvents, RecordSpec recordSpec) {
    final List<StubMapping> stubMappings = serveEventsToStubMappings(Lists.reverse(serveEvents),
            recordSpec.getFilters(),/*  www.  j  av  a2 s .com*/
            new SnapshotStubMappingGenerator(recordSpec.getCaptureHeaders(),
                    recordSpec.getRequestBodyPatternFactory()),
            getStubMappingPostProcessor(admin.getOptions(), recordSpec));

    for (StubMapping stubMapping : stubMappings) {
        if (recordSpec.shouldPersist()) {
            stubMapping.setPersistent(true);
        }
        admin.addStubMapping(stubMapping);
    }

    return recordSpec.getOutputFormat().format(stubMappings);
}

From source file:io.prestosql.sql.gen.SwitchCodeGenerator.java

@Override
public BytecodeNode generateExpression(Signature signature, BytecodeGeneratorContext generatorContext,
        Type returnType, List<RowExpression> arguments) {
    // TODO: compile as
    /*/* w w  w  . j  a  v  a  2  s.  c om*/
    hashCode = hashCode(<value>)
            
    // all constant expressions before a non-constant
    switch (hashCode) {
        case ...:
            if (<value> == <constant1>) {
               ...
            }
            else if (<value> == <constant2>) {
               ...
            }
            else if (...) {
            }
        case ...:
            ...
    }
            
    if (<value> == <non-constant1>) {
        ...
    }
    else if (<value> == <non-constant2>) {
        ...
    }
    ...
            
    // repeat with next sequence of constant expressions
     */

    Scope scope = generatorContext.getScope();

    // process value, else, and all when clauses
    RowExpression value = arguments.get(0);
    BytecodeNode valueBytecode = generatorContext.generate(value);
    BytecodeNode elseValue;

    List<RowExpression> whenClauses;
    RowExpression last = arguments.get(arguments.size() - 1);
    if (last instanceof CallExpression && ((CallExpression) last).getSignature().getName().equals("WHEN")) {
        whenClauses = arguments.subList(1, arguments.size());
        elseValue = new BytecodeBlock().append(generatorContext.wasNull().set(constantTrue()))
                .pushJavaDefault(returnType.getJavaType());
    } else {
        whenClauses = arguments.subList(1, arguments.size() - 1);
        elseValue = generatorContext.generate(last);
    }

    // determine the type of the value and result
    Class<?> valueType = value.getType().getJavaType();

    // evaluate the value and store it in a variable
    LabelNode nullValue = new LabelNode("nullCondition");
    Variable tempVariable = scope.createTempVariable(valueType);
    BytecodeBlock block = new BytecodeBlock().append(valueBytecode)
            .append(BytecodeUtils.ifWasNullClearPopAndGoto(scope, nullValue, void.class, valueType))
            .putVariable(tempVariable);

    BytecodeNode getTempVariableNode = VariableInstruction.loadVariable(tempVariable);

    // build the statements
    elseValue = new BytecodeBlock().visitLabel(nullValue).append(elseValue);
    // reverse list because current if statement builder doesn't support if/else so we need to build the if statements bottom up
    for (RowExpression clause : Lists.reverse(whenClauses)) {
        Preconditions.checkArgument(clause instanceof CallExpression
                && ((CallExpression) clause).getSignature().getName().equals("WHEN"));

        RowExpression operand = ((CallExpression) clause).getArguments().get(0);
        RowExpression result = ((CallExpression) clause).getArguments().get(1);

        // call equals(value, operand)
        Signature equalsFunction = generatorContext.getRegistry().resolveOperator(OperatorType.EQUAL,
                ImmutableList.of(value.getType(), operand.getType()));

        // TODO: what if operand is null? It seems that the call will return "null" (which is cleared below)
        // and the code only does the right thing because the value in the stack for that scenario is
        // Java's default for boolean == false
        // This code should probably be checking for wasNull after the call and "failing" the equality
        // check if wasNull is true
        BytecodeNode equalsCall = generatorContext.generateCall(equalsFunction.getName(),
                generatorContext.getRegistry().getScalarFunctionImplementation(equalsFunction),
                ImmutableList.of(generatorContext.generate(operand), getTempVariableNode));

        BytecodeBlock condition = new BytecodeBlock().append(equalsCall)
                .append(generatorContext.wasNull().set(constantFalse()));

        elseValue = new IfStatement("when").condition(condition).ifTrue(generatorContext.generate(result))
                .ifFalse(elseValue);
    }

    return block.append(elseValue);
}

From source file:org.testfx.service.finder.impl.WindowFinderImpl.java

@SuppressWarnings("deprecation")
private List<Window> fetchWindowsInQueue() {
    List<Window> windows = Lists.newArrayList(Window.impl_getWindows());
    return ImmutableList.copyOf(Lists.reverse(windows));
}

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

@Override
public synchronized void close() {
    for (final AutoCloseable reg : Lists.reverse(salRegistrations)) {
        closeGracefully(reg);/*from  w  ww.  j  av  a  2 s .  c  o m*/
    }
    closeGracefully(salProvider);
}