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:eu.planets_project.tb.gui.backing.ListExp.java

public Collection<Experiment> getAllExpApproved() {
    TestbedManager testbedMan = (TestbedManager) JSFUtil.getManagedObject("TestbedManager");
    Collection<Experiment> allExps = testbedMan
            .getAllExperimentsAtPhase(ExperimentPhase.PHASE_EXPERIMENTEXECUTION);
    currExps = Collections.list(Collections.enumeration(allExps));
    sort(getSort(), isAscending());/* w ww  . java  2 s.  co  m*/
    return currExps;
}

From source file:hudson.remoting.RegExpBenchmark.java

private List<String> getAllRTClasses() throws Exception {
    List<String> classes = new ArrayList<String>();
    // Object.class.getProtectionDomain().getCodeSource() returns null :(
    String javaHome = System.getProperty("java.home");
    JarFile jf = new JarFile(javaHome + "/lib/rt.jar");
    for (JarEntry je : Collections.list(jf.entries())) {
        if (!je.isDirectory() && je.getName().endsWith(".class")) {
            String name = je.getName().replace('/', '.');
            // remove the .class
            name = name.substring(0, name.length() - 6);
            classes.add(name);//from w ww .j a  va 2  s  .com
        }
    }
    jf.close();
    // add in a couple from xalan and commons just for testing...
    classes.add(new String("org.apache.commons.collections.functors.EvilClass"));
    classes.add(new String("org.codehaus.groovy.runtime.IWIllHackYou"));
    classes.add(new String("org.apache.xalan.YouAreOwned"));
    return classes;
}

From source file:com.idega.slide.util.WebdavLocalResource.java

@SuppressWarnings("deprecation")
private Enumeration<LocalResponse> propfindMethod(NodeRevisionDescriptor descriptor)
        throws HttpException, IOException {
    if (descriptor == null) {
        return null;
    }//  ww w . j a v a  2s  . c o m

    if (properties != null) {
        return properties;
    }

    try {
        Vector<LocalResponse> responses = new Vector<LocalResponse>();
        LocalResponse response = new LocalResponse();
        response.setHref(getPath());
        responses.add(response);

        @SuppressWarnings("unchecked")
        List<NodeProperty> nodeProperties = Collections.list(descriptor.enumerateProperties());
        List<Property> properties = new ArrayList<Property>();
        for (NodeProperty p : nodeProperties) {
            String localName = p.getPropertyName().getName();
            Property property = null;

            if (localName.equals(RESOURCETYPE)) {
                Object oValue = p.getValue();
                String value = oValue == null ? null : oValue.toString();

                Element element = null;
                if ("<collection/>".equals(value)) {
                    element = getCollectionElement();
                } else if (CoreConstants.EMPTY.equals(value)) {
                    element = getEmptyElement();
                } else {
                    Document doc = XmlUtil.getDocumentBuilder().newDocument();
                    String namespace = p.getNamespace();
                    String tagName = p.getName();
                    element = doc.createElementNS(namespace, tagName);
                    element.appendChild(doc.createTextNode(value));
                }

                property = new ResourceTypeProperty(response, element);
            } else if (localName.equals(LOCKDISCOVERY)) {
                /*DocumentBuilderFactory factory =
                 DocumentBuilderFactory.newInstance();
                 factory.setNamespaceAware(true);
                 DocumentBuilder builder = factory.newDocumentBuilder();
                 Document doc = builder.newDocument();
                 Element element = doc.createElement("collection");
                 property = new LockDiscoveryProperty(response,element);*/
                throw new RuntimeException("LockDiscoveryProperty not yet implemented for: " + getPath());
            } else if (CREATIONDATE.equals(localName)) {
                setCreationDate((String) p.getValue());
            } else if (GETLASTMODIFIED.equals(localName)) {
                setGetLastModified((String) p.getValue());
            } else {
                LocalProperty lProperty = new LocalProperty(response);
                property = lProperty;
                lProperty.setName(p.getName());
                lProperty.setNamespaceURI(p.getNamespace());
                lProperty.setLocalName(p.getName());
                Object oValue = p.getValue();
                String value = oValue == null ? null : oValue.toString();
                lProperty.setPropertyAsString(value);
            }

            if (property != null) {
                properties.add(property);
            }
        }

        if (!ListUtil.isEmpty(properties)) {
            response.setProperties(new Vector<Property>(properties));
        }

        this.properties = responses.elements();
        if (this.properties != null) {
            setProperties(3, 0); //   Need to set basic properties
        }

        return this.properties;
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Error getting properties for: " + getPath() + ": " + e.getMessage(), e);

        if (e instanceof ObjectNotFoundException) {
            getSlideAPI().deletetDefinitionFile(((ObjectNotFoundException) e).getObjectUri());

            HttpException he = new HttpException("Resource on path: " + getPath() + " not found");
            he.setReasonCode(WebdavStatus.SC_NOT_FOUND);
            throw he;
        } else if (e instanceof RevisionDescriptorNotFoundException) {
            getSlideAPI().deletetDefinitionFile(((RevisionDescriptorNotFoundException) e).getObjectUri());
        }

        return null;
    }
}

