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.epam.cme.storefront.filters.StorefrontFilter.java

protected void initDefaults(final HttpServletRequest request) {
    final StoreSessionFacade storeSessionFacade = getStoreSessionFacade();
    storeSessionFacade.initializeSession(Collections.list(request.getLocales()));
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.security.SamlValidator.java

@Override
public void validate(ConfigProblemSetBuilder p, Saml saml) {
    if (!saml.isEnabled()) {
        return;//from  w  ww  .  j a v  a  2s  . c o  m
    }

    if (StringUtils.isEmpty(saml.getMetadataLocal()) && StringUtils.isEmpty(saml.getMetadataRemote())) {
        p.addProblem(Problem.Severity.ERROR, "No metadata file specified.");
    }

    if (StringUtils.isNotEmpty(saml.getMetadataLocal())) {
        try {
            new File(new URI("file:" + saml.getMetadataLocal()));
        } catch (Exception f) {
            p.addProblem(Problem.Severity.ERROR, f.getMessage());
        }
    }

    if (StringUtils.isNotEmpty(saml.getMetadataRemote())) {
        try {
            HttpClientBuilder.create().build().execute(new HttpGet(saml.getMetadataRemote()));
        } catch (IOException e) {
            p.addProblem(Problem.Severity.WARNING, "Cannot access remote metadata.xml file: " + e.getMessage());
        }
    }

    if (StringUtils.isEmpty(saml.getIssuerId())) {
        p.addProblem(Problem.Severity.ERROR, "No issuerId specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStore())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStorePassword())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore password specified.");
    }

    if (StringUtils.isEmpty(saml.getKeyStoreAliasName())) {
        p.addProblem(Problem.Severity.ERROR, "No keystore alias specified.");
    }

    InputStream is = null;
    try {
        File f = new File(new URI("file:" + saml.getKeyStore()));
        is = new FileInputStream(f);
        val keystore = KeyStore.getInstance(KeyStore.getDefaultType());

        // will throw an exception if `keyStorePassword` is invalid
        keystore.load(is, saml.getKeyStorePassword().toCharArray());

        Collections.list(keystore.aliases()).stream()
                .filter(alias -> alias.equalsIgnoreCase(saml.getKeyStoreAliasName())).findFirst()
                .orElseThrow(() -> new RuntimeException(
                        "Keystore does not contain alias " + saml.getKeyStoreAliasName()));

    } catch (Exception e) {
        p.addProblem(Problem.Severity.ERROR, "Keystore validation problem: " + e.getMessage());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (Exception e) {
                // ignored.
            }
        }
    }

    if (saml.getServiceAddress() == null) {
        p.addProblem(Problem.Severity.ERROR, "No service address specified.");
    } else if (!saml.getServiceAddress().getProtocol().equalsIgnoreCase("https")) {
        p.addProblem(Problem.Severity.WARNING, "Gate should operate on HTTPS");
    }
}

From source file:org.drugis.mtc.gui.results.ResultsComponentFactory.java

private static JTable createTableWithoutHeaders(NetworkRelativeEffectTableModel dm) {
    final JTable table = new JTable(dm);
    table.setTableHeader(null);//  www.j a va 2 s.  c om
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    for (final TableColumn c : Collections.list(table.getColumnModel().getColumns())) {
        c.setMinWidth(170);
        c.setPreferredWidth(170);
    }

    TableCopyHandler.registerCopyAction(table);
    return table;
}

From source file:com.acc.storefront.filters.StorefrontFilter.java

protected void initDefaults(final HttpServletRequest request) {
    final StoreSessionFacade storeSessionFacade = getStoreSessionFacade();

    storeSessionFacade.initializeSession(Collections.list((Enumeration<Locale>) request.getLocales()));
}

From source file:org.apache.james.transport.mailets.LogMessage.java

@SuppressWarnings("unchecked")
private void logHeaders(MimeMessage message) throws MessagingException {
    if (headers) {
        log("\n");
        for (String header : Collections.list((Enumeration<String>) message.getAllHeaderLines())) {
            log(header + "\n");
        }/*from  w  w w  .ja  va 2  s  .  co  m*/
    }
}

From source file:org.ebayopensource.turmeric.runtime.tests.common.jetty.DebugHandler.java

private void logRequest(Request request) {
    String ln = SystemUtils.LINE_SEPARATOR;

    StringBuilder dbg = new StringBuilder();

    dbg.append(ln).append(" Method: ").append(request.getMethod());
    dbg.append(ln).append(" Request URI: ").append(request.getRequestURI());
    if (request.getQueryString() != null) {
        dbg.append("?").append(request.getQueryString());
    }//w w  w. j  a  va  2  s .  c o m

    @SuppressWarnings("unchecked")
    List<String> headerNames = Collections.list(request.getHeaderNames());
    dbg.append(ln).append(" HTTP Request Headers (").append(headerNames.size()).append(")");
    for (String name : headerNames) {
        dbg.append(ln).append("  ").append(name).append(": ");
        dbg.append(request.getHeader(name));
    }

    @SuppressWarnings("unchecked")
    List<String> paramNames = Collections.list(request.getParameterNames());
    dbg.append(ln).append(" Request Parameters (").append(paramNames.size()).append(")");
    for (String name : paramNames) {
        dbg.append(ln).append("  ").append(name).append(" = ");
        dbg.append(request.getParameter(name));
    }

    Log.info("Request: " + dbg.toString());
}

