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:com.android.tradefed.util.Bugreport.java

/**
 * Returns the list of files contained inside the zipped bugreport. Null if it's not a zipped
 * bugreport.//from w  w  w  .  j  a  v  a2  s .  c  o m
 */
public List<String> getListOfFiles() {
    if (mBugreport == null) {
        return null;
    }
    List<String> list = new ArrayList<>();
    if (!mIsZipped) {
        return null;
    }
    try (ZipFile zipBugreport = new ZipFile(mBugreport)) {
        for (ZipArchiveEntry entry : Collections.list(zipBugreport.getEntries())) {
            list.add(entry.getName());
        }
    } catch (IOException e) {
        CLog.e("Error reading the list of files in the bugreport");
        CLog.e(e);
    }
    return list;
}

From source file:com.tbodt.jswerve.servlet.JSwerveServlet.java

private Headers translateHeaders(HttpServletRequest req) {
    Headers.Builder builder = Headers.builder();
    for (String headerName : Collections.list(req.getHeaderNames()))
        builder.header(headerName, req.getHeader(headerName));
    return builder.build();
}

From source file:org.rhq.enterprise.server.plugin.pc.perspective.PerspectiveServerPluginManager.java

private void deployEmbeddedWars(ServerPluginEnvironment env) {
    String name = null;/*from   www .ja v  a2  s . c  om*/
    try {
        JarFile pluginJarFile = new JarFile(env.getPluginUrl().getFile());
        try {
            for (JarEntry entry : Collections.list(pluginJarFile.entries())) {
                name = entry.getName();
                if (name.toLowerCase().endsWith(".war")) {
                    deployWar(env, entry.getName(), pluginJarFile.getInputStream(entry));
                }
            }
        } finally {
            pluginJarFile.close();
        }
    } catch (Exception e) {
        Throwable t = (e instanceof MBeanException) ? e.getCause() : e;
        log.error("Failed to deploy " + env.getPluginKey().getPluginName() + "#" + name, t);
    }
}

From source file:psiprobe.controllers.certificates.ListCertificatesController.java

/**
 * Gets the certificates.//  w  w  w  .  ja v  a 2 s. c  o  m
 *
 * @param storeType the store type
 * @param storeFile the store file
 * @param storePassword the store password
 * @return the certificates
 * @throws Exception the exception
 */
public List<Cert> getCertificates(String storeType, String storeFile, String storePassword) throws Exception {
    KeyStore keyStore;

    // Get key store
    if (storeType != null) {
        keyStore = KeyStore.getInstance(storeType);
    } else {
        keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    }

    // Get password
    char[] password = null;
    if (storePassword != null) {
        password = storePassword.toCharArray();
    }

    // Load key store from file
    try (InputStream storeInput = getStoreInputStream(storeFile)) {
        keyStore.load(storeInput, password);
    } catch (IOException e) {
        logger.error("Error loading store file {}", storeFile, e);
        return null;
    }

    List<Cert> certs = new ArrayList<>();

    for (String alias : Collections.list(keyStore.aliases())) {

        Certificate[] certificateChains = keyStore.getCertificateChain(alias);

        if (certificateChains != null) {
            for (Certificate certificateChain : certificateChains) {
                X509Certificate x509Cert = (X509Certificate) certificateChain;
                addToStore(certs, alias, x509Cert);
            }
        } else {
            X509Certificate x509Cert = (X509Certificate) keyStore.getCertificate(alias);
            addToStore(certs, alias, x509Cert);
        }
    }
    return certs;
}

From source file:com.github.tomakehurst.wiremock.BindAddressTest.java

private String getIpAddressOtherThan(String lopbackAddress) throws SocketException {
    Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
    for (NetworkInterface netInterface : Collections.list(networkInterfaces)) {
        Enumeration<InetAddress> inetAddresses = netInterface.getInetAddresses();
        for (InetAddress address : Collections.list(inetAddresses)) {
            if (address instanceof Inet4Address && !address.getHostAddress().equals(lopbackAddress)) {
                return address.getHostAddress();
            }//www . j  av a  2 s  .c  o  m
        }
    }
    return null;
}

