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.onosproject.net.intent.impl.compiler.OpticalPathIntentCompiler.java

/**
 * Create rules for the reverse path of the intent.
 *
 * @param intent the intent/*from   w ww.jav  a2s.  co  m*/
 * @return list of flow rules
 */
private List<FlowRule> createReverseRules(OpticalPathIntent intent) {
    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    selectorBuilder.matchInPort(intent.dst().port());

    List<FlowRule> rules = new LinkedList<>();
    ConnectPoint current = intent.dst();

    for (Link link : Lists.reverse(intent.path().links())) {
        TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
        treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
        treatmentBuilder.setOutput(link.dst().port());

        FlowRule rule = DefaultFlowRule.builder().forDevice(current.deviceId())
                .withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build())
                .withPriority(intent.priority()).fromApp(appId).makePermanent().build();

        rules.add(rule);

        current = link.src();
        selectorBuilder.matchInPort(link.src().port());
        selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
        selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
    }

    // Build the egress ROADM rule
    TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
    treatmentLast.setOutput(intent.src().port());

    FlowRule rule = new DefaultFlowRule.Builder().forDevice(intent.src().deviceId())
            .withSelector(selectorBuilder.build()).withTreatment(treatmentLast.build())
            .withPriority(intent.priority()).fromApp(appId).makePermanent().build();
    rules.add(rule);

    return rules;
}

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

@Override
public ProxyInvocationHandler findInvocationHandlerForClass(final Class<?> iface) {
    Check.notNull(iface, "iface");
    Check.stateIsTrue(iface.isInterface(), "Must be an interface.");

    for (final InvocationHandlerPair pair : Lists.reverse(invocationHandlerMapping)) {
        if (pair.getKey().equals(iface)) {
            return pair.getValue();
        }/* w  ww .  j ava2 s .co  m*/
    }

    return null;
}

From source file:com.google.template.soy.jbcsrc.PrintDirectives.java

private static AppendableAndOptions applyStreamingPrintDirectivesTo(List<DirectiveWithArgs> directivesToApply,
        Expression appendable, JbcSrcPluginContext context, TemplateVariableManager variableManager) {
    final List<LocalVariable> closeables = new ArrayList<>();
    final List<Variable> appendableVars = new ArrayList<>();
    Scope scope = variableManager.enterScope();

    AppendableAndOptions prev = AppendableAndOptions.create(appendable);
    Variable prevVar = scope.createTemporary("tmp_appendable", appendable);
    appendableVars.add(prevVar);//w w w.  j a  va2 s. c o  m

    // Apply the directives to the appendable in reverse
    // since we are wrapping the directives around the appendable we need to wrap the underlying
    // appendable with the last directive first. so iterate in reverse order.
    for (DirectiveWithArgs directiveToApply : Lists.reverse(directivesToApply)) {
        AppendableAndOptions curr = directiveToApply.apply(context, prevVar.local());
        Variable currVar = scope.createTemporary("tmp_appendable", curr.appendable());
        appendableVars.add(currVar);
        if (curr.closeable()) {
            closeables.add(currVar.local());
        }
        prev = curr;
        prevVar = currVar;
    }

    // Check if we need to apply a wrapper to make sure close propagates to all the right places
    // this is necessary if there are multiple closeable wrappers.
    final Expression appendableExpression;
    final boolean closeable;
    if (closeables.isEmpty()) {
        appendableExpression = prev.appendable();
        closeable = false;
    } else if (closeables.size() == 1 && prev.closeable()) {
        // there is exactly one closeable and it is first, we don't need a wrapper
        appendableExpression = prev.appendable();
        closeable = true;
    } else {
        // there is either more than one closeable, or it is not the first one, so we need a wrapper
        // We need to reverse the list of closeables so that we close them in the correct order. for
        // example, given '|foo|bar' we will first wrap the delegate with bar and then with foo but we
        // need to close foo first.
        appendableExpression = RUNTIME_PROPAGATE_CLOSE.invoke(Iterables.getLast(appendableVars).local(),
                BytecodeUtils.asImmutableList(Lists.reverse(closeables)));
        closeable = true;
    }

    final Statement exitScope = scope.exitScope();
    Expression result = new Expression(appendableExpression.resultType()) {
        @Override
        protected void doGen(CodeBuilder adapter) {
            for (Variable var : appendableVars) {
                var.initializer().gen(adapter);
            }
            appendableExpression.gen(adapter);
            exitScope.gen(adapter);
        }
    };
    if (closeable) {
        return AppendableAndOptions.createCloseable(result);
    } else {
        return AppendableAndOptions.create(result);
    }
}

