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.bimserver.plugins.MavenPluginLocation.java

public Iterator<MavenPluginVersion> iterateAllVersions() {
    Artifact artifact = new DefaultArtifact(groupId, artifactId, null, "[0,)");

    VersionRangeRequest rangeRequest = new VersionRangeRequest();
    rangeRequest.setArtifact(artifact);//from   ww  w.j  a  v a 2 s  .c  om
    rangeRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList());

    try {
        VersionRangeResult rangeResult = mavenPluginRepository.getSystem()
                .resolveVersionRange(mavenPluginRepository.getSession(), rangeRequest);
        List<Version> versions = rangeResult.getVersions();
        if (!versions.isEmpty()) {
            Iterator<Version> versionIterator = Lists.reverse(versions).iterator();
            return Iterators.transform(versionIterator, new Function<Version, MavenPluginVersion>() {
                @Override
                public MavenPluginVersion apply(Version version) {
                    try {
                        MavenPluginVersion mavenPluginVersion = createMavenVersion(version);
                        return mavenPluginVersion;
                    } catch (ArtifactDescriptorException | ArtifactResolutionException | IOException
                            | XmlPullParserException e) {
                        LOGGER.error("", e);
                    }
                    return null;
                }
            });
        }
    } catch (VersionRangeResolutionException e) {
        LOGGER.error("", e);
    }

    return Collections.emptyIterator();
}

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

/**
 * Create a path in the ARG from root to the given element.
 * If there are several such paths, one is chosen randomly.
 *
 * @param pLastElement The last element in the path.
 * @return A path from root to lastElement.
 *//*  w  w w . ja  va2s.  co  m*/
public static ARGPath getOnePathTo(ARGState pLastElement) {
    List<ARGState> states = new ArrayList<>(); // reversed order
    Set<ARGState> seenElements = new HashSet<>();

    // each element of the path consists of the abstract state and the outgoing
    // edge to its successor

    ARGState currentARGState = pLastElement;
    states.add(currentARGState);
    seenElements.add(currentARGState);

    while (!currentARGState.getParents().isEmpty()) {
        Iterator<ARGState> parents = currentARGState.getParents().iterator();

        ARGState parentElement = parents.next();
        while (!seenElements.add(parentElement) && parents.hasNext()) {
            // while seenElements already contained parentElement, try next parent
            parentElement = parents.next();
        }

        states.add(parentElement);

        currentARGState = parentElement;
    }
    return new ARGPath(Lists.reverse(states));
}

From source file:com.cloudbees.demo.beesshop.domain.Product.java

/**
 * @return read only
 */
@Nonnull
public ImmutableList<Comment> getComments() {
    return ImmutableList.copyOf(Lists.reverse(comments));
}

From source file:forge.screens.match.views.VLog.java

private void displayNewGameLogEntries(final GameView model) {
    final List<GameLogEntry> newLogEntries = Lists.reverse(getNewGameLogEntries(model));
    if (newLogEntries.size() > 0) {
        addNewLogEntriesToJPanel(newLogEntries);
    }//from w ww.  j  ava2s .  co  m
}

From source file:com.android.ahat.AhatSnapshot.java

/**
 * Construct an AhatSnapshot for the given perflib snapshot.
 * Ther user is responsible for calling snapshot.computeDominators before
 * calling this AhatSnapshot constructor.
 *//* ww w  . j  av  a 2 s  .c o  m*/
private AhatSnapshot(Snapshot snapshot) {
    mSnapshot = snapshot;
    mHeaps = new ArrayList<Heap>(mSnapshot.getHeaps());

    final ClassObj javaLangClass = mSnapshot.findClass("java.lang.Class");
    for (Heap heap : mHeaps) {
        // Use a single element array for the total to act as a reference to a
        // long.
        final long[] total = new long[] { 0 };
        TObjectProcedure<Instance> processInstance = new TObjectProcedure<Instance>() {
            @Override
            public boolean execute(Instance inst) {
                Instance dominator = inst.getImmediateDominator();
                if (dominator != null) {
                    total[0] += inst.getSize();

                    if (dominator == Snapshot.SENTINEL_ROOT) {
                        mRooted.add(inst);
                    }

                    // Properly label the class of a class object.
                    if (inst instanceof ClassObj && javaLangClass != null && inst.getClassObj() == null) {
                        inst.setClassId(javaLangClass.getId());
                    }

                    // Update dominated instances.
                    List<Instance> instances = mDominated.get(dominator);
                    if (instances == null) {
                        instances = new ArrayList<Instance>();
                        mDominated.put(dominator, instances);
                    }
                    instances.add(inst);

                    // Update sites.
                    List<StackFrame> path = Collections.emptyList();
                    StackTrace stack = getStack(inst);
                    int stackId = getStackTraceSerialNumber(stack);
                    if (stack != null) {
                        StackFrame[] frames = getStackFrames(stack);
                        if (frames != null && frames.length > 0) {
                            path = Lists.reverse(Arrays.asList(frames));
                        }
                    }
                    mRootSite.add(stackId, 0, path.iterator(), inst);

                    // Update native allocations.
                    InstanceUtils.NativeAllocation alloc = InstanceUtils.getNativeAllocation(inst);
                    if (alloc != null) {
                        mNativeAllocations.add(alloc);
                    }
                }
                return true;
            }
        };
        for (Instance instance : heap.getClasses()) {
            processInstance.execute(instance);
        }
        heap.forEachInstance(processInstance);
        mHeapSizes.put(heap, total[0]);
    }

    // Record the roots and their types.
    for (RootObj root : snapshot.getGCRoots()) {
        Instance inst = root.getReferredInstance();
        Collection<RootType> types = mRoots.get(inst);
        if (types == null) {
            types = new HashSet<RootType>();
            mRoots.put(inst, types);
        }
        types.add(root.getRootType());
    }
}

