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:Main.java

public static Collection enumToCollection(Enumeration e) {
    ArrayList result = new ArrayList();
    while (e.hasMoreElements()) {
        result.add(e.nextElement());/*from   w w  w. j ava2 s .  co  m*/
    }
    return result;
}

From source file:Main.java

static Hashtable hashtableClone(Hashtable ht) {
    if (ht == null)
        return null;

    Hashtable htresp = new Hashtable();
    Enumeration e = ht.keys();

    while (e.hasMoreElements()) {
        Object element = e.nextElement();
        htresp.put(element, ht.get(element));
    }//from   w  w  w.j  a v  a2  s . c o m
    return htresp;
}

From source file:Main.java

/**
 * Converts a Properties object into a Map.
 * /*  w w  w  .  j av a  2s. com*/
 * @param properties
 *            set of string key-value pairs
 * @returns map of key-value pairs (never null)
 */
public static Map<String, String> getMapFromProperties(Properties props) {
    Map<String, String> map = new HashMap<String, String>();

    if (props != null) {
        Enumeration<Object> e = props.keys();
        while (e.hasMoreElements()) {
            String s = (String) e.nextElement();
            map.put(s, props.getProperty(s));
        }
    }

    return map;
}

From source file:Main.java

public static void mergePropertiesIntoMap(Properties props, Map map) {
    if (map == null) {
        throw new IllegalArgumentException("Map must not be null");
    } else {/*from  w  w  w  .j av  a 2  s  . c  o  m*/
        if (props != null) {
            Enumeration en = props.propertyNames();

            while (en.hasMoreElements()) {
                String key = (String) en.nextElement();
                map.put(key, props.getProperty(key));
            }
        }

    }
}

From source file:Main.java

private static List<NameValuePair> buildNameValuePair(Hashtable<String, String> httpPost) {
    if (httpPost == null)
        return null;

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    Enumeration<String> keys = httpPost.keys();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        String value = (String) httpPost.get(key);
        BasicNameValuePair nv = new BasicNameValuePair(key, value);
        nvps.add(nv);//from  w w w  .  jav a  2 s . co  m
    }

    return nvps;
}

From source file:Main.java

public static void printUIDefaults() {
    UIDefaults uiDefaults = UIManager.getDefaults();
    Enumeration<Object> e = uiDefaults.keys();
    while (e.hasMoreElements()) {
        Object key = e.nextElement();
        Object val = uiDefaults.get(key);
        System.out.println("[" + key.toString() + "]:[" + (null != val ? val.toString() : "(null)") + "]");
    }/*from   w w w . jav a  2 s  . c o  m*/
}

From source file:com.asual.summer.onejar.OneJarServer.java

private static String getCurrentWarFile() throws IOException {
    JarFile jarFile = new JarFile(System.getProperty("java.class.path"));
    Enumeration<JarEntry> entries = jarFile.entries();
    while (entries.hasMoreElements()) {
        String name = entries.nextElement().getName();
        if (name.endsWith(".war")) {
            File war = new File(new File(System.getProperty("java.io.tmpdir")),
                    "summer-onejar-" + System.currentTimeMillis() + ".war");
            InputStream input = jarFile.getInputStream(new ZipEntry(name));
            FileOutputStream output = new FileOutputStream(war);
            IOUtils.copy(input, output);
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
            war.deleteOnExit();//  w  w w  .ja v a  2  s  .c  o m
            return war.getAbsolutePath();
        }
    }
    return null;
}

From source file:Main.java

public static void setButtonGroupEnabled(ButtonGroup buttonGroup, boolean enabled) {
    Enumeration<AbstractButton> buttonEnum = buttonGroup.getElements();
    while (buttonEnum.hasMoreElements()) {
        buttonEnum.nextElement().setEnabled(enabled);
    }/*from w  ww  .  jav a2  s .co  m*/
}

From source file:Main.java

public static AbstractButton getSelectedButton(ButtonGroup group) {
    Enumeration<AbstractButton> buttons = group.getElements();
    while (buttons.hasMoreElements()) {
        AbstractButton b = buttons.nextElement();
        if (b.isSelected()) {
            return b;
        }//ww  w.j a  v  a2  s.c o  m
    }
    return null;
}

From source file:Main.java

/**
 * magnify the all fonts in swing.// w ww .  j a v  a2  s.  co m
 * 
 * @param mag
 *            magnify parameter <br/> mag > 1. : large <br/> mag < 1. :
 *            small
 */
public static void magnifyAllFont(float mag) {
    List history = new LinkedList();
    UIDefaults defaults = UIManager.getDefaults();
    Enumeration it = defaults.keys();
    while (it.hasMoreElements()) {
        Object key = it.nextElement();
        Object a = defaults.get(key);
        if (a instanceof Font) {
            if (history.contains(a))
                continue;
            Font font = (Font) a;
            font = font.deriveFont(font.getSize2D() * mag);
            defaults.put(key, font);
            history.add(font);
        }
    }
}