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:de.pavloff.spark4knime.jsnippet.ui.JarListPanel.java

private void onJarFileAdd() {
    DefaultListModel<String> model = (DefaultListModel<String>) m_addJarList.getModel();
    Set<String> hash = new HashSet<>(Collections.list(model.elements()));
    StringHistory history = StringHistory.getInstance("java_snippet_jar_dirs");
    if (m_jarFileChooser == null) {
        File dir = null;/*  ww  w . j  a  va2s. com*/
        for (String h : history.getHistory()) {
            File temp = new File(h);
            if (temp.isDirectory()) {
                dir = temp;
                break;
            }
        }
        m_jarFileChooser = new JFileChooser(dir);
        m_jarFileChooser.setFileFilter(new SimpleFileFilter(".zip", ".jar"));
        m_jarFileChooser.setMultiSelectionEnabled(true);
    }
    int result = m_jarFileChooser.showDialog(m_addJarList, "Select");

    if (result == JFileChooser.APPROVE_OPTION) {
        for (File f : m_jarFileChooser.getSelectedFiles()) {
            String s = f.getAbsolutePath();
            if (hash.add(s)) {
                model.addElement(s);
            }
        }
        history.add(m_jarFileChooser.getCurrentDirectory().getAbsolutePath());
    }
}

From source file:org.opennms.features.scv.impl.JCEKSSecureCredentialsVault.java

@Override
public Set<String> getAliases() {
    try {/*from  w ww  .ja  v a  2  s. c o  m*/
        return Sets.newHashSet(Collections.list(m_keystore.aliases()));
    } catch (KeyStoreException e) {
        throw Throwables.propagate(e);
    }
}

From source file:ninja.servlet.ContextImpl.java

@Override
public List<String> getHeaders(String name) {
    return Collections.list(httpServletRequest.getHeaders(name));
}

From source file:org.abs_models.backend.erlang.ErlApp.java

private void copyJarDirectory(JarFile jarFile, String inname, String outname) throws IOException {
    InputStream is = null;//  www  .  jav  a2s.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.asByteSink(new File(outname, relFilename)).openStream());
            } else {
                new File(outname, relFilename).mkdirs();
            }
        }
    }
    is.close();
}

From source file:ro.nextreports.designer.wizpublish.DownloadListWizardPanel.java

/**
 * Called to validate the panel before finishing the wizard. Should return
 * false if canFinish returns false.//ww  w  .j a  va 2  s.co  m
 * 
 * @param messages a List of messages to be displayed.
 * @return true if it is valid for this wizard to finish.
 */
public boolean validateFinish(List<String> messages) {
    if (listModel.size() <= 0) {
        messages.add(I18NSupport.getString("wizard.publish.entities.select.error"));
        return false;
    }
    String destinationPath = (String) context.getAttribute(DownloadBulkWizard.DESTINATION);
    String entity = (String) context.getAttribute(WizardConstants.ENTITY);
    String extension;
    if (WizardConstants.ENTITY_REPORT.equals(entity)) {
        extension = FormSaver.REPORT_FULL_EXTENSION;
    } else {
        extension = ChartUtil.CHART_FULL_EXTENSION;
    }
    StringBuilder sb = new StringBuilder();
    for (Object path : Collections.list(listModel.elements())) {
        String serverPath = (String) path;
        String name = getName(serverPath);
        if (new File(destinationPath + File.separator + name + extension).exists()) {
            sb.append(name).append(" : ");
            sb.append(I18NSupport.getString("wizard.publish.entity.found"));
            sb.append("\n");
        }
    }
    if (sb.length() > 0) {
        JDialog parent = (JDialog) context.getAttribute(PublishWizard.MAIN_FRAME);
        if (!overwriteBulk(parent, sb.toString())) {
            return false;
        }
    }
    return true;
}

From source file:org.apache.sling.scripting.sightly.impl.engine.runtime.RenderContextImpl.java

