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.errorprone.bugpatterns.ExpectedExceptionChecker.java

@Override
protected Description handleMatch(MethodTree tree, VisitorState state, List<Tree> expectations,
        List<StatementTree> suffix) {
    if (suffix.size() <= 1) {
        // for now, allow ExpectedException as long as it's testing that exactly one statement throws
        return NO_MATCH;
    }/* w ww .ja  v  a  2  s .co  m*/
    BaseFix baseFix = buildBaseFix(state, expectations);
    // provide fixes to wrap each of the trailing statements in a lambda
    // skip statements that look like assertions
    List<Fix> fixes = Lists.reverse(suffix).stream().filter(t -> !JUnitMatchers.containsTestMethod(t))
            .map(t -> baseFix.build(ImmutableList.of(t))).collect(toImmutableList());
    if (fixes.isEmpty()) {
        fixes.add(baseFix.build(ImmutableList.of(getLast(suffix))));
    }
    return buildDescription(tree).addAllFixes(fixes).build();
}

From source file:com.palantir.typescript.text.ContentFormatter.java

@Override
public void format(IDocument document, IRegion region) {
    int start = region.getOffset();
    int end = start + region.getLength();
    FormatCodeOptions options = createFormatCodeOptions();
    List<TextChange> edits = this.editor.getLanguageService().getFormattingEditsForRange(start, end, options);

    // apply the edits
    try {//from  www  .ja  v  a2 s  .  c o  m
        for (TextChange edit : Lists.reverse(edits)) {
            TextSpan span = edit.getSpan();
            String newText = edit.getNewText();

            document.replace(span.getStart(), span.getLength(), newText);
        }
    } catch (BadLocationException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.github.arven.sleuth.WatchedInterpreter.java

public WatchedInterpreter(Interpreter in, InputStream is, OutputStream os) {
    this.in = in;
    this.is = new BufferedReader(new InputStreamReader(is));
    this.os = new PrintStream(os);
    this.in.setOut(this.os);
    this.history = new ArrayList<String>();
    this.historyReverse = Lists.reverse(this.history);
    this.map = new ObjectMapper();
}

From source file:org.fcrepo.kernel.identifiers.ExternalIdentifierConverter.java

/**
 * We fold the list of translators once in each direction and store the
 * resulting calculation.//from   w ww.  j  ava 2  s. co m
 */
@PostConstruct
public void accumulateTranslations() {
    for (final InternalIdentifierConverter t : translationChain) {
        forward = forward.andThen(t);
    }
    for (final InternalIdentifierConverter t : Lists.reverse(translationChain)) {
        reverse = reverse.andThen(t.reverse());
    }
}

From source file:org.eclipse.xtext.scoping.impl.ResourceSetGlobalScopeProvider.java

@Override
protected IScope getScope(Resource resource, boolean ignoreCase, EClass type,
        Predicate<IEObjectDescription> filter) {
    IScope parent = IScope.NULLSCOPE;//w ww .  jav a2  s  .  c  o m
    if (resource == null || resource.getResourceSet() == null)
        return parent;
    final ResourceSet resourceSet = resource.getResourceSet();
    if (resourceSet instanceof ResourceSetReferencingResourceSet) {
        ResourceSetReferencingResourceSet set = (ResourceSetReferencingResourceSet) resourceSet;
        Iterable<ResourceSet> referencedSets = Lists.reverse(set.getReferencedResourceSets());
        for (ResourceSet referencedSet : referencedSets) {
            parent = createScopeWithQualifiedNames(parent, resource, filter, referencedSet, type, ignoreCase);
        }
    }
    return createScopeWithQualifiedNames(parent, resource, filter, resourceSet, type, ignoreCase);
}

From source file:co.cask.cdap.explore.executor.AbstractExploreQueryExecutorHttpHandler.java

protected List<QueryInfo> filterQueries(List<QueryInfo> queries, final long offset, final boolean isForward,
        final int limit) {
    // Reverse the list if the pagination is in the reverse from the offset until the max limit
    if (!isForward) {
        queries = Lists.reverse(queries);
    }/*from  w w  w .  j  a  va  2 s .  c  om*/

    return FluentIterable.from(queries).filter(new Predicate<QueryInfo>() {
        @Override
        public boolean apply(QueryInfo queryInfo) {
            if (isForward) {
                return queryInfo.getTimestamp() < offset;
            } else {
                return queryInfo.getTimestamp() > offset;
            }
        }
    }).limit(limit).toSortedImmutableList(new Comparator<QueryInfo>() {
        @Override
        public int compare(QueryInfo first, QueryInfo second) {
            //sort descending.
            return Longs.compare(second.getTimestamp(), first.getTimestamp());
        }
    });
}

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

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

From source file:org.auraframework.impl.css.ThemeListImpl.java

@Override
public Optional<Object> getValue(String name) throws QuickFixException {
    for (DefDescriptor<ThemeDef> theme : Lists.reverse(themes)) {
        ThemeDef def = theme.getDef();/*from   w ww.  ja v a  2 s  .c o  m*/

        Optional<Object> value = def.getVar(name);
        if (value.isPresent()) {
            return value;
        }

        if (def.getMapProvider() != null) {
            value = Optional.<Object>fromNullable(dynamicVars.get(name, theme));
        }
        if (value.isPresent()) {
            return value;
        }
    }

    return Optional.absent();
}

From source file:da.RequestJpaController.java

public List<Request> getRequestsByResolver(String username, int status, int type) {
    TypedQuery<Request> query = getEntityManager().createQuery(
            "SELECT r FROM Request r WHERE r.resolveAccount.username = :username AND r.type=:type AND r.status=:status ORDER BY r.time DESC",
            Request.class);
    query.setParameter("username", username);
    query.setParameter("type", type);
    query.setParameter("status", status);
    return Lists.reverse(query.getResultList());
}

From source file:org.apache.flume.tools.DirectMemoryUtils.java

public static long getDirectMemorySize() {
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    List<String> arguments = Lists.reverse(RuntimemxBean.getInputArguments());
    long multiplier = 1; //for the byte case.
    for (String s : arguments) {
        if (s.contains(MAX_DIRECT_MEMORY_PARAM)) {
            String memSize = s.toLowerCase().replace(MAX_DIRECT_MEMORY_PARAM.toLowerCase(), "").trim();

            if (memSize.contains("k")) {
                multiplier = 1024;//from  w w  w. j  a  va2 s. com
            } else if (memSize.contains("m")) {
                multiplier = 1048576;
            } else if (memSize.contains("g")) {
                multiplier = 1073741824;
            }
            memSize = memSize.replaceAll("[^\\d]", "");
            long retValue = Long.parseLong(memSize);
            return retValue * multiplier;
        }
    }
    return DEFAULT_SIZE;
}