From source file:org.opendaylight.controller.blueprint.BlueprintContainerRestartServiceImpl.java

private void restartContainerAndDependentsInternal(Bundle forBundle) {
    // We use a LinkedHashSet to preserve insertion order as we walk the service usage hierarchy.
    Set<Bundle> containerBundlesSet = new LinkedHashSet<>();
    List<Entry<String, ModuleIdentifier>> configModules = new ArrayList<>();
    findDependentContainersRecursively(forBundle, containerBundlesSet, configModules);

    List<Bundle> containerBundles = new ArrayList<>(containerBundlesSet);

    LOG.info("Restarting blueprint containers for bundle {} and its dependent bundles {}", forBundle,
            containerBundles.subList(1, containerBundles.size()));

    // Destroy the containers in reverse order with 'forBundle' last, ie bottom-up in the service tree.
    for (Bundle bundle : Lists.reverse(containerBundles)) {
        blueprintExtenderService.destroyContainer(bundle, blueprintExtenderService.getContainer(bundle));
    }//  ww w. j a v  a  2  s. c om

    // The blueprint containers are created asynchronously so we register a handler for blueprint events
    // that are sent when a container is complete, successful or not. The CountDownLatch tells when all
    // containers are complete. This is done to ensure all blueprint containers are finished before we
    // restart config modules.
    final CountDownLatch containerCreationComplete = new CountDownLatch(containerBundles.size());
    ServiceRegistration<?> eventHandlerReg = registerEventHandler(forBundle.getBundleContext(),
            new EventHandler() {
                @Override
                public void handleEvent(Event event) {
                    LOG.debug("handleEvent {} for bundle {}", event.getTopic(),
                            event.getProperty(EventConstants.BUNDLE));
                    if (containerBundles.contains(event.getProperty(EventConstants.BUNDLE))) {
                        containerCreationComplete.countDown();
                    }
                }
            });

    // Restart the containers top-down starting with 'forBundle'.
    for (Bundle bundle : containerBundles) {
        List<Object> paths = BlueprintBundleTracker.findBlueprintPaths(bundle);

        LOG.info("Restarting blueprint container for bundle {} with paths {}", bundle, paths);

        blueprintExtenderService.createContainer(bundle, paths);
    }

    try {
        containerCreationComplete.await(5, TimeUnit.MINUTES);
    } catch (InterruptedException e) {
        LOG.debug("CountDownLatch await was interrupted - returning");
        return;
    }

    AriesFrameworkUtil.safeUnregisterService(eventHandlerReg);

    // Now restart any associated config system Modules.
    restartConfigModules(forBundle.getBundleContext(), configModules);
}

From source file:edu.udo.scaffoldhunter.gui.SubsetTreeModel.java

/**
 * @param subset/*from  www  .  j  a  v a2 s. c  o m*/
 * 
 * @return the TreePath leading to the given subset
 */
public TreePath getPathToSubset(Subset subset) {
    Object[] objs = Lists.reverse(Subsets.getAncestors(subset)).toArray();
    return new TreePath(objs);
}

From source file:at.bitcoin_austria.bitfluids.BitFluidsMainActivity.java

private void restoreState(Bundle savedInstanceState) {
    Preconditions.checkNotNull(bitcoinTransactionListener);
    if (savedInstanceState != null) {
        state = (BitFluidsActivityState) savedInstanceState.getSerializable("state");
    }//  w  w w  . j a va2s . c o m
    if (state == null) {
        state = new BitFluidsActivityState();
    }
    bitcoinTransactionListener.addHashes(state.getTransactionItems());
    list_view_adapter = new ArrayAdapter<TransactionItem>(this, R.layout.list_tx_item,
            Lists.reverse(state.getTransactionItems()));
    list_view_tx.setAdapter(list_view_adapter);
}

