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

/**
 * Marshal the elements from the given enumeration into an array of the given type.
 * Enumeration elements must be assignable to the type of the given array. The array
 * returned will be a different instance than the array given.
 *//*  ww w .  ja  v a  2 s  .com*/
public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) {
    ArrayList<A> elements = new ArrayList<A>();
    while (enumeration.hasMoreElements()) {
        elements.add(enumeration.nextElement());
    }
    return elements.toArray(array);
}

From source file:MainClass.java

public static void printDescendents(TreeNode root) {
    System.out.println(root);// w w w .  ja  v a 2s  .  com
    Enumeration children = root.children();
    if (children != null) {
        while (children.hasMoreElements()) {
            printDescendents((TreeNode) children.nextElement());
        }
    }
}

From source file:Main.java

/**
 * Fix properties keys.//from  w  w w.j  a v  a  2s  .  c  om
 *
 * @param prop
 *            the prop
 */
public static void fixPropertiesKeys(final Properties prop) {
    final Enumeration<Object> keys = prop.keys();
    while (keys.hasMoreElements()) {
        final String currentKey = (String) keys.nextElement();
        final String fixedKey = fixPropertyKey(currentKey);
        final String value = prop.getProperty(currentKey);
        prop.remove(currentKey);
        prop.setProperty(fixedKey, value);
    }
}

From source file:Main.java

public static void loadExpansionState(JTree tree, Enumeration<TreePath> enumeration) {
    if (enumeration != null) {
        while (enumeration.hasMoreElements()) {
            TreePath treePath = enumeration.nextElement();
            tree.expandPath(treePath);/*from w w w  .j a v  a2  s  .  co m*/
        }
    }
}

From source file:Main.java

public static void saveAttributesToNode(Node node, Properties props) {
    Document doc = node.getOwnerDocument();
    Element elem;//from   www .  jav  a 2  s  .co m
    Enumeration keys = props.keys();
    Enumeration elems = props.elements();
    while (keys.hasMoreElements()) {
        String s;
        s = keys.nextElement().toString() + "=" + elems.nextElement().toString();
        addTextTag(node, TAG_ATTR, s);
    }

}

From source file:Main.java

/** Finds a network interface of sub-interface with the given name */
public static NetworkInterface getByName(String name) throws SocketException {
    if (name == null)
        return null;
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
        NetworkInterface intf = en.nextElement();
        if (intf.getName().equals(name))
            return intf;
        Enumeration<NetworkInterface> en2 = intf.getSubInterfaces();
        while (en2.hasMoreElements()) {
            NetworkInterface intf2 = en2.nextElement();
            if (intf2.getName().equals(name)) {
                return intf2;
            }/*from w  ww  .ja  v a  2 s  .c o  m*/
        }
    }
    return null;
}

From source file:Main.java

public static void findClassesInApk(String apkPath, String packageName, List<String> classNames)
        throws IOException {

    DexFile dexFile = null;/* ww  w .  j a  v a2s.c  o m*/
    try {
        dexFile = new DexFile(apkPath);
        Enumeration<String> apkClassNames = dexFile.entries();
        while (apkClassNames.hasMoreElements()) {
            String className = apkClassNames.nextElement();

            if (className.startsWith(packageName) && isToplevelClass(className)) {
                classNames.add(className);
            }
        }
    } catch (IOException e) {
        android.util.Log.w(LOGTAG, "Error finding classes at apk path: " + apkPath, e);
    }
}

From source file:Util.java

/*********************************************************************
* Removes duplicate elements from the array.
*********************************************************************/
public static Object[] removeDuplicates(Object[] array)
//////////////////////////////////////////////////////////////////////
{

    Hashtable hashtable = new Hashtable();

    for (int i = 0; i < array.length; i++) {
        hashtable.put(array[i], array[i]);
    }/*w w  w . j  a v  a  2 s  .com*/

    Object[] newArray = (Object[]) Array.newInstance(array.getClass().getComponentType(), hashtable.size());

    int index = 0;

    Enumeration enumeration = hashtable.elements();

    while (enumeration.hasMoreElements()) {
        newArray[index++] = enumeration.nextElement();
    }

    return newArray;
}

From source file:Main.java

/**
 * Dictionary does not have an equals./*from   w w  w . j  a  v  a2  s.co  m*/
 * Please use  Map.equals()
 *
 * <p>Follows the equals contract of Java 2's Map.</p>
 *
 * @since Ant 1.5
 * @deprecated
 */
public static boolean equals(Dictionary d1, Dictionary d2) {
    if (d1 == d2) {
        return true;
    }

    if (d1 == null || d2 == null) {
        return false;
    }

    if (d1.size() != d2.size()) {
        return false;
    }

    Enumeration e1 = d1.keys();
    while (e1.hasMoreElements()) {
        Object key = e1.nextElement();
        Object value1 = d1.get(key);
        Object value2 = d2.get(key);
        if (value2 == null || !value1.equals(value2)) {
            return false;
        }
    }

    // don't need the opposite check as the Dictionaries have the
    // same size, so we've also covered all keys of d2 already.

    return true;
}

From source file:net.jadler.stubbing.server.jetty.RequestUtils.java

private static Map<String, List<String>> converHeaders(HttpServletRequest request) {
    Map<String, List<String>> result = new HashMap<String, List<String>>();
    Enumeration headerNames = request.getHeaderNames();
    while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        result.put(headerName, list(request.getHeaders(headerName)));
    }/*from  w  ww . j  a  v a2 s  .  co m*/

    return result;
}