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.googlejavaformat.java.JavacTokens.java

/** Lex the input and return a list of {@link RawTok}s. */
public static ImmutableList<RawTok> getTokens(String source, Context context, Set<TokenKind> stopTokens) {
    if (source == null) {
        return ImmutableList.of();
    }/*from w  w w.  jav  a2s.  c o m*/
    ScannerFactory fac = ScannerFactory.instance(context);
    char[] buffer = (source + EOF_COMMENT).toCharArray();
    Scanner scanner = new AccessibleScanner(fac, new CommentSavingTokenizer(fac, buffer, buffer.length));
    ImmutableList.Builder<RawTok> tokens = ImmutableList.builder();
    int end = source.length();
    int last = 0;
    do {
        scanner.nextToken();
        Token t = scanner.token();
        if (t.comments != null) {
            for (Comment c : Lists.reverse(t.comments)) {
                if (last < c.getSourcePos(0)) {
                    tokens.add(new RawTok(null, null, last, c.getSourcePos(0)));
                }
                tokens.add(new RawTok(null, null, c.getSourcePos(0), c.getSourcePos(0) + c.getText().length()));
                last = c.getSourcePos(0) + c.getText().length();
            }
        }
        if (stopTokens.contains(t.kind)) {
            if (t.kind != TokenKind.EOF) {
                end = t.pos;
            }
            break;
        }
        if (last < t.pos) {
            tokens.add(new RawTok(null, null, last, t.pos));
        }
        tokens.add(new RawTok(t.kind == TokenKind.STRINGLITERAL ? "\"" + t.stringVal() + "\"" : null, t.kind,
                t.pos, t.endPos));
        last = t.endPos;
    } while (scanner.token().kind != TokenKind.EOF);
    if (last < end) {
        tokens.add(new RawTok(null, null, last, end));
    }
    return tokens.build();
}

From source file:c1c.v8fs.Attributes.java

@Override
public void readFromBuffer(ByteBuffer buffer) {
    byte[] buf = new byte[8];
    buffer.get(buf);/*from w  w w  .  j  ava2 s  .  c  om*/
    buf = Bytes.toArray(Lists.reverse(Bytes.asList(buf)));
    creationDate = decodeDateTime(buf);
    buffer.get(buf);
    buf = Bytes.toArray(Lists.reverse(Bytes.asList(buf)));
    modifyDate = decodeDateTime(buf);
    reserved = UnsignedInteger.fromIntBits(buffer.getInt()).longValue();
    name = "";
    boolean skip = false;
    while (buffer.hasRemaining()) {
        char ch = (char) buffer.get();
        if (!skip) {
            name += ch;
        }
        skip = !skip;
    }
    name = name.replaceAll("[\\x00-\\x1F]", "");
}

From source file:org.optaplanner.core.impl.heuristic.move.CompositeMove.java

public CompositeMove createUndoMove(ScoreDirector scoreDirector) {
    List<Move> undoMoveList = new ArrayList<Move>(moveList.size());
    for (Move move : moveList) {
        // Note: this undoMove creation doesn't have the effect yet of a previous move in the moveList
        Move undoMove = move.createUndoMove(scoreDirector);
        undoMoveList.add(undoMove);/*from w ww .  j a  v  a  2 s  .  com*/
    }
    return new CompositeMove(Lists.reverse(undoMoveList));
}

From source file:org.sonar.java.checks.SwitchCaseWithoutBreakCheck.java

@Override
public void visitSwitchStatement(SwitchStatementTree switchStatement) {
    switchStatement.cases().stream()/*from ww  w.java  2  s .  com*/
            // Exclude the last case as stated in RSPEC. This also excludes switches with no or a single case group.
            .limit(Math.max(0, switchStatement.cases().size() - 1)).forEach(caseGroup -> {
                // Assign issues to the last label in the group
                CaseLabelTree caseLabel = caseGroup.labels().get(caseGroup.labels().size() - 1);

                // Reverse the body as commonly the unconditional exit will be at the end of the body.
                if (Lists.reverse(caseGroup.body()).stream()
                        .noneMatch(SwitchCaseWithoutBreakCheck::isUnconditionalExit)) {
                    context.reportIssue(this, caseLabel,
                            "End this switch case with an unconditional break, return or throw statement.");
                }
            });

    super.visitSwitchStatement(switchStatement);
}

From source file:org.apache.james.jmap.utils.SortingHierarchicalCollections.java

public List<T> sortFromLeafToRoot(Collection<T> elements) throws CycleDetectedException {
    return Lists.reverse(sortFromRootToLeaf(elements));
}

From source file:com.google.idea.blaze.base.experiments.ExperimentServiceImpl.java

@Override
public synchronized void reloadExperiments() {
    if (experimentScopeCounter.get() > 0) {
        return;/*from  w w w  .  j a  v a  2 s  .  co  m*/
    }

    Map<String, String> experiments = Maps.newHashMap();
    for (ExperimentLoader loader : Lists.reverse(services)) {
        experiments.putAll(loader.getExperiments());
    }
    this.experiments = experiments;
}

From source file:org.apache.drill.exec.physical.PhysicalPlan.java

public List<PhysicalOperator> getSortedOperators(boolean reverse) {
    List<PhysicalOperator> list = GraphAlgos.TopoSorter.sort(graph);
    if (reverse) {
        return Lists.reverse(list);
    } else {//from  w  w w .  j  a v  a 2 s  . c o  m
        return list;
    }

}

From source file:org.springframework.xd.dirt.rest.DocumentParseResultResourceAssembler.java

@Override
public DocumentParseResultResource toResource(DocumentParseResult entity) {
    DocumentParseResultResource resource = new DocumentParseResultResource();
    for (DocumentParseResult.Line line : entity) {
        DocumentParseResultResource.Line resourceLine = new DocumentParseResultResource.Line();

        // Add any exceptions to the response for this line
        if (line.getExceptions() != null) {

            for (Exception e : line.getExceptions()) {

                if (e instanceof StreamDefinitionException) {
                    StreamDefinitionException sde = (StreamDefinitionException) e;
                    resourceLine.addError(
                            new DocumentParseResultResource.Error(sde.getMessage(), sde.getPosition()));
                } else {
                    resourceLine.addError(new DocumentParseResultResource.Error(e.getMessage()));
                }/*ww w. j  a v  a2 s. co  m*/
            }
        }
        // If any modules were parsed, include that in the response
        if (line.getDescriptors() != null) {
            for (ModuleDescriptor md : Lists.reverse(line.getDescriptors())) {
                resourceLine.addDescriptor(new DocumentParseResultResource.ModuleDescriptor(md.getGroup(),
                        md.getModuleLabel(), RESTModuleType.valueOf(md.getType().name()), md.getModuleName(),
                        md.getSourceChannelName(), md.getSinkChannelName(), md.getParameters()));
            }
        }
        resource.addLine(resourceLine);
    }
    return resource;
}

From source file:org.onosproject.event.ListenerTracker.java

/**
 * Removes all listeners in reverse order they have been registered.
 *//*from   w  ww  .ja  va2  s . c  o m*/
public void removeListeners() {
    Lists.reverse(listeners).forEach(r -> r.getLeft().removeListener(r.getRight()));
    listeners.clear();
}

From source file:org.apache.james.AggregateJunitExtension.java

@Override
public void afterEach(ExtensionContext extensionContext) {
    Runnables.runParallel(Flux.fromIterable(Lists.reverse(registrableExtensions))
            .map(ext -> Throwing.runnable(() -> ext.afterEach(extensionContext))));
}