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:org.sonar.server.authentication.SsoAuthenticator.java

private static Map<String, String> getHeaders(HttpServletRequest request) {
    Map<String, String> headers = new HashMap<>();
    Collections.list(request.getHeaderNames())
            .forEach(header -> headers.put(header.toLowerCase(Locale.ENGLISH), request.getHeader(header)));
    return headers;
}

From source file:org.auraframework.http.AuraContextFilter.java

protected AuraContext startContext(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) req;

    Format f = format.get(request);
    Authentication a = access.get(request, Authentication.AUTHENTICATED);

    Map<String, Object> configMap = getConfigMap(request);
    Mode m = getMode(request, configMap);
    boolean d = getDebugToolParam(request);

    DefDescriptor<? extends BaseComponentDef> appDesc = getAppParam(request, configMap);

    if (componentDir != null) {
        System.setProperty("aura.componentDir", componentDir);
    }// w ww  .  j  ava 2  s  .co m
    //
    // FIXME: our usage of format should be revisited. Most URLs have
    // a fixed format, so we should have a way of getting that.
    //
    if (f == null) {
        if ("GET".equals(request.getMethod())) {
            f = Format.HTML;
        } else {
            f = Format.JSON;
        }
    }
    AuraContext context = Aura.getContextService().startContext(m, f, a, appDesc, d);

    String contextPath = request.getContextPath();
    // some appservers (like tomcat) use "/" as the root path, others ""
    if ("/".equals(contextPath)) {
        contextPath = "";
    }
    context.setContextPath(contextPath);
    context.setNum(num.get(request));
    context.setRequestedLocales(Collections.list(request.getLocales()));
    context.setClient(new Client(request.getHeader(HttpHeaders.USER_AGENT)));
    if (configMap != null) {
        getLoaded(context, configMap.get("loaded"));
        @SuppressWarnings("unchecked")
        List<Object> dns = (List<Object>) configMap.get("dn");
        if (dns != null) {
            for (Object dn : dns) {
                context.addDynamicNamespace((String) dn);
            }
        }
        context.setFrameworkUID((String) configMap.get("fwuid"));

        @SuppressWarnings("unchecked")
        List<String> themes = (List<String>) configMap.get("themes");
        if (themes != null) {
            try {
                DefinitionService ds = Aura.getDefinitionService();
                for (String theme : themes) {
                    context.appendThemeDescriptor(ds.getDefDescriptor(theme, ThemeDef.class));
                }
            } catch (QuickFixException e) {
                throw new AuraRuntimeException(e);
            }
        }
    }

    if (!isProduction) {
        TestContextAdapter testContextAdapter = Aura.get(TestContextAdapter.class);
        if (testContextAdapter != null) {
            String testName = null;
            // config takes precedence over param because the value is not expected to change during a test and it
            // is less likely to have been modified unintentionally when from the config
            if (configMap != null) {
                testName = (String) configMap.get("test");
            }
            if (testName == null) {
                testName = test.get(request);
            }
            if (testName != null) {
                TestContext testContext = testContextAdapter.getTestContext(testName);
                if (testContext != null) {
                    MasterDefRegistry registry = context.getDefRegistry();
                    Set<Definition> mocks = testContext.getLocalDefs();
                    if (mocks != null) {
                        boolean doReset = testReset.get(request);
                        for (Definition def : mocks) {
                            if (doReset && def instanceof Resettable) {
                                ((Resettable) def).reset();
                            }
                            registry.addLocalDef(def);
                        }
                    }
                }
            } else {
                testContextAdapter.clear();
            }
        }
    }

    return context;
}

From source file:com.seleuco.mame4droid.NetPlay.java

public String getIPAddress() {
    try {//from   w ww.  j  av a  2s  .c  om
        Enumeration<NetworkInterface> ifaceList;
        NetworkInterface selectedIface = null;

        // First look for a WLAN interface
        ifaceList = NetworkInterface.getNetworkInterfaces();
        while (selectedIface == null && ifaceList.hasMoreElements()) {
            NetworkInterface intf = ifaceList.nextElement();
            if (intf.getName().startsWith("wlan")) {
                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 (isIPv4)
                            return sAddr;
                    }
                }
            }
        }

        // If we didn't find that, look for an Ethernet interface
        ifaceList = NetworkInterface.getNetworkInterfaces();
        while (selectedIface == null && ifaceList.hasMoreElements()) {
            NetworkInterface intf = ifaceList.nextElement();
            if (intf.getName().startsWith("eth")) {
                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 (isIPv4)
                            return sAddr;
                    }
                }
            }
        }

        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 (isIPv4)
                        return sAddr;
                }
            }
        }
    } catch (Exception ex) {
    }
    return null;
}

