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.eclipse.elk.layered.p4nodes.bk.BKCompactor.java

/**
 * In this step, actual coordinates are calculated for blocks and its nodes.
 * //from   w w  w  . j  a v a2  s.  com
 * <p>First, all blocks are placed, trying to avoid any crossing of the blocks. Then, the blocks are
 * shifted towards each other if there is any space for compaction.</p>
 * 
 * @param bal One of the four layouts which shall be used in this step
 */
public void horizontalCompaction(final BKAlignedLayout bal) {
    // Initialize fields with basic values, partially depending on the direction
    for (Layer layer : layeredGraph.getLayers()) {
        for (LNode node : layer.getNodes()) {
            bal.sink[node.id] = node;
            bal.shift[node.id] = bal.vdir == VDirection.UP ? Double.NEGATIVE_INFINITY
                    : Double.POSITIVE_INFINITY;
        }
    }

    // If the horizontal direction is LEFT, the layers are traversed from right to left, thus
    // a reverse iterator is needed (note that this does not change the original list of layers)
    List<Layer> layers = layeredGraph.getLayers();
    if (bal.hdir == HDirection.LEFT) {
        layers = Lists.reverse(layers);
    }

    // init threshold strategy
    threshStrategy.init(bal);
    // mark all blocks as unplaced
    Arrays.fill(bal.y, null);

    for (Layer layer : layers) {
        // As with layers, we need a reversed iterator for blocks for different directions
        List<LNode> nodes = layer.getNodes();
        if (bal.vdir == VDirection.UP) {
            nodes = Lists.reverse(nodes);
        }

        // Do an initial placement for all blocks
        for (LNode v : nodes) {
            if (bal.root[v.id].equals(v)) {
                placeBlock(v, bal);
            }
        }
    }

    // Try to compact classes by shifting them towards each other if there is space between them.
    // Other than the original algorithm we use a "class graph" here in conjunction with a longest
    // path layering based on previously calculated separations between any pair of adjacent classes.
    // This allows to have different node sizes and disconnected graphs.
    placeClasses(bal);

    // apply final coordinates
    for (Layer layer : layers) {
        for (LNode v : layer.getNodes()) {
            bal.y[v.id] = bal.y[bal.root[v.id].id];

            // If this is the root node of the block, check if the whole block can be shifted to
            // further compact the drawing (the block's non-root nodes will be processed later by
            // this loop and will thus use the updated y position calculated here)
            if (v.equals(bal.root[v.id])) {
                double sinkShift = bal.shift[bal.sink[v.id].id];

                if ((bal.vdir == VDirection.UP && sinkShift > Double.NEGATIVE_INFINITY)
                        || (bal.vdir == VDirection.DOWN && sinkShift < Double.POSITIVE_INFINITY)) {

                    bal.y[v.id] = bal.y[v.id] + sinkShift;
                }
            }
        }
    }

    // all blocks were placed, shift latecomers
    threshStrategy.postProcess();

}

From source file:com.nesscomputing.lifecycle.AbstractLifecycle.java

/**
 * Execute a lifecycle stage.// ww  w.j av  a2  s . c o  m
 */
@Override
public void execute(@Nonnull final LifecycleStage lifecycleStage) {
    List<LifecycleListener> lifecycleListeners = listeners.get(lifecycleStage);
    if (lifecycleListeners == null) {
        throw illegalStage(lifecycleStage);
    }

    log("Stage '%s' starting...", lifecycleStage.getName());

    // Reverse the order for the STOP stage, so that dependencies are torn down in reverse order.
    if (lifecycleStage.equals(LifecycleStage.STOP_STAGE)) {
        lifecycleListeners = Lists.reverse(lifecycleListeners);
    }

    for (final LifecycleListener listener : lifecycleListeners) {
        listener.onStage(lifecycleStage);
    }

    log("Stage '%s' complete.", lifecycleStage.getName());
}

From source file:com.opentable.lifecycle.AbstractLifecycle.java

