List of usage examples for java.util Enumeration hasMoreElements
boolean hasMoreElements();
From source file:Main.java
/** * Returns string keys in a hashtable as delimited string * * @param ht/* w w w. j a v a 2s. c om*/ * , Hashtable * @param delimiter * , String * @param exclude * , exclude channel if present as substring * @return , string array with hash keys string */ public static synchronized String hashTableKeysToDelimitedString(Hashtable ht, String delimiter, String exclude) { StringBuffer sb = new StringBuffer(); boolean first = true; Enumeration e = ht.keys(); while (e.hasMoreElements()) { String s = (String) e.nextElement(); if (exclude != null) { if (s.indexOf(exclude) != -1) { continue; } } if (first) { sb.append(s); first = false; } else { sb.append(delimiter).append(s); } } return sb.toString(); }
From source file:Main.java
public static String getIpAddress() { try {//from ww w . j a v a2 s .co m Enumeration en = NetworkInterface.getNetworkInterfaces(); while (en.hasMoreElements()) { NetworkInterface ex = (NetworkInterface) en.nextElement(); Enumeration enumIpAddr = ex.getInetAddresses(); while (enumIpAddr.hasMoreElements()) { InetAddress inetAddress = (InetAddress) enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { return inetAddress.getHostAddress().toString(); } } } return null; } catch (SocketException var4) { var4.printStackTrace(); return null; } }
From source file:Main.java
public static Vector appendInto(Vector dest, Vector src) { Enumeration e = src.elements(); while (e.hasMoreElements()) dest.addElement(e.nextElement()); return dest;//from ww w . ja v a2 s .c o m }
From source file:Main.java
public static void saveAttributesToNode(Node node, Properties props) { Document doc = node.getOwnerDocument(); Element elem;/*from w w w . j av a2 s .com*/ 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
/** * 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. *///w w w. ja v a 2 s.c o m 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:com.redhat.victims.util.VictimsConfig.java
/** * return all victim configuration properties * * @return property map//from ww w . ja va2s .c o m */ public static Map<String, String> getProperties() { Map<String, String> propMap = new HashMap<String, String>(); Enumeration<String> keys = props.getKeys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); propMap.put(key, props.getString(key)); } return propMap; }
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 ww . j a va 2s.c o m*/ 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
/** 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; }/* w ww. j a v a2 s . co m*/ } } return null; }
From source file:BoxSample.java
private static void tweak(Vector buttons) { // calc max preferred width JButton button;// ww w . j av a2s . c o m Dimension dim; int maxWidth = 0; Enumeration e = buttons.elements(); while (e.hasMoreElements()) { button = (JButton) e.nextElement(); dim = button.getPreferredSize(); if (dim.width > maxWidth) maxWidth = dim.width; } // set max preferred width e = buttons.elements(); while (e.hasMoreElements()) { button = (JButton) e.nextElement(); dim = button.getPreferredSize(); dim.width = maxWidth; button.setPreferredSize(dim); } }
From source file:Main.java
public static <V> List<V> asList(Enumeration<V> elements) { if (elements == null || !elements.hasMoreElements()) { return Collections.emptyList(); }//from w w w . jav a 2s . co m List<V> copy = new ArrayList<V>(); for (; elements.hasMoreElements();) { copy.add(elements.nextElement()); } return copy; }