From source file:ca.tnt.ldaputils.impl.LdapEntry.java

public List getAttributeValues(final String attribute) {
    final Attribute ldapAttribute;
    List values = null;/*from   w ww .  jav a 2  s .  c  om*/

    ldapAttribute = attributes.get(attribute);
    try {
        if (ldapAttribute != null && ldapAttribute.size() != 0) {
            values = Collections.list(ldapAttribute.getAll());
        }
    } catch (NamingException e) {
        throw new LdapNamingException(e);
    }

    return values;
}

From source file:org.xwoot.jxta.test.multiplePeers.DiscoverPeersInGroup.java

/** {@inheritDoc} **/
public void run() {
    System.out.println(this.peerName + " : Thread started.");

    if (this.groupCreator) {
        PeerGroup group = null;/*from  www .j  av  a 2  s.co  m*/
        try {
            group = this.peer.createNewGroup(this.groupName, "A test group.",
                    MultiplePeersTestCaseLauncher.KEYSTORE_PASSWORD,
                    MultiplePeersTestCaseLauncher.GROUP_PASSWORD);
        } catch (Exception e) {
            System.out.println(this.peerName + " : Thread Failed. Stopping.");
            e.printStackTrace();
            //Assert.fail("Failed to crete group: " + e.getMessage());

            synchronized (MultiplePeersTestCaseLauncher.GROUP_ADV_LOCK) {
                // notify other peers that the group adv will not be published.
                MultiplePeersTestCaseLauncher.GROUP_ADV_LOCK.notifyAll();
            }

            // stop this thread
            this.fail("Failed to create group: " + e.getMessage());
            /*synchronized (MultiplePeersTestCaseLauncher.MAIN_THREAD_LOCK) {
            // notify main thread not to wait for this thread anymore.
            MultiplePeersTestCaseLauncher.MAIN_THREAD_LOCK.notifyAll();
            }
                    
            return;*/
        }

        System.out.println(this.peerName + " : group created. : " + group.getPeerGroupName());

        synchronized (MultiplePeersTestCaseLauncher.GROUP_ADV_LOCK) {
            // notify other peers that the group adv has been published.
            MultiplePeersTestCaseLauncher.GROUP_ADV_LOCK.notifyAll();
            System.out.println(this.peerName + " : Listeners notified.");
        }

    } else {
        PeerGroupAdvertisement joinGroupAdv = this.searchForGroup(this.groupName);

        System.out.println(this.peerName + " : Joining group.");

        PeerGroup group = null;
        try {
            group = this.peer.joinPeerGroup(joinGroupAdv, MultiplePeersTestCaseLauncher.KEYSTORE_PASSWORD,
                    MultiplePeersTestCaseLauncher.GROUP_PASSWORD, false);
        } catch (Exception e) {
            e.printStackTrace();
            this.fail(e.getMessage());
        }

        if (this.peer.isGroupRendezVous()) {
            this.fail("Failed to contact existing group rendezvous.");
        }

        System.out.println(this.peerName + " : Joied group " + group.getPeerGroupName() + ".");

        int numberOfPipeAdvs = 0;
        for (int i = 0; i < 3; i++) {
            System.out.println(this.peerName + " : Try " + i + " to discover pipeAdv");
            List<Advertisement> pipeAdvs = Collections
                    .list(peer.getKnownDirectCommunicationPipeAdvertisements());
            System.out.println(this.peerName + " : pipeAdvs :\n" + pipeAdvs);
            numberOfPipeAdvs = pipeAdvs.size();
            System.out.println("Found " + numberOfPipeAdvs + " PipeAdvertisements");
            if (numberOfPipeAdvs == 1) {
                break;
            }

            try {
                Thread.sleep(15000);
            } catch (InterruptedException ignore) {
            }
        }

        if (numberOfPipeAdvs != 1) {
            this.fail("Expecting 1 pipe Adv, actual: " + numberOfPipeAdvs);
        }

        this.pass();
    }

    System.out.println(this.peerName + " : Thread finished.");
}