/**
 * Execute a lifecycle stage.//  ww w.java  2s  . co  m
 */
@Override
public void execute(@Nonnull final LifecycleStage lifecycleStage) {
    List<LifecycleListener> lifecycleListeners = listeners.get(lifecycleStage);
    if (lifecycleListeners == null) {
        throw illegalStage(lifecycleStage);
    }

    log("Stage '{}' starting...", lifecycleStage.getName());

    // Reverse the order for the STOP stage, so that dependencies are torn down in reverse order.
    if (lifecycleStage.equals(LifecycleStage.STOP_STAGE)) {
        lifecycleListeners = Lists.reverse(lifecycleListeners);
    }

    for (final LifecycleListener listener : lifecycleListeners) {
        listener.onStage(lifecycleStage);
    }

    log("Stage '{}' complete.", lifecycleStage.getName());
}

From source file:com.torodb.core.Shutdowner.java

@SuppressWarnings("rawtypes")
private void closePrivate() {
    shuttingDown = true;// w w  w .ja  v  a 2 s. c  o m
    Lists.reverse(closeCallbacks).forEach(closeCallback -> {
        if (closeCallback != null) {
            executeCloseCallback(closeCallback);
        }
    });
}

From source file:org.obeonetwork.dsl.uml2.core.internal.services.SemanticElementsSwitch.java

/**
 * Get semantics elements./* w  w  w .  jav a2 s.  c o m*/
 * 
 * @param cur
 *            Element
 * @return Semantic elements
 */
public Collection<EObject> getSemanticElements(EObject cur) {
    semantics = Lists.newArrayList();
    doSwitch(cur);
    /*
     * We are reversing as we want the first specific before.
     */
    return Lists.reverse(semantics);
}

From source file:org.sosy_lab.cpachecker.cfa.blocks.BlockToDotWriter.java

/** This function returns a structure which contains hierarchical dependencies between blocks.
 * The returned Multimap contains the outer block (father) as key
 * and the inner blocks (children) as values for the key.
 * We assume, that for each pair of blocks the following conditions hold:
 * a block is either completely part of the other block or there is nothing common in both blocks. */
private Multimap<Block, Block> getHierarchy() {

    // sort blocks, largest blocks first
    List<Block> sortedBlocks = Lists.newArrayList(blockPartitioning.getBlocks());
    Collections.sort(sortedBlocks, new Comparator<Block>() {
        @Override/*from w w w  . j a va 2s  .c om*/
        public int compare(Block b1, Block b2) {
            return b2.getNodes().size() - b1.getNodes().size();
        }
    });

    // build hierarchy, worst case runtime O(n^2), iff mainBlock contains all other blocks 'directly'.
    final Multimap<Block, Block> hierarchy = HashMultimap.create();
    while (!sortedBlocks.isEmpty()) {
        // get smallest block and then the smallest outer block, that contains it
        Block currentBlock = sortedBlocks.remove(sortedBlocks.size() - 1); // get smallest block,
        for (Block possibleOuterBlock : Lists.reverse(sortedBlocks)) { // order is important, smallest first
            // trick: we know, iff one node is contained in outer block, all nodes must be contained. So we check only one.
            if (possibleOuterBlock.getNodes().contains(currentBlock.getNodes().iterator().next())) {
                hierarchy.put(possibleOuterBlock, currentBlock);
                break;
            }
        }
    }

    assert hierarchy.values().size() <= blockPartitioning.getBlocks().size()
            - 1 : "all blocks except mainBlock might appear at most once as child.";
    // there might also be blocks, that are not part of the hierarchy, for example unused functions.

    return hierarchy;
}

From source file:org.jboss.hal.ballroom.Pages.java

/**
 * Shows the specified main / nested page and updates the breadcrumb.
 *
 * @param id the page id//from   ww  w  . ja  v a  2  s .c  o  m
 */