From source file:edu.ku.brc.af.ui.forms.ViewSetMgr.java

/**
 * Returns a list of all the ViewSets// ww  w . j  a  v a 2  s  .  c o m
 * @return a list of all the ViewSets
 */
public List<ViewSetIFace> getViewSets() {
    return Collections.list(viewsHash.elements());
}

From source file:ninja.servlet.ContextImpl.java

@Override
public Map<String, List<String>> getHeaders() {
    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    Enumeration<String> names = httpServletRequest.getHeaderNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        headers.put(name, Collections.list(httpServletRequest.getHeaders(name)));
    }/*from   w w w. j  av  a  2  s.c  om*/
    return headers;
}

From source file:com.dmsl.anyplace.utils.NetworkUtils.java

public static String getLocalIP(boolean useIPv4) {
    String ip = "No Local IP assigned";
    try {/* w w w .j a  v a2  s .  c o m*/

        List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (NetworkInterface ni : interfaces) {
            List<InetAddress> addresses = Collections.list(ni.getInetAddresses());
            for (InetAddress ia : addresses) {
                if (ia != null && !ia.isLoopbackAddress()) {
                    String sAddr = ia.getHostAddress().toUpperCase(Locale.ENGLISH);
                    boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
                    if (useIPv4) {
                        if (isIPv4) {
                            ip = sAddr;
                        }
                    } else {
                        if (!isIPv4) {
                            int delim = sAddr.indexOf('%');
                            ip = delim < 0 ? sAddr : sAddr.substring(0, delim);
                        }
                    }
                }
            }
        }
    } catch (Exception ex) {
        ip = "Unknown Error, Report it!";
    }
    return ip;
}

From source file:jenkins.metrics.api.MetricsRootAction.java

/**
 * Utility method to check if the request has an authorization key in the header.
 *
 * @param req the request./*  w w  w.  j av a 2s  . co m*/
 * @return the authorization key or {@code null}.
 */
@CheckForNull
private static String getKeyFromAuthorizationHeader(@NonNull StaplerRequest req) {
    for (Object o : Collections.list(req.getHeaders("Authorization"))) {
        if (o instanceof String && ((String) o).startsWith("Jenkins-Metrics-Key ")) {
            return Util.fixEmptyAndTrim(((String) o).substring("Jenkins-Metrics-Key ".length()));
        }
    }
    return null;
}

From source file:com.hypersocket.netty.NettyServer.java

protected void bindInterface(Integer port, Set<Channel> channels) throws IOException {

    Enumeration<NetworkInterface> e = NetworkInterface.getNetworkInterfaces();

    Set<String> interfacesToBind = new HashSet<String>(
            Arrays.asList(configurationService.getValues("listening.interfaces")));

    if (interfacesToBind.isEmpty()) {

        if (log.isInfoEnabled()) {
            log.info("Binding server to all interfaces on port " + port);
        }/*from www. j  ava2  s .  co  m*/
        Channel ch = serverBootstrap.bind(new InetSocketAddress(port));
        channels.add(ch);

        if (log.isInfoEnabled()) {
            log.info("Bound to port " + ((InetSocketAddress) ch.getLocalAddress()).getPort());
        }
    } else {
        while (e.hasMoreElements()) {

            NetworkInterface i = e.nextElement();

            Enumeration<InetAddress> inetAddresses = i.getInetAddresses();

            for (InetAddress inetAddress : Collections.list(inetAddresses)) {

                if (interfacesToBind.contains(inetAddress.getHostAddress())) {
                    try {
                        if (log.isInfoEnabled()) {
                            log.info("Binding server to interface " + i.getDisplayName() + " "
                                    + inetAddress.getHostAddress() + ":" + port);
                        }

                        Channel ch = serverBootstrap.bind(new InetSocketAddress(inetAddress, port));
                        channels.add(ch);

                        if (log.isInfoEnabled()) {
                            log.info("Bound to " + inetAddress.getHostAddress() + ":"
                                    + ((InetSocketAddress) ch.getLocalAddress()).getPort());
                        }

                    } catch (ChannelException ex) {
                        log.error("Failed to bind port", ex);
                    }
                }
            }
        }
    }
}

From source file:org.openrepose.filters.authz.RequestAuthorizationHandler.java

private boolean adminRoleMatchIgnoringCase(Enumeration<String> roleStringList) {
    List<String> roles = Collections.list(roleStringList);
    if (!roles.isEmpty()) {
        for (String ignoreTenantRole : ignoreTenantRoles) {
            for (String role : roles) {
                if (ignoreTenantRole.equalsIgnoreCase(role)) {
                    return true;
                }// w w w  . j  av a2  s  .  c  o m
            }
        }
    }
    return false;
}