From source file:io.hops.hopsworks.admin.project.InodesMB.java

/**
 *
 * @param components string for path to parse. Has to be a List supporting
 * remove, so ArrayList here./*from  w w w.  j a v  a  2s.  c om*/
 * @param path empty to begin with
 * @param origCwd cwd when calling this method and still cwd when it returns
 * @return list of path components, starting with root.
 */
private List<Inode> getPathComponents(ArrayList<String> components, List<Inode> path, Inode origCwd)
        throws BadPath {
    if (components.size() < 1) {
        throw new BadPath("Path was empty");
    }
    if (components.size() == 1) { //base case
        path.add(this.cwd);
        this.cwd = origCwd;
        return Lists.reverse(path); // put the root at the start of the list
    }
    if (path.isEmpty()) {
        this.cwd = this.root;
    }
    path.add(this.cwd);
    cdUp();
    components.remove(0);
    return getPathComponents(components, path, origCwd);
}

From source file:net.sourceforge.docfetcher.gui.StatusBar.java

/**
 * Updates the layout of the status bar parts.
 *///from   www  .j a  v a2  s .c  o  m
private void updateLayout() {
    if (rightParts == null)
        return; // right parts are in the process of being created

    FormDataFactory fdf = FormDataFactory.getInstance();
    fdf.margin(0).top().bottom();

    List<StatusBarPart> parts = Lists.reverse(rightParts);
    parts = Util.createList(parts, leftPart);

    Control lastControl = null;
    for (StatusBarPart part : parts) {
        if (!part.isVisible) {
            part.label.setLayoutData(null);
            continue;
        }
        if (lastControl == null)
            fdf.right();
        else
            fdf.right(lastControl, -20);
        fdf.applyTo(part.label);
        lastControl = part.label;
    }

    assert lastControl == leftPart.label;
    fdf.left().applyTo(lastControl);

    layout();
}

From source file:com.davidbracewell.reflection.BeanUtils.java

/**
 * Sets properties on an object using the values defined in the Config. Will set properties defined in the Config
 * for all of this object's super classes as well.
 *
 * @param object The object to parameterize
 * @return The object/* w  w  w .  ja  v a 2 s  .com*/
 */
public static <T> T parameterizeObject(T object) {
    if (object == null) {
        return null;
    }

    BeanMap beanMap = new BeanMap(object);
    for (Class<?> clazz : Lists.reverse(ReflectionUtils.getAllClasses(object))) {
        String match = clazz.getName() + ".";
        doParametrization(beanMap, match);
    }

    return object;
}

From source file:max.hubbard.bettershops.Menus.ShopMenus.History.java

