Example usage for java.util Collections list

List of usage examples for java.util Collections list

Introduction

In this page you can find the example usage for java.util Collections list.

Prototype

public static <T> ArrayList<T> list(Enumeration<T> e) 

Source Link

Document

Returns an array list containing the elements returned by the specified enumeration in the order they are returned by the enumeration.

Usage

From source file:org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilderTest.java

@Test
public void buildRequestLocaleMulti() {
    webRequest.setAdditionalHeader("Accept-Language", "da, en-gb;q=0.8, en;q=0.7");

    MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);

    // FIXME Locale.ENGLISH is due to fact cannot remove it from MockHttpServletRequest
    List<Locale> expected = Arrays.asList(new Locale("da"), new Locale("en", "gb", "0.8"),
            new Locale("en", "", "0.7"), Locale.ENGLISH);
    assertThat(Collections.list(actualRequest.getLocales())).isEqualTo(expected);
}

From source file:com.eucalyptus.upgrade.TestHarness.java

@SuppressWarnings("unchecked")
private static Multimap<Class, Method> getTestMethods() throws Exception {
    final Multimap<Class, Method> testMethods = ArrayListMultimap.create();
    List<Class> classList = Lists.newArrayList();
    for (File f : new File(System.getProperty("euca.home") + "/usr/share/eucalyptus").listFiles()) {
        if (f.getName().startsWith("eucalyptus") && f.getName().endsWith(".jar")
                && !f.getName().matches(".*-ext-.*")) {
            try {
                JarFile jar = new JarFile(f);
                Enumeration<JarEntry> jarList = jar.entries();
                for (JarEntry j : Collections.list(jar.entries())) {
                    if (j.getName().matches(".*\\.class.{0,1}")) {
                        String classGuess = j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
                        try {
                            Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
                            for (final Method m : candidate.getDeclaredMethods()) {
                                if (Iterables.any(testAnnotations,
                                        new Predicate<Class<? extends Annotation>>() {
                                            public boolean apply(Class<? extends Annotation> arg0) {
                                                return m.getAnnotation(arg0) != null;
                                            }
                                        })) {
                                    System.out.println("Added test class: " + candidate.getCanonicalName());
                                    testMethods.put(candidate, m);
                                }/*from  w  ww.j  av  a2  s  .com*/
                            }
                        } catch (ClassNotFoundException e) {
                        }
                    }
                }
                jar.close();
            } catch (Exception e) {
                System.out.println(e.getMessage());
                continue;
            }
        }
    }
    return testMethods;
}

From source file:com.enioka.jqm.tools.JndiContext.java

@Override
public void bind(Name name, Object obj) throws NamingException {
    this.bind(StringUtils.join(Collections.list(name.getAll()), "/"), obj);
}

From source file:edu.mayo.cts2.framework.webapp.rest.controller.AbstractMessageWrappingController.java

@SuppressWarnings("unchecked")
protected HttpHeaders getHeaders(HttpServletRequest request) {
    HttpHeaders httpHeaders = new HttpHeaders();

    Enumeration<String> headers = request.getHeaderNames();
    while (headers.hasMoreElements()) {
        String headerName = headers.nextElement();
        httpHeaders.put(headerName, Collections.list(request.getHeaders(headerName)));
    }/* ww  w.ja  va2 s  .c o  m*/

    return httpHeaders;
}

From source file:com.att.arocollector.AROCollectorActivity.java

/**
 * check a network interface by name/*from  w  w w.j  a v  a  2  s  . c om*/
 *
 * @param context
 * @param networkInterfaceName
 * @return true if interface exists and is active
 * @throws Exception
 */
private boolean checkForActiveInterface(Context context, String networkInterfaceName) throws Exception {

    List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
    for (NetworkInterface intf : interfaces) {
        if (intf.getName().equals(networkInterfaceName)) {
            return intf.isUp();
        }
    }
    return false;
}

From source file:io.github.tavernaextras.biocatalogue.ui.filtertree.FilterTreePane.java

/**
 * This method loads filter data from API and populates the view.
 *///from   w  ww .  ja  va 2 s .  c om
