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.eiichiro.bootleg.AbstractRequest.java

/**
 * Returns the Web endpoint method parameter from HTTP request header.
 * /*from   w  w w.  ja va2s .  c  om*/
 * @param type The parameter type.
 * @param name The parameter name.
 * @return The Web endpoint method parameter from the HTTP request header.
 */
protected Object header(Type type, String name) {
    return parameter(type, name, new Function<String, Object>() {

        public Object apply(String name) {
            return context.request().getHeader(name);
        }

    }, new Function<String, Collection<Object>>() {

        @SuppressWarnings("unchecked")
        public Collection<Object> apply(String name) {
            HttpServletRequest request = context.request();
            Map<String, Object> map = new TreeMap<String, Object>();

            for (Object object : Collections.list(request.getHeaderNames())) {
                String key = (String) object;

                if (key.startsWith(name + "[")) {
                    map.put(key, request.getHeader(key));
                }
            }

            return (map.isEmpty()) ? null : map.values();
        }

    });
}

From source file:org.pentaho.marketplace.domain.services.BaPluginService.java

private void copyKettleFilesToExecutionFolder() {
    Path kettleExecutionFolderPath = this.getAbsoluteKettleExecutionFolderPath();
    File targetKettleFilesFolder = new File(kettleExecutionFolderPath.toUri());
    if (!targetKettleFilesFolder.exists() && !targetKettleFilesFolder.mkdirs()) {
        this.getLogger().error("Failed to create temporary folder for marketplace kettle transformations at "
                + targetKettleFilesFolder.toString());
    }/*from w w w . j  a  v  a2s. com*/

    String kettleResourcesSourcePath = this.getAbsoluteKettleResourcesSourcePath();
    Iterable<String> kettleResourcePaths = Collections.list(bundle.getEntryPaths(kettleResourcesSourcePath));
    for (String kettleResourcePath : kettleResourcePaths) {
        this.writeResourceToFolder(kettleResourcePath, kettleExecutionFolderPath);
    }
}

From source file:org.votingsystem.util.HttpHelper.java

public static String getLocalIP() throws SocketException {
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
        Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();
        for (InetAddress inetAddress : Collections.list(inetAddresses)) {
            if (inetAddress.isSiteLocalAddress()) {
                String inetAddressStr = inetAddress.toString();
                while (inetAddressStr.startsWith("/"))
                    inetAddressStr = inetAddressStr.substring(1);
                return inetAddressStr;
            }//from ww  w.  j ava2  s . c  o m

        }
    }
    return null;
}

From source file:com.jsmartframework.web.manager.BeanHandler.java

public void finalizeBeans(HttpServletRequest request, HttpServletResponse response) {
    List<String> names = Collections.list(request.getAttributeNames());
    for (String name : names) {
        Object bean = request.getAttribute(name);
        if (bean == null) {
            continue;
        }/*from  w  w  w.j a  v  a2s. c  o m*/

        Field[] exposeVars = HELPER.getExposeVarFields(bean.getClass());
        for (int i = 0; i < exposeVars.length; i++) {
            try {
                Object value = exposeVars[i].get(bean);
                if (value != null) {
                    setExposeVarAttribute(request, exposeVars[i].getName(), value);
                }
            } catch (Exception ex) {
                LOGGER.log(Level.SEVERE, "Could not expose var [" + exposeVars[i] + "]", ex);
            }
        }

        if (bean.getClass().isAnnotationPresent(WebBean.class)) {
            finalizeWebBean(bean, request);

        } else if (bean.getClass().isAnnotationPresent(AuthBean.class)) {
            finalizeAuthBean(bean, request, response);

        } else if (bean.getClass().isAnnotationPresent(WebSecurity.class)) {
            finalizeWebSecurity(bean, request);
        }
    }
}

From source file:org.drugis.addis.gui.builder.NetworkMetaAnalysisView.java

private void setColumnWidths(final JTable table) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (final TableColumn c : Collections.list(table.getColumnModel().getColumns())) {
        c.setMinWidth(170);/*from w  w  w  .  ja  v a 2s. c om*/
        c.setPreferredWidth(170);
    }
}

From source file:org.apache.hadoop.hive.ql.exec.HadoopJobExecHelper.java

