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.opendaylight.controller.configpusherfeature.internal.FeatureConfigSnapshotHolder.java

public ImmutableList<Feature> getFeatureChain() {
    return ImmutableList.copyOf(Lists.reverse(featureChain));
}

From source file:org.jetbrains.kotlin.codegen.inline.InternalFinallyBlockInliner.java

private void processInlineFunFinallyBlocks() {
    int nextTempNonLocalVarIndex = initAndGetVarIndexForNonLocalReturnValue();

    InsnList instructions = inlineFun.instructions;

    //As we do finally block code search after non-local return instruction
    // we should be sure that all others non-local returns already processed in this finally block.
    // So we do instruction processing in reverse order!
    AbstractInsnNode curIns = instructions.getLast();
    while (curIns != null) {
        processInstruction(curIns, false);

        //At this point only global return is possible, local one already substituted with: goto endLabel
        if (!InlineCodegenUtil.isReturnOpcode(curIns.getOpcode())
                || !InlineCodegenUtil.isMarkedReturn(curIns)) {
            curIns = curIns.getPrevious();
            continue;
        }/*  ww  w.ja va  2 s.com*/

        List<TryCatchBlockNodeInfo> currentCoveringNodesFromInnermost = sortTryCatchBlocks(
                new ArrayList<TryCatchBlockNodeInfo>(getTryBlocksMetaInfo().getCurrentIntervals()));
        checkCoveringBlocksInvariant(Lists.reverse(currentCoveringNodesFromInnermost));

        if (currentCoveringNodesFromInnermost.isEmpty() || currentCoveringNodesFromInnermost
                .get(currentCoveringNodesFromInnermost.size() - 1).getOnlyCopyNotProcess()) {
            curIns = curIns.getPrevious();
            continue;
        }

        AbstractInsnNode markedReturn = curIns;
        AbstractInsnNode instrInsertFinallyBefore = markedReturn.getPrevious();
        AbstractInsnNode nextPrev = instrInsertFinallyBefore.getPrevious();
        assert markedReturn.getNext() instanceof LabelNode : "Label should be occurred after non-local return";
        LabelNode newFinallyEnd = (LabelNode) markedReturn.getNext();
        Type nonLocalReturnType = InlineCodegenUtil.getReturnType(markedReturn.getOpcode());

        //Generally there could be several tryCatch blocks (group) on one code interval (same start and end labels, but maybe different handlers) -
        // all of them refer to one try/*catches*/finally or try/catches.
        // Each group that corresponds to try/*catches*/finally contains tryCatch block with default handler.
        // For each such group we should insert corresponding finally before non-local return.
        // So we split all try blocks on current instructions to groups and process them independently
        List<TryBlockCluster<TryCatchBlockNodeInfo>> clustersFromInnermost = TryBlockClusteringKt
                .doClustering(currentCoveringNodesFromInnermost);
        Iterator<TryBlockCluster<TryCatchBlockNodeInfo>> tryCatchBlockIterator = clustersFromInnermost
                .iterator();

        checkClusterInvariant(clustersFromInnermost);

        int originalDepthIndex = 0;

        while (tryCatchBlockIterator.hasNext()) {
            TryBlockCluster<TryCatchBlockNodeInfo> clusterToFindFinally = tryCatchBlockIterator.next();
            List<TryCatchBlockNodeInfo> clusterBlocks = clusterToFindFinally.getBlocks();
            TryCatchBlockNodeInfo nodeWithDefaultHandlerIfExists = clusterBlocks.get(clusterBlocks.size() - 1);

            FinallyBlockInfo finallyInfo = findFinallyBlockBody(nodeWithDefaultHandlerIfExists,
                    getTryBlocksMetaInfo().getAllIntervals());
            if (finallyInfo == null)
                continue;

            if (nodeWithDefaultHandlerIfExists.getOnlyCopyNotProcess()) {
                //lambdas finally generated before non-local return instruction,
                //so it's a gap in try/catch handlers
                throw new RuntimeException("Lambda try blocks should be skipped");
            }

            originalDepthIndex++;

            instructions.resetLabels();

            List<TryCatchBlockNodePosition> tryCatchBlockInlinedInFinally = findTryCatchBlocksInlinedInFinally(
                    finallyInfo);

            //Creating temp node for finally block copy with some additional instruction
            MethodNode finallyBlockCopy = createEmptyMethodNode();
            Label newFinallyStart = new Label();
            Label insertedBlockEnd = new Label();

            boolean generateAloadAstore = nonLocalReturnType != Type.VOID_TYPE && !finallyInfo.isEmpty();
            if (generateAloadAstore) {
                finallyBlockCopy.visitVarInsn(nonLocalReturnType.getOpcode(Opcodes.ISTORE),
                        nextTempNonLocalVarIndex);
            }
            finallyBlockCopy.visitLabel(newFinallyStart);

            //Keep some information about label nodes, we need it to understand whether it's jump inside finally block or outside
            // in first case we do call VISIT on instruction otherwise recreating jump instruction (see below)
            Set<LabelNode> labelsInsideFinally = rememberOriginalLabelNodes(finallyInfo);
            //Writing finally block body to temporary node
            AbstractInsnNode currentIns = finallyInfo.startIns;
            while (currentIns != finallyInfo.endInsExclusive) {
                boolean isInsOrJumpInsideFinally = !(currentIns instanceof JumpInsnNode)
                        || labelsInsideFinally.contains(((JumpInsnNode) currentIns).label);

                copyInstruction(finallyBlockCopy, currentIns, isInsOrJumpInsideFinally, originalDepthIndex);

                currentIns = currentIns.getNext();
            }

            if (generateAloadAstore) {
                finallyBlockCopy.visitVarInsn(nonLocalReturnType.getOpcode(Opcodes.ILOAD),
                        nextTempNonLocalVarIndex);
                nextTempNonLocalVarIndex += nonLocalReturnType.getSize(); //TODO: do more wise indexing
            }

            finallyBlockCopy.visitLabel(insertedBlockEnd);

            //Copying finally body before non-local return instruction
            InlineCodegenUtil.insertNodeBefore(finallyBlockCopy, inlineFun, instrInsertFinallyBefore);

            updateExceptionTable(clusterBlocks, newFinallyStart, newFinallyEnd, tryCatchBlockInlinedInFinally,
                    labelsInsideFinally, (LabelNode) insertedBlockEnd.info);
        }

        //skip just inserted finally
        curIns = markedReturn.getPrevious();
        while (curIns != null && curIns != nextPrev) {
            processInstruction(curIns, false);
            curIns = curIns.getPrevious();
        }

        //finally block inserted so we need split update localVarTable in lambda
        if (instrInsertFinallyBefore.getPrevious() != nextPrev && curIns != null) {
            LabelNode startNode = new LabelNode();
            LabelNode endNode = new LabelNode();
            instructions.insert(curIns, startNode);
            //TODO: note that on return expression we have no variables
            instructions.insert(markedReturn, endNode);
            getLocalVarsMetaInfo().splitCurrentIntervals(new SimpleInterval(startNode, endNode), true);
        }
    }

    substituteTryBlockNodes(inlineFun);
    substituteLocalVarTable(inlineFun);
}

