Example usage for java.util Enumeration nextElement

List of usage examples for java.util Enumeration nextElement

Introduction

In this page you can find the example usage for java.util Enumeration nextElement.

Prototype

E nextElement();

Source Link

Document

Returns the next element of this enumeration if this enumeration object has at least one more element to provide.

Usage

From source file:gov.nih.nci.cabig.ctms.web.WebTools.java

private static <T> SortedMap<String, T> namedAttributesToMap(Enumeration<String> names,
        AttributeAccessor<T> accessor) {
    SortedMap<String, T> map = new TreeMap<String, T>();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        map.put(name, accessor.getAttribute(name));
    }/*from ww w .  j a va2s . c o  m*/
    return Collections.unmodifiableSortedMap(map);
}

From source file:com.alibaba.napoli.metamorphosis.network.RemotingUtils.java

public static String getLocalAddress() throws Exception {
    // ????ip?//from   w w w. j  av  a  2s  .co m
    final Enumeration<NetworkInterface> enumeration = NetworkInterface.getNetworkInterfaces();
    InetAddress ipv6Address = null;
    while (enumeration.hasMoreElements()) {
        final NetworkInterface networkInterface = enumeration.nextElement();
        final Enumeration<InetAddress> en = networkInterface.getInetAddresses();
        while (en.hasMoreElements()) {
            final InetAddress address = en.nextElement();
            if (!address.isLoopbackAddress()) {
                if (address instanceof Inet6Address) {
                    ipv6Address = address;
                } else {
                    // ipv4
                    return normalizeHostAddress(address);
                }
            }

        }

    }
    // ipv4?ipv6
    if (ipv6Address != null) {
        return normalizeHostAddress(ipv6Address);
    }
    final InetAddress localHost = InetAddress.getLocalHost();
    return normalizeHostAddress(localHost);
}

From source file:com.teradata.logging.TestFrameworkLoggingAppender.java

/**
 * Returns logs directory for configured TestFrameworkLoggingAppender.
 */// w  ww  .j a v  a 2 s  .c  o  m
public static Optional<String> getSelectedLogsDirectory() {
    Enumeration allAppenders = Logger.getRootLogger().getAllAppenders();
    while (allAppenders.hasMoreElements()) {
        Appender appender = (Appender) allAppenders.nextElement();
        if (appender instanceof TestFrameworkLoggingAppender) {
            return Optional.of(((TestFrameworkLoggingAppender) appender).logsDirectory);
        }
    }
    return Optional.empty();
}

From source file:Main.java

public static String toString(Enumeration/*<String>*/ enumer, String separator) {
    if (separator == null)
        separator = ","; //NOI18N
    StringBuffer buf = new StringBuffer();
    while (enumer.hasMoreElements()) {
        if (buf.length() != 0)
            buf.append(separator);/*from w  w  w  . j  a va  2s  .  co  m*/
        buf.append(enumer.nextElement());
    }
    return buf.toString();
}

From source file:android.databinding.tool.util.GenerationalClassUtil.java

private static void loadFomZipFile(File file) throws IOException {
    ZipFile zipFile = new ZipFile(file);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        for (ExtensionFilter filter : ExtensionFilter.values()) {
            if (!filter.accept(entry.getName())) {
                continue;
            }//from   ww  w .j av  a 2  s . co  m
            InputStream inputStream = null;
            try {
                inputStream = zipFile.getInputStream(entry);
                Serializable item = fromInputStream(inputStream);
                L.d("loaded item %s from zip file", item);
                if (item != null) {
                    //noinspection unchecked
                    sCache[filter.ordinal()].add(item);
                }
            } catch (IOException e) {
                L.e(e, "Could not merge in Bindables from %s", file.getAbsolutePath());
            } catch (ClassNotFoundException e) {
                L.e(e, "Could not read Binding properties intermediate file. %s", file.getAbsolutePath());
            } finally {
                IOUtils.closeQuietly(inputStream);
            }
        }
    }
}

From source file:de.mylifesucks.oss.ncsimulator.protocol.SerialComm.java

public static HashMap<String, CommPortIdentifier> getPorts() {
    if (portMap == null) {
        portMap = new HashMap<String, CommPortIdentifier>();
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
            portId = (CommPortIdentifier) portList.nextElement();
            if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                portMap.put(portId.getName(), portId);
            }/*from  w  ww.  j a  v  a2 s  .  c o  m*/
        }
    }
    return portMap;
}

From source file:org.ambraproject.wombat.util.HttpMessageUtil.java

/**
 * Return a list of headers from a request, using an optional whitelist
 *
 * @param request a request/*w  w w  .j av  a  2 s  . c  o  m*/
 * @return its headers
 */
public static Collection<Header> getRequestHeaders(HttpServletRequest request,
        ImmutableSet<String> headerWhitelist) {
    Enumeration headerNames = request.getHeaderNames();
    List<Header> headers = Lists.newArrayList();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        if (headerWhitelist.contains(headerName)) {
            String headerValue = request.getHeader(headerName);
            headers.add(new BasicHeader(headerName, headerValue));
        }
    }
    return headers;
}

From source file:com.redhat.rhn.common.util.ServletUtils.java

/**
 * Creates a encoded URL query string with the parameters from the given request. If the
 * request is a GET, then the returned query string will simply consist of the query
 * string from the request. If the request is a POST, the returned query string will
 * consist of the form variables.//from  w w  w . j  a v a2  s  .  co  m
 *
 * <br/><br/>
 *
 * <strong>Note</strong>: This method does not support multi-value parameters.
 *
 * @param request The request for which the query string will be generated.
 *
 * @return An encoded URL query string with the parameters from the given request.
 */
public static String requestParamsToQueryString(ServletRequest request) {

    StringBuffer queryString = new StringBuffer();

    String paramName = null;
    String paramValue = null;

    Enumeration paramNames = request.getParameterNames();

    while (paramNames.hasMoreElements()) {
        paramName = (String) paramNames.nextElement();
        paramValue = request.getParameter(paramName);

        queryString.append(encode(paramName)).append("=").append(encode(paramValue)).append("&");
    }

    if (endsWith(queryString, '&')) {
        queryString.deleteCharAt(queryString.length() - 1);
    }

    return queryString.toString();
}

From source file:Main.java

/**
 * Sets the background color for the specified <code>ButtonGroup</code> and
 * all the JCheckBox, JComboBox, JButton, and JRadioButton components that 
 * it contains to the same color.// w  ww . j  a  v a  2 s. c  o m
 * 
 * @param buttons the button group to set the background for.
 * @param bg the background color.
 */
public static void setBackground(ButtonGroup buttons, Color bg) {
    Enumeration<?> children = buttons.getElements();
    if (children == null) {
        return;
    }
    Component child;

    if (bg != null) {
        while (children.hasMoreElements()) {
            child = (Component) children.nextElement();
            if (!bg.equals(child.getBackground())
                    && ((child instanceof JCheckBox) || (child instanceof JComboBox)
                            || (child instanceof JButton) || (child instanceof JRadioButton))) {
                child.setBackground(bg);
            }
        }
    }
}

From source file:spring.osgi.utils.OsgiResourceUtils.java

public static Resource[] convertURLEnumerationToResourceArray(Enumeration enm) {
    Set<Resource> resources = new LinkedHashSet<>(4);
    while (enm != null && enm.hasMoreElements()) {
        resources.add(new UrlResource((URL) enm.nextElement()));
    }/*  ww w.j av  a 2 s  .c  o m*/
    return resources.toArray(new Resource[resources.size()]);
}