private void loadFiltersAndBuildTheTree() {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            resetTreeActionToolbar();

            jpFilters.removeAll();
            jpFilters.setLayout(new BorderLayout());
            jpFilters.add(new JLabel(" Loading filters..."), BorderLayout.NORTH);
            jpFilters.add(new JLabel(ResourceManager.getImageIcon(ResourceManager.BAR_LOADER_ORANGE)),
                    BorderLayout.CENTER);
            thisPanel.validate();
            thisPanel.repaint(); // validate and repaint this component to make sure that
                                 // scroll bar around the filter tree placeholder panel disappears
        }
    });

    new Thread("Load filters") {
        public void run() {
            try {
                // load filter data
                filtersRoot = client.getBioCatalogueFilters(filtersURL);

                // Create root of the filter tree component
                FilterTreeNode root = new FilterTreeNode("root");

                // populate the tree via its root element
                for (FilterGroup fgroup : filtersRoot.getGroupList()) {
                    // attach filter group directly to the root node
                    FilterTreeNode fgroupNode = new FilterTreeNode(
                            "<html><span style=\"color: black; font-weight: bold;\">"
                                    + StringEscapeUtils.escapeHtml(fgroup.getName().toString())
                                    + "</span></html>");
                    root.add(fgroupNode);

                    // go through all filter types in this group and add them to the tree
                    for (FilterType ftype : fgroup.getTypeList()) {
                        // if there's more than one filter type in the group, add the type node as another level of nesting
                        // (otherwise, attach filters inside the single type directly to the group node)
                        FilterTreeNode filterTypeNode = fgroupNode;
                        if (fgroup.getTypeList().size() > 1) {
                            filterTypeNode = new FilterTreeNode(
                                    "<html><span style=\"color: black; font-weight: bold;\">"
                                            + StringEscapeUtils.escapeHtml(ftype.getName().toString())
                                            + "</span></html>");
                            fgroupNode.add(filterTypeNode);
                        }

                        // For some reason sorting the list of filters before inserting into tree
                        // messes up the tree nodes
                        //              Collections.sort(ftype.getFilterList(), new Comparator<Filter>(){
                        //            @Override
                        //            public int compare(Filter f1, Filter f2) {
                        //                return (f1.getName().compareToIgnoreCase(f2.getName()));
                        //            }                
                        //              });
                        addFilterChildren(filterTypeNode, ftype.getUrlKey().toString(), ftype.getFilterList());
                    }
                }

                // Create the tree view with the populated root
                filterTree = new JFilterTree(root);
                filterTree.setRootVisible(false); // don't want the root to be visible; not a standard thing, so not implemented within JTriStateTree
                filterTree.setLargeModel(true); // potentially can have many filters!
                filterTree.addCheckingListener(thisPanel);

                // insert the created tree view into the filters panel
                jpFilters.removeAll();
                jpFilters.setLayout(new GridLayout(0, 1));
                jpFilters.add(filterTree);
                jpFilters.validate();

                // add actions from the contextual menu of the filter tree into the toolbar
                // that replicates those plus adds additional ones in this panel
                tbFilterTreeToolbar.removeAll();
                for (Action a : filterTree.getContextualMenuActions()) {
                    tbFilterTreeToolbar.add(a);
                }

                // enable all actions
                filterTree.enableAllContextualMenuAction(true);
            } catch (Exception e) {
                logger.error("Failed to load filter tree from the following URL: " + filtersURL, e);
            }
        }

        /**
         * Recursive method to populate a node of the filter tree with all
         * sub-filters.
         * 
         * Ontological terms will be underlined.
         * 
         * @param root Tree node to add children to.
         * @param filterList A list of Filters to add to "root" as children.
         */
        private void addFilterChildren(FilterTreeNode root, String filterCategory, List<Filter> filterList) {
            for (Filter f : filterList) {

                // Is this an ontological term?
                String ontology = null;
                if (FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue())) {
                    String nameAndNamespace = f.getUrlValue().substring(1, f.getUrlValue().length() - 1);
                    String[] namePlusNamespace = nameAndNamespace.split("#");
                    ontology = JFilterTree.getOntologyFromNamespace(namePlusNamespace[0]);
                }

                FilterTreeNode fNode = new FilterTreeNode("<html><span color=\"black\""
                        /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? " style=\"text-decoration: underline;\"" : "") */ + ">"
                        + StringEscapeUtils.escapeHtml(f.getName()) + " (" + f.getCount() + ")" + "</span>" +
                /*(FilterTreeNode.isTagWithNamespaceNode(filterCategory, f.getUrlValue()) ? "<span color=\"gray\">&nbsp;("+f.getCount().intValue()+")</span></html>" : "</html>"),*/
                (ontology != null ? "<span color=\"#3090C7\"> &lt;" + ontology + "&gt;</span></html>"
                        : "</html>"), filterCategory, f.getUrlValue());
                addFilterChildren(fNode, filterCategory, f.getFilterList());

                // Insert the node into the (alphabetically) sorted children nodes
                List<FilterTreeNode> children = Collections.list(root.children());
                // Search for the index the new node should be inserted at
                int index = Collections.binarySearch(children, fNode, new Comparator<FilterTreeNode>() {
                    @Override
                    public int compare(FilterTreeNode o1, FilterTreeNode o2) {
                        String str1 = ((String) o1.getUserObject()).toString();
                        String str2 = ((String) o2.getUserObject()).toString();
                        return (str1.compareToIgnoreCase(str2));
                    }
                });

                if (index < 0) { // not found - index will be equal to -insertion-point -1
                    index = -index - 1;
                } // else node with the same name found in the array - insert it at that position
                root.insert(fNode, index);

                //root.add(fNode);
            }
        }
    }.start();
}