From source file:com.DPFaragir.DPFUtils.java

public static String getMACAddress(String interfaceName) {
    try {/*www  .  j  a v  a2 s  .  c o m*/
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                return "";
            StringBuilder buf = new StringBuilder();
            for (int idx = 0; idx < mac.length; idx++)
                buf.append(String.format("%02X:", mac[idx]));
            if (buf.length() > 0)
                buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
    /*try {
    // this is so Linux hack
    return loadFileAsString("/sys/class/net/" +interfaceName + "/address").toUpperCase().trim();
    } catch (IOException ex) {
    return null;
    }*/
}

From source file:psiprobe.tools.ApplicationUtils.java

/**
 * Creates Application instance from Tomcat Context object. If ResourceResolver is passed the
 * method will also collect additional information about the application such as session count,
 * session attribute count, application attribute count, servlet count, servlet stats summary and
 * datasource usage summary. Collecting additional information can be CPU intensive and time
 * consuming so this should be avoided unless absolutely required. Some datasource implementations
 * (c3p0) are known to be prone to internal deadlocks, so this method can also hang is datasource
 * usage stats is to be collected./*  w w w. j a  v  a2 s  . co m*/
 *
 * @param context the context from which to create the Application
 * @param resourceResolver the resolver to use for resources associated with the given context
 * @param calcSize flag which controls whether to calculate session size
 * @param containerWrapper the wrapper for the context's root containing server
 * @return Application object
 */
public static Application getApplication(Context context, ResourceResolver resourceResolver, boolean calcSize,
        ContainerWrapperBean containerWrapper) {

    // ContainerWrapperBean containerWrapper
    logger.debug("Querying webapp: {}", context.getName());

    Application app = new Application();
    app.setName(context.getName().length() > 0 ? context.getName() : "/");
    app.setDocBase(context.getDocBase());
    app.setDisplayName(context.getDisplayName());

    app.setAvailable(containerWrapper.getTomcatContainer().getAvailable(context));
    app.setDistributable(context.getDistributable());
    app.setSessionTimeout(context.getSessionTimeout());
    app.setServletVersion(context.getServletContext().getMajorVersion() + "."
            + context.getServletContext().getMinorVersion());

    if (resourceResolver != null) {
        logger.debug("counting servlet attributes");

        app.setContextAttributeCount(Collections.list(context.getServletContext().getAttributeNames()).size());

        if (app.isAvailable()) {
            logger.debug("collecting session information");

            app.setSessionCount(context.getManager().findSessions().length);

            boolean serializable = true;
            int sessionAttributeCount = 0;
            long size = 0;

            for (Session session : context.getManager().findSessions()) {
                ApplicationSession appSession = getApplicationSession(session, calcSize, false);
                if (appSession != null) {
                    sessionAttributeCount += appSession.getObjectCount();
                    serializable = serializable && appSession.isSerializable();
                    size += appSession.getSize();
                }
            }
            app.setSerializable(serializable);
            app.setSessionAttributeCount(sessionAttributeCount);
            app.setSize(size);
        }

        logger.debug("aggregating servlet stats");

        collectApplicationServletStats(context, app);

        if (resourceResolver.supportsPrivateResources() && app.isAvailable()) {
            int[] scores = getApplicationDataSourceUsageScores(context, resourceResolver, containerWrapper);
            app.setDataSourceBusyScore(scores[0]);
            app.setDataSourceEstablishedScore(scores[1]);
        }
    }

    return app;
}

From source file:com.exxonmobile.ace.hybris.storefront.filters.StorefrontFilter.java

protected void initDefaults(final HttpServletRequest request) {
    final StoreSessionFacade storeSessionFacade = getStoreSessionFacade();

    storeSessionFacade.initializeSession(Collections.list(request.getLocales()));
}

From source file:com.rincliu.library.util.RLNetUtil.java

/**
 * Returns MAC address of the given interface name.
 * /*ww w. j  ava 2s . c  o m*/
 * @param interfaceName eth0, wlan0 or NULL=use first interface
 * @return mac address or empty string
 */
public static String getMACAddress(String interfaceName) {
    try {
        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface intf : interfaces) {
            if (interfaceName != null) {
                if (!intf.getName().equalsIgnoreCase(interfaceName))
                    continue;
            }
            byte[] mac = intf.getHardwareAddress();
            if (mac == null)
                return "";
            StringBuilder buf = new StringBuilder();
            for (int idx = 0; idx < mac.length; idx++)
                buf.append(String.format("%02X:", mac[idx]));
            if (buf.length() > 0)
                buf.deleteCharAt(buf.length() - 1);
            return buf.toString();
        }
    } catch (Exception ex) {
    } // for now eat exceptions
    return "";
    // try
    // { // this is so Linux hack return
    // loadFileAsString("/sys/class/net/" + interfaceName +
    // "/address").toUpperCase().trim();
    // }
    // catch (IOException e)
    // {
    // e.printStackTrace();
    // return null;
    // }
}