Example usage for java.util Enumeration hasMoreElements

List of usage examples for java.util Enumeration hasMoreElements

Introduction

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

Prototype

boolean hasMoreElements();

Source Link

Document

Tests if this enumeration contains more elements.

Usage

From source file:com.nary.util.LogFileObject.java

public static void closeAll() {
    Enumeration E = logfiles.elements();
    while (E.hasMoreElements())
        ((LogFileObject) E.nextElement()).close();
}

From source file:com.twitter.ambrose.model.hadoop.MapReduceHelper.java

public static Configuration toConfiguration(Properties properties) {
    assert properties != null;
    final Configuration config = new Configuration(false);
    final Enumeration<Object> iter = properties.keys();
    while (iter.hasMoreElements()) {
        final String key = (String) iter.nextElement();
        final String val = properties.getProperty(key);
        config.set(key, val);
    }//from   w w w. ja  v a 2 s . c  o  m
    return config;
}

From source file:com.adito.agent.AgentRequestHandler.java

@SuppressWarnings({ "unchecked" })
private static Map getParameters(RequestHandlerRequest request) {
    Map parameters = new HashMap(request.getParameters());
    for (Enumeration fieldNames = request.getFieldNames(); fieldNames.hasMoreElements();) {
        String fieldName = (String) fieldNames.nextElement();
        Enumeration fieldValues = request.getFieldValues(fieldName);
        if (fieldValues.hasMoreElements())
            parameters.put(fieldName, fieldValues.nextElement());
    }/*ww w .  j av a 2  s . c  om*/
    return parameters;
}

From source file:Main.java

/** 
 * Returns a string with all fonts used by Swing's UIManager.
 *//*from www.  j  a  v a 2 s.  com*/
public static String getUIFonts() {

    final StringBuffer fonts = new StringBuffer(128);
    fonts.append("Default font: ");
    fonts.append(getUIFont().toString());
    final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys();
    String lf = System.getProperty("line.separator");
    while (keys.hasMoreElements()) {
        final Object key = keys.nextElement();
        final Object value = UIManager.get(key);
        if (value instanceof Font) {
            final Font ifont = (Font) value;
            fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " "
                    + ifont.getSize());
        }
    }
    return fonts.toString();
}

From source file:com.apdplat.platform.spring.APDPlatContextLoaderListener.java

/**
 * Find all ServletContext attributes which implement {@link DisposableBean}
 * and destroy them, removing all affected ServletContext attributes eventually.
 * @param sc the ServletContext to check
 *//*from  w w  w .  j  av  a  2 s. co m*/
static void cleanupAttributes(ServletContext sc) {
    Enumeration attrNames = sc.getAttributeNames();
    while (attrNames.hasMoreElements()) {
        String attrName = (String) attrNames.nextElement();
        if (attrName.startsWith("org.springframework.")) {
            Object attrValue = sc.getAttribute(attrName);
            if (attrValue instanceof DisposableBean) {
                try {
                    ((DisposableBean) attrValue).destroy();
                } catch (Throwable ex) {
                    logger.error("Couldn't invoke destroy method of attribute with name '" + attrName + "'",
                            ex);
                }
            }
        }
    }
}

From source file:com.wmfsystem.eurekaserver.broadcast.Server.java

public static Set<InetAddress> getLocalAddress() throws SocketException {
    Set<InetAddress> address = new HashSet<>();
    Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
    while (ifaces.hasMoreElements()) {
        NetworkInterface iface = ifaces.nextElement();
        Enumeration<InetAddress> addresses = iface.getInetAddresses();

        while (addresses.hasMoreElements()) {
            InetAddress addr = addresses.nextElement();

            if (addr instanceof Inet4Address && !addr.isLoopbackAddress()) {
                address.add(addr);/*  w  w  w .j a  va  2 s  .c  om*/
            }
        }
    }

    return address;
}

From source file:com.evanmclean.evlib.commons.dbcp.DbcpUtils.java

/**
 * Get the DBCP pooling driver.//from www. j a  v a  2s. c  o  m
 * 
 * @return Return the DBCP pooling driver or null.
 */
public static PoolingDriver getPoolingDriver() {
    PoolingDriver pdriver = null;
    final Enumeration<Driver> drivers = DriverManager.getDrivers();
    while (drivers.hasMoreElements()) {
        final Driver driver = drivers.nextElement();
        if (driver instanceof PoolingDriver) {
            if (pdriver == null)
                pdriver = (PoolingDriver) driver;
            else
                throw new IllegalStateException("More than one DBCP pooling driver.");
        }
    }
    return pdriver;
}

From source file:Main.java

/**
 * Adds all elements in the enumeration to the given collection.
 * /*from   www. j a v  a 2s  . c o m*/
 * @param collection
 *            the collection to add to, must not be null
 * @param enumeration
 *            the enumeration of elements to add, must not be null
 * @throws NullPointerException
 *             if the collection or enumeration is null
 */
public static <E> void addAll(Collection<E> collection, Enumeration<E> enumeration) {
    if (collection == null || enumeration == null) {
        return;
    }

    while (enumeration.hasMoreElements()) {
        collection.add(enumeration.nextElement());
    }
}

From source file:Main.java

private static String getChannelFromApk(Context context, String channelKey) {
    ApplicationInfo appinfo = context.getApplicationInfo();
    String sourceDir = appinfo.sourceDir;
    String key = "META-INF/" + channelKey;
    String ret = "";
    ZipFile zipfile = null;//from   w  w w  .  j a v a 2  s. com
    try {
        zipfile = new ZipFile(sourceDir);
        Enumeration<?> entries = zipfile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            String entryName = entry.getName();
            if (entryName.startsWith(key)) {
                ret = entryName;
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipfile != null) {
            try {
                zipfile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    String[] split = ret.split("_");
    String channel = "";
    if (split != null && split.length >= 2) {
        channel = ret.substring(split[0].length() + 1);
    }
    return channel;
}

From source file:br.msf.commons.netbeans.util.FileObjectUtils.java

public static Collection<FileObject> getFiles(final FileObject rootDir, final boolean recursive,
        final FileType... types) {
    assert rootDir != null && rootDir.isFolder() && !ArrayUtils.contains(types, FileType.OTHER);
    Collection<FileObject> fileObjects = new ArrayList<FileObject>();
    Enumeration<FileObject> entries = (Enumeration<FileObject>) rootDir.getChildren(recursive);
    while (entries.hasMoreElements()) {
        FileObject curr = entries.nextElement();
        if (curr.isData()) {
            FileType t = FileType.parse(curr.getExt());
            if (ArrayUtils.isEmpty(types) || ArrayUtils.contains(types, t)) {
                fileObjects.add(curr);//  w w  w .  ja  va 2 s  . c om
            }
        }
    }
    return fileObjects;
}