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:NotificationMessage.java

public static InetAddress getIPAddress() throws SocketException {
    InetAddress ip = null;/*from   ww w .  ja va2  s.  c om*/
    Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netint : Collections.list(nets)) {
        if (netint.getName().equals("wlan0")) {
            Enumeration<InetAddress> inetAddresses = netint.getInetAddresses();

            for (InetAddress inetAddress : Collections.list(inetAddresses)) {
                return inetAddress;
            }
            //displayInterfaceInformation(netint);

        }
        continue;

    }
    return ip;
}

From source file:net.sf.jabref.importer.ZipFileChooser.java

/**
 * Entries that can be selected with this dialog.
 *
 * @param zipFile  Zip-File//from  w w  w. j a va 2s  . c  o m
 * @return  entries that can be selected
 */
private static ZipEntry[] getSelectableZipEntries(ZipFile zipFile) {
    List<ZipEntry> entries = new ArrayList<>();
    Enumeration<? extends ZipEntry> e = zipFile.entries();
    for (ZipEntry entry : Collections.list(e)) {
        if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
            entries.add(entry);
        }
    }
    return entries.toArray(new ZipEntry[entries.size()]);
}

From source file:it.tidalwave.northernwind.frontend.filesystem.impl.ResourceFileNetBeansPlatform.java

@Override
@Nonnull/*w ww  .  jav  a 2s. com*/
public Finder findChildren() {
    return ResourceFileFinderSupport.withComputeResults(getClass().getSimpleName(),
            new Function<Finder, List<ResourceFile>>() {
                @Override
                public List<ResourceFile> apply(final @Nonnull Finder f) {
                    final String name = f.getName();
                    final boolean recursive = f.isRecursive();

                    final List<ResourceFile> result = new ArrayList<>();

                    if (name != null) {
                        final FileObject child = delegate.getFileObject(name);

                        if (child != null) {
                            result.add(fileSystem.createResourceFile(child));
                        }
                    } else {
                        for (final FileObject child : Collections.list(delegate.getChildren(recursive))) {
                            result.add(fileSystem.createResourceFile(child));
                        }
                    }

                    return result;
                }
            });
}

From source file:com.github.reverseproxy.ReverseProxyJettyHandler.java

private Map<String, String> getRequestHeaders(HttpServletRequest request) {
    Map<String, String> requestHeaders = new HashMap<String, String>();
    Enumeration<String> headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerKey = headerNames.nextElement();
        if (!headerKey.equalsIgnoreCase("Accept-Encoding") && !headerKey.equalsIgnoreCase("Host")) { //Encoding doesnt work???
            String headerValue = StringUtils.join(Collections.list(request.getHeaders(headerKey)), ",");
            requestHeaders.put(headerKey, headerValue);
        }/*from  ww w  .  j av  a 2 s.c  o m*/
    }
    return requestHeaders;
}

From source file:abs.backend.erlang.ErlApp.java

private void copyJarDirectory(JarFile jarFile, String inname, String outname) throws IOException {
    InputStream is = null;/*from w  w w .j  a  v  a2  s .c  om*/
    for (JarEntry entry : Collections.list(jarFile.entries())) {
        if (entry.getName().startsWith(inname)) {
            String relFilename = entry.getName().substring(inname.length());
            if (!entry.isDirectory()) {
                is = jarFile.getInputStream(entry);
                ByteStreams.copy(is, Files.newOutputStreamSupplier(new File(outname, relFilename)));
            } else {
                new File(outname, relFilename).mkdirs();
            }
        }
    }
    is.close();
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void initComps() {

    final ButtonGroup examples = new ButtonGroup();
    examples.add(new JRadioButton(Main.Examples.DEPRESSION.name, true));
    examples.add(new JRadioButton(Main.Examples.HYPERTENSION.name));

    final AbstractAction exampleAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            d_main.loadExampleDomain(Main.Examples.findFileName(getSelection(examples).getText()));
            closeWelcome();//  w  w w  .j  a v  a  2s  .co  m
        }
    };

    final AbstractAction loadAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            if (d_main.fileLoadActions() == JFileChooser.APPROVE_OPTION) {
                closeWelcome();
            }
        }
    };

    final AbstractAction newAction = new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            d_main.newFileActions();
            closeWelcome();
        }
    };

    FormLayout layout = new FormLayout("left:pref, " + SPACING + "px, left:pref",
            "p, 3dlu, p, " + SPACING + "px, p, " + SPACING + "px, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    final CellConstraints cc = new CellConstraints();

    builder.add(createImageLabel(FileNames.IMAGE_HEADER), cc.xyw(1, 1, 3));
    builder.add(createButton("Load example", FileNames.ICON_TIP, exampleAction), cc.xy(1, 3));

    final PanelBuilder radios = new PanelBuilder(new FormLayout("p, fill:pref:grow, right:pref", "p, 3dlu, p"));

    final ArrayList<AbstractButton> buttons = Collections.list(examples.getElements());
    forAllDo(buttons, new Closure<AbstractButton>() {
        public void execute(final AbstractButton exampleOption) {
            int row = buttons.indexOf(exampleOption) == 0 ? 1 : buttons.indexOf(exampleOption) + 2;
            exampleOption.setOpaque(false);
            radios.add(exampleOption, cc.xy(1, row));
            radios.add(createHelpButton(exampleOption), cc.xy(3, row));
        }

        private JButton createHelpButton(final AbstractButton exampleOption) {
            JButton help = GUIFactory.createIconButton(org.drugis.mtc.gui.FileNames.ICON_ABOUT,
                    "Information about this example");
            removeBackground(help);

            help.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    Examples example = Examples.findByName(exampleOption.getText());
                    String helpText = s_help.getHelpText(example.name().toLowerCase());
                    showExampleInfo(helpText);
                }
            });
            return help;
        }
    });

    JPanel radiosPanel = radios.getPanel();
    setBorder(radiosPanel);
    builder.add(radiosPanel, cc.xy(3, 3));

    builder.add(createButton("Open file", FileNames.ICON_OPENFILE, loadAction), cc.xy(1, 5));
    JTextPane load = createLabel("Load an existing ADDIS data file stored on your computer.");
    builder.add(load, cc.xy(3, 5));

    builder.add(createButton("New dataset", FileNames.ICON_FILE_NEW, newAction), cc.xy(1, 7));
    builder.add(createLabel("Start with an empty file to build up your own data and analyses."), cc.xy(3, 7));

    builder.add(createImageLabel(FileNames.IMAGE_FOOTER), cc.xyw(1, 9, 3));

    setContentPane(builder.getPanel());
}