public void showPage(String id) {
    if (mainId.equals(id)) {
        showMain();

    } else {
        if (pages.containsKey(id)) {
            breadcrumb.clear();
            List<Page> bottomUp = new ArrayList<>();
            Page page1 = pages.get(id);
            do {
                bottomUp.add(page1);
                page1 = pages.get(page1.parentId);
            } while (page1 != null);

            List<Page> topDown = Lists.reverse(bottomUp);
            for (Iterator<Page> iterator = topDown.iterator(); iterator.hasNext();) {
                Page page2 = iterator.next();
                breadcrumb.append(page2.parentTitle.get(), () -> {
                    if (mainId.equals(page2.parentId)) {
                        showMain();
                    } else {
                        showPage(page2.parentId);
                    }
                });
                if (!iterator.hasNext()) {
                    breadcrumb.append(page2.title.get());
                }
            }

            Elements.setVisible(mainPage, false);
            Elements.setVisible(breadcrumb.element(), true);
            pages.forEach((pageId, page3) -> Elements.setVisible(page3.element(), id.equals(pageId)));
        }
    }
}

From source file:com.google.api.codegen.configgen.transformer.DiscoConfigTransformer.java

private String getPackageName(Document model) {
    String reverseDomain = Joiner.on(".").join(Lists.reverse(Arrays.asList(model.ownerDomain().split("\\."))));
    return String.format("%s.%s.%s", reverseDomain, model.name(), model.version());
}

From source file:com.github.fge.jsonpatch.diff.LCS.java

/**
 * Return the list of common tail elements of two lists
 *
 * <p>Note that the arguments are NOT altered. Elements are returned in
 * their order of appearance.</p>/*from  w  w  w  .  j  a  v  a  2 s .  c om*/
 *
 * @param l1 first list
 * @param l2 second list
 * @return a list of common tail elements
 */
private static List<JsonNode> tail(final List<JsonNode> l1, final List<JsonNode> l2) {
    final List<JsonNode> l = head(Lists.reverse(l1), Lists.reverse(l2));
    return Lists.reverse(l);
}

From source file:org.solovyev.android.calculator.view.TextHighlighter.java

@Nonnull
@Override//www  .j  a v  a 2 s. co  m
public TextProcessorEditorResult process(@Nonnull String text) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    final BaseNumberBuilder nb = !formatNumber ? new LiteNumberBuilder(engine) : new NumberBuilder(engine);
    final MathType.Result result = new MathType.Result();

    int offset = 0;
    int groupsCount = 0;
    int openGroupsCount = 0;

    for (int i = 0; i < text.length(); i++) {
        MathType.getType(text, i, nb.isHexMode(), result, engine);

        offset += nb.process(sb, result);

        final String match = result.match;
        switch (result.type) {
        case open_group_symbol:
            openGroupsCount++;
            groupsCount = Math.max(groupsCount, openGroupsCount);
            sb.append(text.charAt(i));
            break;
        case close_group_symbol:
            openGroupsCount--;
            sb.append(text.charAt(i));
            break;
        case operator:
            i += append(sb, match);
            break;
        case function:
            i += append(sb, match);
            makeItalic(sb, i + 1 - match.length(), i + 1);
            break;
        case constant:
        case numeral_base:
            i += append(sb, match);
            makeBold(sb, i + 1 - match.length(), i + 1);
            break;
        default:
            if (result.type == MathType.text || match.length() <= 1) {
                sb.append(text.charAt(i));
            } else {
                i += append(sb, match);
            }
        }
    }

    if (nb instanceof NumberBuilder) {
        offset += ((NumberBuilder) nb).processNumber(sb);
    }

    if (groupsCount == 0) {
        return new TextProcessorEditorResult(sb, offset);
    }
    final List<GroupSpan> groupSpans = new ArrayList<>(groupsCount);
    fillGroupSpans(sb, 0, 0, groupsCount, groupSpans);
    for (GroupSpan groupSpan : Lists.reverse(groupSpans)) {
        makeColor(sb, groupSpan.start, groupSpan.end, getColor(groupSpan.group, groupsCount));
    }
    return new TextProcessorEditorResult(sb, offset);
}