From source file:org.eclipse.emf.eson.ui.editor.tree.URIBasedPropertySource.java

private void completedChange(final Object propertyId) {
    Lists.reverse(ongoingChanges).remove(propertyId);
}

From source file:de.se_rwth.langeditor.util.antlr.ParseTrees.java

public static ImmutableList<ParseTree> bottomUpAncestors(ParseTree parseTree) {
    return ImmutableList
            .copyOf(Iterables.filter(Lists.reverse(Trees.getAncestors(parseTree)), ParseTree.class));
}

From source file:com.google.gerrit.server.change.Submit.java

/**
 * If the merge was attempted and it failed the system usually writes a
 * comment as a ChangeMessage and sets status to NEW. Find the relevant
 * message and return it./*from  ww w  .j  a v a  2s  .  c  o  m*/
 */
public ChangeMessage getConflictMessage(RevisionResource rsrc) throws OrmException {
    final Timestamp before = rsrc.getChange().getLastUpdatedOn();
    ChangeMessage msg = Iterables.getFirst(Iterables.filter(
            Lists.reverse(dbProvider.get().changeMessages().byChange(rsrc.getChange().getId()).toList()),
            new Predicate<ChangeMessage>() {
                @Override
                public boolean apply(ChangeMessage input) {
                    return input.getAuthor() == null && input.getWrittenOn().getTime() >= before.getTime();
                }
            }), null);
    return msg;
}

From source file:edu.udo.scaffoldhunter.model.util.Scaffolds.java

private static int[] fillMap(Map<Scaffold, List<Integer>> map, Scaffold scaffold, ConfigMapping mapping,
        final PropertyDefinition propertyDefinition, boolean cumulative) {
    int[] dist = new int[mapping.getIntervals().size()];
    { // determine Distribution for current Scaffold
        Predicate<Molecule> propertyNotNull = new Predicate<Molecule>() {
            @Override//from  w w  w.  jav  a2s  . com
            public boolean apply(Molecule input) {
                return input.getNumPropertyValue(propertyDefinition) != null;
            }
        };
        Set<Molecule> current = Sets.filter(scaffold.getMolecules(), propertyNotNull);
        int i = mapping.getIntervals().size() - 1;
        for (Interval interval : Iterables.limit(Lists.reverse(mapping.getIntervals()),
                mapping.getIntervals().size() - 1)) {
            Set<Molecule> filtered = Sets.filter(current,
                    new LesserOrEqual(propertyDefinition, interval.getLowerBound()));
            dist[i--] = current.size() - filtered.size();
            current = filtered;
        }
        dist[0] = current.size();
    }
    /*
     * determine distributions for children recursively and add them in the
     * cumulative case
     */
    for (Scaffold child : scaffold.getChildren()) {
        int[] childDistribution = fillMap(map, child, mapping, propertyDefinition, cumulative);
        if (cumulative) {
            for (int i = 0; i < dist.length; ++i)
                dist[i] += childDistribution[i];
        }
    }
    map.put(scaffold, Ints.asList(dist));
    return dist;
}