From source file:com.flexive.shared.FxArrayUtils.java

/**
 * Removes dupicated entries from the list.
 *
 * @param list the list/*from  w ww.j  av a  2 s .  c  om*/
 * @return the list without any duplicated entries
 */
public static long[] removeDuplicates(long[] list) {
    if (list == null || list.length == 0) {
        return new long[0];
    }
    Hashtable<Long, Boolean> tbl = new Hashtable<Long, Boolean>(list.length);
    for (long ele : list) {
        tbl.put(ele, Boolean.FALSE);
    }
    long[] result = new long[tbl.size()];
    int pos = 0;
    for (long element : Collections.list(tbl.keys())) {
        result[pos++] = element;
    }
    return result;
}

From source file:com.ery.ertc.estorm.util.DNS.java

/**
 * Returns all the IPs associated with the provided interface, if any, in textual form.
 * /* w  w w  .jav  a 2s.com*/
 * @param strInterface
 *            The name of the network interface or subinterface to query (eg eth0 or eth0:0) or the string "default"
 * @param returnSubinterfaces
 *            Whether to return IPs associated with subinterfaces of the given interface
 * @return A string vector of all the IPs associated with the provided interface
 * @throws UnknownHostException
 *             If an UnknownHostException is encountered in querying the default interface or the given interface can not be found
 * 
 */
public static String[] getIPs(String strInterface, boolean returnSubinterfaces) throws UnknownHostException {
    if ("default".equals(strInterface)) {
        return new String[] { InetAddress.getLocalHost().getHostAddress() };
    }
    NetworkInterface netIf;
    try {
        netIf = NetworkInterface.getByName(strInterface);
        if (netIf == null) {
            netIf = getSubinterface(strInterface);
            if (netIf == null) {
                throw new UnknownHostException("Unknown interface " + strInterface);
            }
        }
    } catch (SocketException e) {
        LOG.warn("Unable to get IP for interface " + strInterface, e);
        return new String[] { InetAddress.getLocalHost().getHostAddress() };
    }

    // NB: Using a LinkedHashSet to preserve the order for callers
    // that depend on a particular element being 1st in the array.
    // For example, getDefaultIP always returns the first element.
    LinkedHashSet<InetAddress> allAddrs = new LinkedHashSet<InetAddress>();
    allAddrs.addAll(Collections.list(netIf.getInetAddresses()));
    if (!returnSubinterfaces) {
        allAddrs.removeAll(getSubinterfaceInetAddrs(netIf));
    }

    String ips[] = new String[allAddrs.size()];
    int i = 0;
    for (InetAddress addr : allAddrs) {
        ips[i++] = addr.getHostAddress();
    }
    return ips;
}

From source file:com.centeractive.ws.server.core.SoapServer.java

/**
 * @return a list of registered context paths
 */// w w  w  .j  ava  2s.  com
public List<String> getRegisteredContextPaths() {
    return Collections.list(endpoint.getRegisteredContextPaths());
}

From source file:eu.planets_project.tb.gui.backing.ListExp.java

public Collection<Experiment> getAllMatchingExperiments() {
    // Otherwise, search for the string toFind:
    log.debug("Searching experiments for: " + toFind);
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    Collection<Experiment> allExps = null;
    // Only go if there is a string to search for:
    if (toFind == null || "".equals(toFind)) {
        allExps = testbedMan.getAllExperiments();
    } else {//w w w  .  jav  a2 s  .c  om
        allExps = testbedMan.searchAllExperiments(toFind);
    }
    log.debug("Found " + allExps.size() + " matching experiment(s).");
    currExps = Collections.list(Collections.enumeration(allExps));
    sort(getSort(), isAscending());
    return currExps;
}