From source file:net.sourceforge.processdash.ui.web.psp.TimeLogPhaseWaterfallChart.java

private List getTimeLogEntries() {
    String path = getPrefix();/*ww w.  j  ava2 s  .c  om*/
    TimeLog tl = getDashboardContext().getTimeLog();
    List result;
    try {
        result = Collections.list(tl.filter(path, null, null));
        Collections.sort(result);
    } catch (IOException e) {
        e.printStackTrace();
        result = Collections.EMPTY_LIST;
    }
    return result;
}

From source file:de.berlios.gpon.wui.actions.data.ItemSearchAction.java

private void addAssociatedProperties(List idMapped, HashMap associatedPropertyMap) {

    // build up a pathDigest -> ipd-List mapping
    final Hashtable pathAndProperties = new Hashtable();

    CollectionUtils.forAllDo(associatedPropertyMap.keySet(), new Closure() {
        // foreach key in associatedPropertyMap do:
        public void execute(Object o) {
            String key = (String) o;

            String[] keySplit = ItemSearchForm.splitAssociatedPropertyKey(key);

            String pathDigest = keySplit[0];
            String ipdId = keySplit[1];

            if (!pathAndProperties.containsKey(pathDigest)) {
                pathAndProperties.put(pathDigest, new ArrayList());
            }//from www .  j  av a 2 s  .  c  o  m

            ((List) pathAndProperties.get(pathDigest)).add(new Long(ipdId));
        }
    });

    final String[] digests = (String[]) Collections.list(pathAndProperties.keys()).toArray(new String[0]);

    final PathResolver pathResolver = (PathResolver) getObjectForBeanId("pathResolver");

    CollectionUtils.forAllDo(idMapped, new Closure() {

        public void execute(Object o) {

            ItemMap im = (ItemMap) o;

            // foreach digest

            for (int digIdx = 0; digIdx < digests.length; digIdx++) {
                String digest = digests[digIdx];

                Set items = pathResolver.getItemsForPath(im.getItem().getId(), digest);

                if (items != null && items.size() > 0) {
                    if (items.size() > 1) {
                        throw new RuntimeException("more than one associated item found");
                    }

                    // get one & only item
                    Item item = ((Item[]) items.toArray(new Item[0]))[0];

                    Long[] ipds = (Long[]) ((List) pathAndProperties.get(digest)).toArray(new Long[0]);

                    ItemMappedById associatedImbi = new ItemMappedById(item);

                    for (int ipdIdx = 0; ipdIdx < ipds.length; ipdIdx++) {
                        Value value = associatedImbi.getValueObject(ipds[ipdIdx] + "");

                        if (value != null) {
                            im.addAdditionalAttribute(digest + "|" + ipds[ipdIdx], value);
                        }
                    }
                }
            }

        }
    });
}

From source file:org.reprap.configuration.store.ConfigurationInitializer.java

private static void copyJarTree(final URL source, final File target) throws IOException {
    final JarURLConnection jarConnection = (JarURLConnection) source.openConnection();
    final String prefix = jarConnection.getEntryName();
    final JarFile jarFile = jarConnection.getJarFile();
    for (final JarEntry jarEntry : Collections.list(jarFile.entries())) {
        final String entryName = jarEntry.getName();
        if (entryName.startsWith(prefix)) {
            if (!jarEntry.isDirectory()) {
                final String fileName = StringUtils.removeStart(entryName, prefix);
                final InputStream fileStream = jarFile.getInputStream(jarEntry);
                try {
                    FileUtils.copyInputStreamToFile(fileStream, new File(target, fileName));
                } finally {
                    fileStream.close();// ww w.java2  s .  c  o  m
                }
            }
        }
    }
}