@Override
public void draw(final Player p, final int page, final Object... obj) {
    inv.clear();//from w w  w  .  j  a  v  a2  s. co  m

    ItemStack item = new ItemStack(Material.STAINED_GLASS_PANE, 1, shop.getFrameColor());
    ItemMeta m = item.getItemMeta();
    m.setDisplayName(" ");
    item.setItemMeta(m);
    for (int i = 0; i < 18; i++) {
        inv.setItem(i, item);
    }

    ItemStack info = new ItemStack(Material.ENDER_CHEST);
    ItemMeta infoMeta = info.getItemMeta();
    infoMeta.setDisplayName(Language.getString("History", "History"));
    infoMeta.setLore(Arrays.asList(Language.getString("MainGUI", "Page") + " 7" + page));
    info.setItemMeta(infoMeta);

    ItemStack clear = new ItemStack(Material.STAINED_GLASS_PANE, 1, (byte) 14);
    ItemMeta clearMeta = clear.getItemMeta();
    clearMeta.setDisplayName(Language.getString("History", "ClearHistory"));
    clearMeta.setLore(Arrays.asList(Language.getString("History", "ClearHistoryLore")));
    clear.setItemMeta(clearMeta);
    ClickableItem clearClick = new ClickableItem(new ShopItemStack(clear), inv, p);
    clearClick.addLeftClickAction(new LeftClickAction() {
        @Override
        public void onAction(InventoryClickEvent e) {
            shop.getHistory().clearHistory();
            draw(p, page, obj);
        }
    });

    ItemStack back = new ItemStack(Material.ARROW);
    ItemMeta backMeta = back.getItemMeta();
    backMeta.setDisplayName(Language.getString("MainGUI", "BackArrow"));
    back.setItemMeta(backMeta);
    ClickableItem backClick = new ClickableItem(new ShopItemStack(back), inv, p);
    backClick.addLeftClickAction(new LeftClickAction() {
        @Override
        public void onAction(InventoryClickEvent e) {
            shop.getMenu(MenuType.OWNER_BUYING).draw(p, page, obj);
        }
    });

    ItemStack arrow = new ItemStack(Material.ARROW);
    ItemMeta arrowMeta = arrow.getItemMeta();
    arrowMeta.setDisplayName(Language.getString("MainGUI", "NextPage"));
    arrow.setItemMeta(arrowMeta);
    ClickableItem arrowClick = new ClickableItem(new ShopItemStack(arrow), inv, p);
    arrowClick.addLeftClickAction(new LeftClickAction() {
        @Override
        public void onAction(InventoryClickEvent e) {
            draw(p, page + 1, obj);
        }
    });

    ItemStack barrow = new ItemStack(Material.ARROW);
    ItemMeta barrowMeta = barrow.getItemMeta();
    barrowMeta.setDisplayName(Language.getString("MainGUI", "PreviousPage"));
    barrow.setItemMeta(barrowMeta);
    ClickableItem barrowClick = new ClickableItem(new ShopItemStack(barrow), inv, p);
    barrowClick.addLeftClickAction(new LeftClickAction() {
        @Override
        public void onAction(InventoryClickEvent e) {
            draw(p, page - 1, obj);
        }
    });

    if (page > 1) {
        inv.setItem(1, barrow);
    }

    inv.setItem(0, back);

    inv.setItem(4, info);
    if (shop instanceof FileShop)
        inv.setItem(7, clear);

    int maxPage = (int) Math.ceil((double) (shop.getHistory().getAllTransactions().size()) / 36);

    if (maxPage == 0) {
        maxPage = 1;
    }

    if (page != maxPage) {
        inv.setItem(8, arrow);
    }

    int j = 0;

    if (page > 1) {
        j = 36 * (page - 1);
    }

    int k = shop.getHistory().getAllTransactions().size();

    if (page != maxPage) {
        k = k - (j + (shop.getHistory().getAllTransactions().size() - 36));
    }

    LinkedList<Transaction> list = shop.getHistory().getAllTransactions();

    List<Transaction> l = Lists.reverse(list);

    if (list.size() > 0) {
        for (int i = j; i < k; i++) {
            Transaction trans = l.get(i);
            ItemStack it = new ItemStack(Material.EMERALD);
            ItemMeta sk = it.getItemMeta();
            String s = "Buying";
            if (trans.isSell()) {
                it = new ItemStack(Material.EMERALD_BLOCK);
                s = "Selling";
            }

            sk.setDisplayName("a" + trans.getPlayerName());

            sk.setLore(Arrays.asList(
                    Language.getString("History", "Date") + " 8" + trans.getDate().toLocaleString(),
                    Language.getString("History", "Item") + " 8" + trans.getItem(),
                    Language.getString("History", "Price") + " 8" + trans.getPrice(),
                    Language.getString("History", "Amount") + " 8" + trans.getAmount(),
                    Language.getString("History", "Shop") + " 8" + s));

            it.setItemMeta(sk);

            if (inv.firstEmpty() > 0)
                inv.setItem(inv.firstEmpty(), it);
        }
    }

    new BukkitRunnable() {

        @Override
        public void run() {
            p.openInventory(inv);
        }

    }.runTask(Bukkit.getPluginManager().getPlugin("BetterShops"));
}