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:otsopack.commons.network.coordination.spacemanager.HttpSpaceManager.java

public static String getIpAddress() {
    try {//ww  w  .jav  a2  s  .  c om
        final Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces();
        for (NetworkInterface netIf : Collections.list(nets)) {
            // If the network is active
            if (isUp(netIf)) {
                Enumeration<InetAddress> addresses = netIf.getInetAddresses();
                for (InetAddress addr : Collections.list(addresses))
                    // If the IP address is IPv4 and it's not the local address, store it
                    if (addr.getAddress().length == 4 && !addr.isLoopbackAddress())
                        return addr.getHostAddress();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.gnut3ll4.android.basicandroidkeystore.MainActivity.java

public ArrayList<String> getAliases()
        throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
    KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");

    keyStore.load(null, null);/*from   w w  w.  j  av  a 2 s  .  com*/

    return Collections.list(keyStore.aliases());
}

From source file:org.apache.hadoop.hdfs.server.namenode.TestAuditLogs.java

@Before
public void setupCluster() throws Exception {
    // must configure prior to instantiating the namesystem because it
    // will reconfigure the logger if async is enabled
    configureAuditLogs();/*from  w ww  .  j av  a 2s.c  om*/
    conf = new HdfsConfiguration();
    final long precision = 1L;
    conf.setLong(DFSConfigKeys.DFS_NAMENODE_ACCESSTIME_PRECISION_KEY, precision);
    conf.setLong(DFSConfigKeys.DFS_BLOCKREPORT_INTERVAL_MSEC_KEY, 10000L);
    conf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
    conf.setBoolean(DFSConfigKeys.DFS_NAMENODE_AUDIT_LOG_ASYNC_KEY, useAsyncLog);
    util = new DFSTestUtil.Builder().setName("TestAuditAllowed").setNumFiles(20).build();
    cluster = new MiniDFSCluster.Builder(conf).numDataNodes(4).build();
    fs = cluster.getFileSystem();
    util.createFiles(fs, fileName);

    // make sure the appender is what it's supposed to be
    Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
    @SuppressWarnings("unchecked")
    List<Appender> appenders = Collections.list(logger.getAllAppenders());
    assertEquals(1, appenders.size());
    assertEquals(useAsyncLog, appenders.get(0) instanceof AsyncAppender);

    fnames = util.getFileNames(fileName);
    util.waitReplication(fs, fileName, (short) 3);
    userGroupInfo = UserGroupInformation.createUserForTesting(username, groups);
}

From source file:ca.uhn.fhir.rest.server.servlet.ServletRequestDetails.java

@Override
public List<String> getHeaders(String name) {
    Enumeration<String> headers = getServletRequest().getHeaders(name);
    return headers == null ? Collections.<String>emptyList()
            : Collections.list(getServletRequest().getHeaders(name));
}

From source file:org.eclipse.smarthome.binding.fsinternetradio.test.RadioServiceDummy.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String queryString = request.getQueryString();
    Collection<String> requestParameterNames = Collections.list(request.getParameterNames());
    if (queryString != null && requestParameterNames.contains(VALUE)) {
        StringBuffer fullUrl = request.getRequestURL().append("?").append(queryString);
        int value = Integer.parseInt(request.getParameter(VALUE));
        requestParameters.put(value, fullUrl.toString());
    }/*from  ww w  . j a  v a2 s. co  m*/

    String pin = request.getParameter("pin");
    if (!MOCK_RADIO_PIN.equals(pin)) {
        response.setStatus(HttpStatus.FORBIDDEN_403);
    } else if (!isOKAnswerExpected) {
        response.setStatus(HttpStatus.NOT_FOUND_404);
    } else {
        response.setStatus(HttpStatus.OK_200);
        response.setContentType("text/xml");
        String commandString = request.getPathInfo();

        switch (commandString) {
        case (REQUEST_SET_POWER):
            if (isInvalidValueExpected) {
                powerValue = null;
            } else {
                powerValue = request.getParameter(VALUE);
            }

        case (REQUEST_GET_POWER):
            powerTag = makeU8Tag(powerValue);
            tagToReturn = powerTag;
            break;

        case (REQUEST_SET_MUTE):
            if (isInvalidValueExpected) {
                muteValue = null;
            } else {
                muteValue = request.getParameter(VALUE);
            }

        case (REQUEST_GET_MUTE):
            muteTag = makeU8Tag(muteValue);
            tagToReturn = muteTag;
            break;

        case (REQUEST_SET_MODE):
            if (isInvalidValueExpected) {
                modeValue = null;
            } else {
                modeValue = request.getParameter(VALUE);
            }

        case (REQUEST_GET_MODE):
            modeTag = makeU32Tag(modeValue);
            tagToReturn = modeTag;
            break;

        case (REQUEST_SET_VOLUME):
            if (isInvalidValueExpected) {
                absoluteVolumeValue = null;
            } else {
                absoluteVolumeValue = request.getParameter(VALUE);
            }

        case (REQUEST_GET_VOLUME):
            absoluteVolumeTag = makeU8Tag(absoluteVolumeValue);
            tagToReturn = absoluteVolumeTag;
            break;

        case (REQUEST_SET_PRESET_ACTION):
            final String station = request.getParameter(VALUE);
            setRadioStation(station);
            break;

        case (REQUEST_GET_PLAY_INFO_NAME):
            tagToReturn = playInfoNameTag;
            break;

        case (REQUEST_GET_PLAY_INFO_TEXT):
            tagToReturn = playInfoTextTag;
            break;

        default:
            tagToReturn = "";
            break;
        }

        if (isInvalidResponseExpected) {
            responseToReturn = makeInvalidXMLResponse();
        } else {
            responseToReturn = makeValidXMLResponse();
        }
        PrintWriter out = response.getWriter();
        out.print(responseToReturn);
    }
}

From source file:net.centro.rtb.monitoringcenter.infos.NodeInfo.java

private static String detectLoadBalancerIpAddress() {
    Enumeration<NetworkInterface> networkInterfaces = null;
    try {/*from  w  w w  . j ava  2 s  . c om*/
        networkInterfaces = NetworkInterface.getNetworkInterfaces();
    } catch (SocketException e) {
        logger.debug("Unable to obtain network interfaces!", e);
        return null;
    }

    for (NetworkInterface networkInterface : Collections.list(networkInterfaces)) {
        boolean isLoopback = false;
        try {
            isLoopback = networkInterface.isLoopback();
        } catch (SocketException e) {
            logger.debug("Unable to identify if a network interface is a loopback or not");
            continue;
        }

        if (isLoopback) {
            Enumeration<InetAddress> inetAddresses = networkInterface.getInetAddresses();
            while (inetAddresses.hasMoreElements()) {
                InetAddress inetAddress = inetAddresses.nextElement();
                if (!inetAddress.isLoopbackAddress() && Inet4Address.class.isInstance(inetAddress)) {
                    return inetAddress.getHostAddress();
                }
            }
        }
    }

    return null;
}

From source file:org.apereo.portal.portlets.jsp.JspInvokerPortletController.java

private Map<String, List<String>> getPreferences(PortletRequest req) {
    Map<String, List<String>> rslt = new HashMap<String, List<String>>(); // default
    PortletPreferences prefs = req.getPreferences();
    List<String> names = Collections.list(prefs.getNames());
    for (String name : names) {
        if (!name.startsWith(CONTROLLER_PREFERENCE_PREFIX)) {
            // Pass it along in the model
            List<String> values = Arrays.asList(prefs.getValues(name, new String[] {}));
            rslt.put(name, values);//from   w  ww  .  j  av  a  2 s . co  m
        }
    }
    logger.debug("Invoking with preferences={}", rslt);
    return rslt;
}

From source file:org.kei.android.phone.cellhistory.towers.MobileNetworkInfo.java

/** Get IP For mobile */
public static String getMobileIP(final boolean useIPv4) {
    try {//from   w w  w.  j ava 2 s. co m
        final List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
        for (final NetworkInterface intf : interfaces) {
            final List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
            for (final InetAddress addr : addrs) {
                if (!addr.isLoopbackAddress()) {
                    final String sAddr = addr.getHostAddress().toUpperCase(Locale.US);
                    final boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr);
                    if (useIPv4) {
                        if (isIPv4)
                            return sAddr;
                    } else {
                        if (!isIPv4) {
                            final int delim = sAddr.indexOf('%'); // drop ip6 port suffix
                            return delim < 0 ? sAddr : sAddr.substring(0, delim);
                        }
                    }
                }
            }
        }
    } catch (final Exception ex) {
        Log.e(MobileNetworkInfo.class.getSimpleName(), "Exception in Get IP Address: " + ex.getMessage(), ex);
    }
    return TowerInfo.UNKNOWN;
}

From source file:org.apache.servicecomb.foundation.vertx.http.TestStandardHttpServletRequestEx.java

@Test
public void setParameter() {
    Map<String, String[]> parameterMap = new HashMap<>();
    Deencapsulation.setField(requestEx, "parameterMap", parameterMap);

    requestEx.setParameter("k1", "v1");
    requestEx.setParameter("k2", "v2");

    Assert.assertEquals("v1", requestEx.getParameter("k1"));
    Assert.assertEquals("v2", requestEx.getParameter("k2"));

    Assert.assertSame(parameterMap, requestEx.getParameterMap());

    Assert.assertThat(Collections.list(requestEx.getParameterNames()), Matchers.contains("k1", "k2"));
}

From source file:org.phenotips.variantstore.shared.ResourceManager.java

/**
 * Copy resources recursively from a folder specified by source in a jar file specified by jarPath
 * to a destination folder on the filesystem dest.
 *
 * @param jarPath the jar file/*from  ww w .j a  v a2  s  . c o m*/
 * @param source  the folder on the filesystem
 * @param dest    the destination
 * @throws IOException
 */
private static void copyResourcesFromJar(Path jarPath, Path source, Path dest) throws IOException {
    JarFile jar = new JarFile(jarPath.toFile());

    for (JarEntry entry : Collections.list(jar.entries())) {

        if (entry.getName().startsWith(source.toString())) {
            if (entry.isDirectory()) {
                Files.createDirectory(dest.resolve(entry.getName()));
            } else {
                Files.copy(jar.getInputStream(entry), dest.resolve(entry.getName()));
            }
        }

    }
}