@SuppressWarnings("unchecked")
private Collection<Object> obtainCollection(Object obj) {
    if (obj == null) {
        return Collections.emptyList();
    }//from  w  w w.j  av  a  2  s  .c  o m
    if (obj instanceof Object[]) {
        return Arrays.asList((Object[]) obj);
    }
    if (obj instanceof Collection) {
        return (Collection<Object>) obj;
    }
    if (obj instanceof Map) {
        return ((Map) obj).keySet();
    }
    if (obj instanceof Record) {
        return ((Record) obj).getPropertyNames();
    }
    if (obj instanceof Enumeration) {
        return Collections.list((Enumeration<Object>) obj);
    }
    if (obj instanceof Iterator) {
        return fromIterator((Iterator<Object>) obj);
    }
    if (obj instanceof Iterable) {
        Iterable iterable = (Iterable) obj;
        return fromIterator(iterable.iterator());
    }
    if (obj instanceof String || obj instanceof Number) {
        Collection list = new ArrayList();
        list.add(obj);
        return list;
    }
    return Collections.emptyList();
}

From source file:net.pms.network.UPNPHelper.java

/**
 * Gets the new multicast socket.//from   w w  w.  ja v a  2 s.  c o  m
 *
 * @return the new multicast socket
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static MulticastSocket getNewMulticastSocket() throws IOException {
    NetworkInterface networkInterface = NetworkConfiguration.getInstance().getNetworkInterfaceByServerName();

    if (networkInterface == null) {
        networkInterface = PMS.get().getServer().getNetworkInterface();
    }

    if (networkInterface == null) {
        throw new IOException("No usable network interface found for UPnP multicast");
    }

    List<InetAddress> usableAddresses = new ArrayList<InetAddress>();
    List<InetAddress> networkInterfaceAddresses = Collections.list(networkInterface.getInetAddresses());

    for (InetAddress inetAddress : networkInterfaceAddresses) {
        if (inetAddress != null && inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
            usableAddresses.add(inetAddress);
        }
    }

    if (usableAddresses.isEmpty()) {
        throw new IOException("No usable addresses found for UPnP multicast");
    }

    InetSocketAddress localAddress = new InetSocketAddress(usableAddresses.get(0), 0);
    MulticastSocket ssdpSocket = new MulticastSocket(localAddress);
    ssdpSocket.setReuseAddress(true);

    logger.trace(
            "Sending message from multicast socket on network interface: " + ssdpSocket.getNetworkInterface());
    logger.trace("Multicast socket is on interface: " + ssdpSocket.getInterface());
    ssdpSocket.setTimeToLive(32);
    logger.trace("Socket Timeout: " + ssdpSocket.getSoTimeout());
    logger.trace("Socket TTL: " + ssdpSocket.getTimeToLive());
    return ssdpSocket;
}

From source file:org.pentaho.hadoop.PropertiesConfigurationPropertiesTest.java

@Test
public void testPropertyNames() {
    HashSet<String> names = new HashSet<>(Arrays.asList("a", "b", "c"));
    mockKeys(names);/*from w  w  w. jav a2  s.  c om*/

    HashSet<String> propertyNames = Collections.list(propertiesConfigurationProperties.propertyNames()).stream()
            .map(Object::toString).collect(Collectors.toCollection(HashSet::new));
    assertEquals(names, propertyNames);
}

From source file:com.celements.payment.service.PayPalScriptService.java

@SuppressWarnings("unchecked")
String getOrigHeader(XWikiRequest request) {
    StringBuffer origHeaderBuffer = new StringBuffer();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String key = (String) headerNames.nextElement();
        List<String> valueList = Collections.list(request.getHeaders(key));
        String[] values = valueList.toArray(new String[0]);
        addParamToStringBuffer(origHeaderBuffer, key, values);
    }//from w  w  w.  j  av  a2  s  .  c  om
    return origHeaderBuffer.toString();
}