From source file:com.netflix.spinnaker.clouddriver.google.controllers.GoogleNamedImageLookupController.java

private static Map<String, String> extractTagFilters(HttpServletRequest httpServletRequest) {
    List<String> parameterNames = Collections.list(httpServletRequest.getParameterNames());

    return parameterNames.stream().filter(Objects::nonNull)
            .filter(parameter -> parameter.toLowerCase().startsWith("tag:"))
            .collect(Collectors.toMap(tagParameter -> tagParameter.replaceAll("tag:", "").toLowerCase(),
                    httpServletRequest::getParameter, (a, b) -> b));
}

From source file:cpw.mods.fml.server.FMLServerHandler.java

private void searchZipForENUSLanguage(File source) throws IOException {
    ZipFile zf = new ZipFile(source);
    for (ZipEntry ze : Collections.list(zf.entries())) {
        Matcher matcher = assetENUSLang.matcher(ze.getName());
        if (matcher.matches()) {
            FMLLog.fine("Injecting found translation data in zip file %s at %s into language system",
                    source.getName(), ze.getName());
            StringTranslate.inject(zf.getInputStream(ze));
        }/*from w ww  .  ja  v  a2s .  co  m*/
    }
    zf.close();
}

From source file:com.google.appinventor.components.runtime.BlockyTalky.java