From source file:org.inria.myriads.snoozecommon.communication.virtualcluster.VirtualMachineMetaData.java

/**
 * Returns the algorithm monitoring data.
 * //w w  w .  j  a  v  a  2s  .  com
 * @param numberOfMonitoringEntries   The maximum number of monitoring entries
 * @return                            The virtual machine monitoring data
 */
private LRUCache<Long, VirtualMachineMonitoringData> getMonitoringData(int numberOfMonitoringEntries) {
    Guard.check(numberOfMonitoringEntries);

    LRUCache<Long, VirtualMachineMonitoringData> result = new LRUCache<Long, VirtualMachineMonitoringData>(
            numberOfMonitoringEntries);

    // Indeed we want the n most recent values -> Reverse the list
    List<VirtualMachineMonitoringData> reverseList = Lists.reverse(Lists.newArrayList(usedCapacity_.values()));
    for (VirtualMachineMonitoringData monitoringData : reverseList) {
        VirtualMachineMonitoringData copiedEntity = new VirtualMachineMonitoringData(monitoringData);
        if (result.size() == numberOfMonitoringEntries) {
            break;
        }

        log_.debug(String.format("Copied virtual machine monitoring data. Time: %s, Used capacity: %s",
                copiedEntity.getTimeStamp(), copiedEntity.getUsedCapacity()));
        result.put(copiedEntity.getTimeStamp(), copiedEntity);
    }

    return result;
}

From source file:org.eclipse.elk.alg.layered.intermediate.wrapping.BreakingPointProcessor.java

/**
 * Main wrapping procedure, placing the determined chunks one below the other. 
 *//* w  w  w  .j  av a  2 s .c  o  m*/
private void performWrapping(final LGraph graph) {

    final List<Layer> layers = graph.getLayers();
    final ListIterator<Layer> layerIt = layers.listIterator();

    // add initial empty layer to account for break point start dummies 
    layerIt.add(new Layer(graph));

    // iterate the layers from left to right
    //  as soon as a layer with a BREAKING POINT start dummy is encountered,
    //  the nodes of the next layer should be moved to the very first layer
    //  consequently 'wrapping' the graph
    boolean reverse = false;
    int idx = 1;

    while (layerIt.hasNext()) {

        Layer layer = layerIt.next();
        Layer newLayer = layers.get(idx);
        List<LNode> nodesToMove = Lists.newArrayList(layer.getNodes());

        // remember an offset used for adding in-layer dummies later
        int offset = nodesToMove.size();

        // move the nodes to their new layer
        for (LNode n : nodesToMove) {
            n.setLayer(newLayer);
        }

        if (reverse) {
            // important to introduce the chains of long edge dummies in reversed order
            for (LNode n : Lists.reverse(nodesToMove)) {

                for (LEdge e : Lists.newArrayList(n.getIncomingEdges())) {

                    // reverse the edge
                    e.reverse(graph, true);
                    graph.setProperty(InternalProperties.CYCLIC, true);

                    // insert proper dummy nodes for the newly created long edge
                    List<LEdge> dummyEdges = CuttingUtils.insertDummies(graph, e, offset);

                    // ameliorate breaking point info
                    BPInfo bpi = n.getProperty(InternalProperties.BREAKING_POINT_INFO);
                    LEdge startInLayerEdge = dummyEdges.get(dummyEdges.size() - 1);
                    bpi.startInLayerDummy = startInLayerEdge.getSource().getNode();
                    bpi.startInLayerEdge = startInLayerEdge;
                    bpi.endInLayerDummy = e.getTarget().getNode();
                    bpi.endInLayerEdge = e;
                }
            }
            reverse = false;

        } else {
            if (!nodesToMove.isEmpty()) {
                LNode aNode = nodesToMove.get(0);
                if (aNode.getType() == NodeType.BREAKING_POINT) {
                    // next layer should be moved (it contains the breaking point end dummies)
                    reverse = true;
                    // start moving nodes to the very first layer
                    idx = -1;
                }
            }
        }

        idx++;
    }

    // remove old layers that are now empty
    ListIterator<Layer> it = graph.getLayers().listIterator();
    while (it.hasNext()) {
        Layer l = it.next();
        if (l.getNodes().isEmpty()) {
            it.remove();
        }
    }
}

From source file:alluxio.master.MasterRegistry.java

/**
 * Stops all masters in reverse dependency order. If A depends on B, B is stopped before A.
 *
 * @throws IOException if an IO error occurs
 *//*w ww . j a  v  a 2 s . c  o m*/
public void stop() throws IOException {
    for (Master master : Lists.reverse(getMasters())) {
        master.stop();
    }
}

From source file:alluxio.Registry.java

/**
 * Stops all {@link Server}s in reverse dependency order. If A depends on B, B is stopped
 * before A.//from  w  w  w.  j av  a 2  s. com
 */
public void stop() throws IOException {
    for (T server : Lists.reverse(getServers())) {
        server.stop();
    }
}

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

@Nullable
@Override//ww  w .j  ava  2  s.c  o m
@Throws(IllegalNullArgumentException.class)
public CreationStrategy<?> findCreationStrategyForType(@Nonnull final Class<?> clazz) {
    Check.notNull(clazz, "clazz");

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

    return null;
}