From source file:org.apache.solr.response.transform.TestSubQueryTransformer.java

@Test
public void testThreeLevel() throws Exception {
    List<String> asserts = new ArrayList<>();
    // dave works in both dept, get his coworkers from both
    for (String dept : new String[] { "Engineering", "Support" }) { //dept_id_s_dv">Engineering

        ArrayList<Object> deptWorkers = Collections.list(new StringTokenizer(h.query(req("q",
                "dept_ss_dv:" + dept, //dept_id_i_dv
                "wt", "csv", "csv.header", "false", "fl", "name_s_dv", "rows", "" + peopleMultiplier * 3, // dave has three coworkers in two depts
                "sort", "id desc"))));
        // System.out.println(deptWorkers);

        // looping dave clones
        for (int p : new int[] { 1, peopleMultiplier }) {
            // looping dept clones
            for (int d : new int[] { 1, deptMultiplier }) {
                // looping coworkers
                int wPos = 1;
                for (Object mate : deptWorkers) {
                    // (/response/result/doc/str[@name='name_s_dv'][.='dave']/..)[1]
                    //  /result[@name='subq1']/doc/str[@name='dept_id_s_dv'][.='Engineering']/..
                    //  /result[@name='neighbours']/doc/str[@name='name_s_dv'][.='tina']
                    asserts.add("((/response/result/doc/str[@name='name_s_dv'][.='dave']/..)[" + p + "]"
                            + "/result[@name='subq1']/doc/str[@name='dept_id_s_dv'][.='" + dept + "']/..)[" + d
                            + "]" + "/result[@name='neighbours']/doc[" + wPos + "]/str[@name='name_s_dv'][.='"
                            + mate + "']");
                    wPos++;/*from w  ww.ja  va  2 s .c o  m*/
                }

            }
        }
    }
    //System.out.println(asserts);
    assertQ("dave works at both dept with other folks",
            //  System.out.println(h.query( 
            req(new String[] { "q", "name_s:dave", "indent", "true", "fl",
                    "dept_ss_dv,name_s_dv,subq1:[subquery]", "rows", "" + peopleMultiplier, "subq1.q",
                    "{!terms f=dept_id_s v=$row.dept_ss_dv}", "subq1.fl",
                    "dept_id_i_dv,text_t,dept_id_s_dv,neighbours:[subquery]", "subq1.indent", "true",
                    "subq1.rows", "" + (deptMultiplier * 2), "subq1.neighbours.q", //flipping via numbers 
                    random().nextBoolean() ? "{!terms f=dept_ss_dv v=$row.dept_id_s_dv}"
                            : "{!terms f=dept_is v=$row.dept_id_i_dv}",
                    "subq1.neighbours.fl", "name_s_dv", "subq1.neighbours.rows", "" + peopleMultiplier * 3 },
                    "subq1.neighbours.sort", "id desc")//,
            , asserts.toArray(new String[] {})
    //        ) 
    );

}

From source file:org.basdroid.common.NetworkUtils.java

/**
 * Get IP address from first non-localhost interface
 * @param interfaceName eth0, wlan0 or NULL=use first interface
 * @param useIPv4  true=return ipv4, false=return ipv6
 * @return  address or empty string//  w  w  w  .ja  va  2 s  .c om
 */
public static String getIPAddress(String interfaceName, boolean useIPv4) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            List<InetAddress> inetAddresses = Collections.list(intf.getInetAddresses());
            for (InetAddress inetAddr : inetAddresses) {
                if (!inetAddr.isLoopbackAddress()) {
                    String address = inetAddr.getHostAddress().toUpperCase();
                    boolean isIPv4 = InetAddressUtils.isIPv4Address(address);
                    if (useIPv4) {
                        if (isIPv4) {
                            return address;
                        }
                    } else {
                        if (!isIPv4) {
                            int delim = address.indexOf('%'); // drop ip6 port suffix
                            return delim < 0 ? address : address.substring(0, delim);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

public static String getMacAddr() {
    try {/*w  w w .  j av  a  2 s  . c om*/
        List<NetworkInterface> all = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface nif : all) {
            if (!nif.getName().equalsIgnoreCase("wlan0"))
                continue;

            byte[] macBytes = nif.getHardwareAddress();
            if (macBytes == null) {
                return "";
            }

            StringBuilder res1 = new StringBuilder();
            for (byte b : macBytes) {
                res1.append(Integer.toHexString(b & 0xFF) + ":");
            }

            if (res1.length() > 0) {
                res1.deleteCharAt(res1.length() - 1);
            }
            return res1.toString();
        }
    } catch (Exception e) {
        throw new NfcTagDroidException("can't get mac address", e);
    }
    return "";
}

From source file:com.enioka.jqm.tools.JndiContext.java

@Override
public void unbind(Name name) throws NamingException {
    this.unbind(StringUtils.join(Collections.list(name.getAll()), "/"));
}