private static String getIPAddress(boolean useIPv4) {
    try {/*from ww w .  jav  a 2 s. c o  m*/
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
            for (InetAddress addr : addrs) {
                if (!addr.isLoopbackAddress()) {
                    String sAddr = addr.getHostAddress().toUpperCase();
                    boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
                    if (useIPv4) {
                        if (isIPv4)
                            return sAddr;
                    } else {
                        if (!isIPv4) {
                            int delim = sAddr.indexOf('%'); // drop ip6 port suffix
                            return delim < 0 ? sAddr : sAddr.substring(0, delim);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
}

From source file:org.tonguetied.web.servlet.ServletContextInitializer.java

/**
 * Create the list of supported languages used by the web front end and add
 * as a application scope variable./*from   ww w  .j a v a 2  s .  c  om*/
 * 
 * @param context the {@linkplain ServletContext} to add the list of 
 * languages
 */
private void loadSupportedLanguages(ServletContext context) {
    // read language.properties
    if (logger.isInfoEnabled())
        logger.info("loading resources from file: " + LANGUAGE_PROPERTIES);
    final ResourceBundle bundle = ResourceBundle.getBundle(LANGUAGE_PROPERTIES);
    Set<String> languageKeys = new TreeSet<String>(Collections.list(bundle.getKeys()));
    if (languageKeys.isEmpty()) {
        logger.warn("Resource file " + LANGUAGE_PROPERTIES + ".properties contains no entries");
        languageKeys.add(Locale.ENGLISH.getLanguage());
    }

    context.setAttribute(KEY_SUPPORTED_LANGUAGES, languageKeys);
}

From source file:it.greenvulcano.gvesb.adapter.http.mapping.ForwardHttpServletMapping.java

@SuppressWarnings("deprecation")
@Override/* w  ww . ja  va2  s  .  co  m*/
public void handleRequest(String methodName, HttpServletRequest req, HttpServletResponse resp)
        throws InboundHttpResponseException {

    logger.debug("BEGIN forward: " + req.getRequestURI());

    final HttpURLConnection httpConnection = (HttpURLConnection) connection;
    ;

    try {

        httpConnection.setRequestMethod(methodName);
        httpConnection.setReadTimeout(soTimeout);
        httpConnection.setDoInput(true);
        httpConnection.setDoOutput(true);

        if (dump) {
            StringBuffer sb = new StringBuffer();
            DumpUtils.dump(req, sb);
            logger.info(sb.toString());
        }

        String mapping = req.getPathInfo();
        if (mapping == null) {
            mapping = "/";
        }
        String destPath = contextPath + mapping;
        String queryString = req.getQueryString();
        if (queryString != null) {
            destPath += "?" + queryString;
        }
        if (!destPath.startsWith("/")) {
            destPath = "/" + destPath;
        }
        logger.info("Resulting QueryString: " + destPath);

        Collections.list(req.getHeaderNames()).forEach(headerName -> {
            httpConnection.setRequestProperty(headerName,
                    Collections.list(req.getHeaders(headerName)).stream().collect(Collectors.joining(";")));
        });

        if (methodName.equalsIgnoreCase("POST") || methodName.equalsIgnoreCase("PUT")) {
            httpConnection.setDoOutput(true);
            IOUtils.copy(req.getInputStream(), httpConnection.getOutputStream());

        }

        httpConnection.connect();
        int status = httpConnection.getResponseCode();

        resp.setStatus(status, httpConnection.getResponseMessage());

        httpConnection.getHeaderFields().entrySet().stream().forEach(header -> {
            resp.addHeader(header.getKey(), header.getValue().stream().collect(Collectors.joining(";")));
        });

        ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
        IOUtils.copy(httpConnection.getInputStream(), bodyOut);

        OutputStream out = resp.getOutputStream();
        out.write(bodyOut.toByteArray());
        //IOUtils.copy(method.getResponseBodyAsStream(), out);
        out.flush();
        out.close();

        if (dump) {
            StringBuffer sb = new StringBuffer();
            DumpUtils.dump(resp, bodyOut, sb);
            logger.info(sb.toString());
        }

    } catch (Exception exc) {
        logger.error("ERROR on forwarding: " + req.getRequestURI(), exc);
        throw new InboundHttpResponseException("GV_CALL_SERVICE_ERROR",
                new String[][] { { "message", exc.getMessage() } }, exc);
    } finally {
        try {
            if (httpConnection != null) {
                httpConnection.disconnect();
            }
        } catch (Exception exc) {
            logger.warn("Error while releasing connection", exc);
        }
        logger.debug("END forward: " + req.getRequestURI());
    }
}

From source file:org.ado.minesync.commons.ZipArchiverTest.java

private List<? extends ZipEntry> getZipEntryList(ZipFile zipFile) {
    List<? extends ZipEntry> list = Collections.list(zipFile.entries());
    System.out.println(list);//from w  ww  .ja  v a 2s .c  o m
    return list;
}

From source file:net.straylightlabs.archivo.controller.TelemetryController.java

public static String getAddressesAsString(NetworkInterface nic) {
    StringJoiner sj = new StringJoiner(", ");
    for (InetAddress address : Collections.list(nic.getInetAddresses())) {
        sj.add(address.getHostAddress());

    }/*from  www  .j  a  v  a  2 s.  c o m*/
    return sj.toString();
}