From source file:brooklyn.entity.network.bind.BindDnsServerImpl.java

@Override
protected void preStart() {
    String reverse = getConfig(REVERSE_LOOKUP_NETWORK);
    if (Strings.isBlank(reverse))
        reverse = getAttribute(ADDRESS);
    setAttribute(REVERSE_LOOKUP_CIDR, new Cidr(reverse + "/24"));
    String reverseLookupDomain = Joiner.on('.')
            .join(Iterables.skip(Lists.reverse(Lists.newArrayList(Splitter.on('.').split(reverse))), 1))
            + ".in-addr.arpa";
    setAttribute(REVERSE_LOOKUP_DOMAIN, reverseLookupDomain);

    addPolicy(PolicySpec.create(MemberTrackingPolicy.class).displayName("Address tracker")
            .configure(AbstractMembershipTrackingPolicy.SENSORS_TO_TRACK,
                    ImmutableSet.<Sensor<?>>of(getConfig(HOSTNAME_SENSOR)))
            .configure(AbstractMembershipTrackingPolicy.GROUP, getEntities()));
}

From source file:org.apache.druid.segment.incremental.IncrementalIndexStorageAdapter.java

@Override
public Sequence<Cursor> makeCursors(@Nullable final Filter filter, final Interval interval,
        final VirtualColumns virtualColumns, final Granularity gran, final boolean descending,
        @Nullable QueryMetrics<?> queryMetrics) {
    if (index.isEmpty()) {
        return Sequences.empty();
    }/*from  w w w .ja  va2  s .  c  o m*/

    final Interval dataInterval = new Interval(getMinTime(), gran.bucketEnd(getMaxTime()));

    if (!interval.overlaps(dataInterval)) {
        return Sequences.empty();
    }
    final Interval actualInterval = interval.overlap(dataInterval);
    Iterable<Interval> intervals = gran.getIterable(actualInterval);
    if (descending) {
        intervals = Lists.reverse(ImmutableList.copyOf(intervals));
    }

    return Sequences.simple(intervals)
            .map(i -> new IncrementalIndexCursor(virtualColumns, descending, filter, i, actualInterval, gran));
}

From source file:org.apache.druid.query.aggregation.AggregatorUtil.java

/**
 * returns the list of dependent postAggregators that should be calculated in order to calculate given postAgg
 *
 * @param postAggregatorList List of postAggregator, there is a restriction that the list should be in an order such
 *                           that all the dependencies of any given aggregator should occur before that aggregator.
 *                           See AggregatorUtilTest.testOutOfOrderPruneDependentPostAgg for example.
 * @param postAggName        name of the postAgg on which dependency is to be calculated
 *
 * @return the list of dependent postAggregators
 *//* ww  w . j  a  v a2 s  . com*/
public static List<PostAggregator> pruneDependentPostAgg(List<PostAggregator> postAggregatorList,
        String postAggName) {
    ArrayList<PostAggregator> rv = new ArrayList<>();
    Set<String> deps = new HashSet<>();
    deps.add(postAggName);
    // Iterate backwards to find the last calculated aggregate and add dependent aggregator as we find dependencies
    // in reverse order
    for (PostAggregator agg : Lists.reverse(postAggregatorList)) {
        if (deps.contains(agg.getName())) {
            rv.add(agg); // add to the beginning of List
            deps.remove(agg.getName());
            deps.addAll(agg.getDependentFields());
        }
    }

    Collections.reverse(rv);
    return rv;
}

From source file:com.puppetlabs.geppetto.ruby.jrubyparser.RubyCallFinder.java

public List<GenericCallNode> findCalls(Node root, String... qualifiedName) {
    if (qualifiedName.length < 1)
        throw new IllegalArgumentException("qualifiedName can not be empty");

    this.stack = Lists.newLinkedList();
    this.nameStack = Lists.newLinkedList();

    // NOTE: opportunity to make this better if guava a.k.a google.collect
    // 2.0 is used
    // since it has a Lists.reverse method - now this ugly construct is
    // used.//from w w  w  . j a  va2  s .c o m
    this.qualifiedName = Lists.reverse(Lists.newArrayList(qualifiedName));

    // TODO: make this return more than one
    return findCallInternal(root, false);
}