public void localJobDebugger(int exitVal, String taskId) {
    StringBuilder sb = new StringBuilder();
    sb.append("\n");
    sb.append("Task failed!\n");
    sb.append("Task ID:\n  " + taskId + "\n\n");
    sb.append("Logs:\n");
    console.printError(sb.toString());//from   w  w  w .  j  ava2s  .c om

    for (Appender a : Collections.list((Enumeration<Appender>) LogManager.getRootLogger().getAllAppenders())) {
        if (a instanceof FileAppender) {
            console.printError(((FileAppender) a).getFile());
        }
    }
}

From source file:org.mortbay.ijetty.IJetty.java

License:asdf

private void printNetworkInterfaces() {
    try {/*www.  java  2  s  . c  o  m*/
        Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
        for (NetworkInterface ni : Collections.list(nis)) {
            Enumeration<InetAddress> iis = ni.getInetAddresses();
            for (InetAddress ia : Collections.list(iis)) {
                consoleBuffer.append(formatJettyInfoLine("Network interface: %s: %s", ni.getDisplayName(),
                        ia.getHostAddress()));
            }
        }
    } catch (SocketException e) {
        Log.w(TAG, e);
    }
}

From source file:org.sonar.classloader.ClassloaderBuilderTest.java

@Test
public void getResources_from_parent_and_siblings() throws Exception {
    Map<String, ClassLoader> newClassloaders = sut.newClassloader("the-parent")
            .addURL("the-parent", new File("tester/a.jar").toURL())

            .newClassloader("the-sib").addURL("the-sib", new File("tester/b.jar").toURL())

            .newClassloader("the-child").addURL("the-child", new File("tester/c.jar").toURL())
            .setParent("the-child", "the-parent", Mask.ALL).addSibling("the-child", "the-sib", Mask.ALL)
            .build();// w w w .j a v  a  2s.  c  o  m

    ClassLoader parent = newClassloaders.get("the-parent");
    assertThat(Collections.list(parent.getResources("a.txt"))).hasSize(1);
    assertThat(Collections.list(parent.getResources("b.txt"))).hasSize(0);
    assertThat(Collections.list(parent.getResources("c.txt"))).hasSize(0);

    ClassLoader child = newClassloaders.get("the-child");
    assertThat(Collections.list(child.getResources("a.txt"))).hasSize(1);
    assertThat(Collections.list(child.getResources("b.txt"))).hasSize(1);
    assertThat(Collections.list(child.getResources("c.txt"))).hasSize(1);
}

From source file:net.sf.jabref.gui.FindUnlinkedFilesDialog.java

/**
 * Creates a list of {@link File}s for all leaf nodes in the tree structure
 * <code>node</code>, which have been marked as <i>selected</i>. <br>
 * <br>//from   w w  w .ja va  2s. com
 * <code>Selected</code> nodes correspond to those entries in the tree,
 * whose checkbox is <code>checked</code>.
 *
 * SIDE EFFECT: The checked nodes are removed from the tree.
 *
 * @param node
 *            The root node representing a tree structure.
 * @return A list of files of all checked leaf nodes.
 */
private List<File> getFileListFromNode(CheckableTreeNode node) {
    List<File> filesList = new ArrayList<>();
    Enumeration<CheckableTreeNode> children = node.depthFirstEnumeration();
    List<CheckableTreeNode> nodesToRemove = new ArrayList<>();
    for (CheckableTreeNode child : Collections.list(children)) {
        if (child.isLeaf() && child.isSelected()) {
            File nodeFile = ((FileNodeWrapper) child.getUserObject()).file;
            if ((nodeFile != null) && nodeFile.isFile()) {
                filesList.add(nodeFile);
                nodesToRemove.add(child);
            }
        }
    }

    // remove imported files from tree
    DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
    for (CheckableTreeNode nodeToRemove : nodesToRemove) {
        DefaultMutableTreeNode parent = (DefaultMutableTreeNode) nodeToRemove.getParent();
        model.removeNodeFromParent(nodeToRemove);

        // remove empty parent node
        while ((parent != null) && parent.isLeaf()) {
            DefaultMutableTreeNode pp = (DefaultMutableTreeNode) parent.getParent();
            if (pp != null) {
                model.removeNodeFromParent(parent);
            }
            parent = pp;
        }
        // TODO: update counter / see: getTreeCellRendererComponent for label generation
    }
    tree.invalidate();
    tree.repaint();

    return filesList;
}