List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:Main.java
private static void displayInterfaceInformation(NetworkInterface netint) throws SocketException { System.out.printf("Display name: %s%n", netint.getDisplayName()); System.out.printf("Name: %s%n", netint.getName()); Enumeration<InetAddress> inetAddresses = netint.getInetAddresses(); for (InetAddress inetAddress : Collections.list(inetAddresses)) { System.out.printf("InetAddress: %s%n", inetAddress); }/*from ww w .j a va 2 s.c o m*/ System.out.printf("Parent: %s%n", netint.getParent()); System.out.printf("Up? %s%n", netint.isUp()); System.out.printf("Loopback? %s%n", netint.isLoopback()); System.out.printf("PointToPoint? %s%n", netint.isPointToPoint()); System.out.printf("Supports multicast? %s%n", netint.isVirtual()); System.out.printf("Virtual? %s%n", netint.isVirtual()); System.out.printf("Hardware address: %s%n", Arrays.toString(netint.getHardwareAddress())); System.out.printf("MTU: %s%n", netint.getMTU()); List<InterfaceAddress> interfaceAddresses = netint.getInterfaceAddresses(); for (InterfaceAddress addr : interfaceAddresses) { System.out.printf("InterfaceAddress: %s%n", addr.getAddress()); } System.out.printf("%n"); Enumeration<NetworkInterface> subInterfaces = netint.getSubInterfaces(); for (NetworkInterface networkInterface : Collections.list(subInterfaces)) { System.out.printf("%nSubInterface%n"); displayInterfaceInformation(networkInterface); } System.out.printf("%n"); }
From source file:Main.java
public static String dumpLuxLevel() { String result = ""; if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null);/*from ww w . ja va 2 s.c o m*/ if (mLevelSet != null) { ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); result = array.toString(); } return result; }
From source file:Main.java
public static boolean getBoundaryLevel(Point bound) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null);/*from w ww. j a v a 2 s.c o m*/ if (mLevelSet != null) { ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); bound.x = Integer.valueOf(array.get(0)); bound.y = Integer.valueOf(array.get(array.size() - 1)); return true; } return false; }
From source file:camp.pixels.signage.util.NetworkInterfaces.java
public static String getMACAddress(String interfaceName) { try {// www.ja v a 2s. c om List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { if (interfaceName != null) { if (!intf.getName().equalsIgnoreCase(interfaceName)) continue; } if (!VALID_INTERFACES.contains(intf.getName())) continue; byte[] mac = intf.getHardwareAddress(); if (mac == null) continue;//return ""; StringBuilder buf = new StringBuilder(); for (int idx = 0; idx < mac.length; idx++) buf.append(String.format("%02X:", mac[idx])); if (buf.length() > 0) buf.deleteCharAt(buf.length() - 1); //Log.d("getMACAddress", intf.getName()); //Log.d("getMACAddress", buf.toString()); return buf.toString(); } } catch (SocketException ex) { } return ""; }
From source file:Main.java
public static boolean isLowestLevel(int level) { if (mLevelSet == null) mLevelSet = mContext.getSharedPreferences(PREFER, Context.MODE_WORLD_READABLE).getStringSet(LEVELSET, null);//www . j ava2 s. c o m if (mLevelSet != null) { if (mLevelSet.size() < 5) // data is too few to judge lowest return false; ArrayList<String> array = Collections.list(Collections.enumeration(mLevelSet)); Collections.sort(array, mComparator); // TODO: may need check statistics to ensure the level is true lowest and not false alarm. if (level <= Integer.valueOf(array.get(0))) return true; } return false; }
From source file:Main.java
/** * Convenience method for retrieving a subset of the UIDefaults pertaining * to a particular class.//w w w. j a va 2 s .c om * * @param className fully qualified name of the class of interest * @return the UIDefaults of the class named */ public static UIDefaults getUIDefaultsOfClass(String className) { UIDefaults retVal = new UIDefaults(); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); List<?> listKeys = Collections.list(defaults.keys()); for (Object key : listKeys) { if (key instanceof String && ((String) key).startsWith(className)) { String stringKey = (String) key; String property = stringKey; if (stringKey.contains(".")) { property = stringKey.substring(stringKey.indexOf(".") + 1); } retVal.put(property, defaults.get(key)); } } return retVal; }
From source file:com.air.mobilebrowser.NetworkUtil.java
public static String getIPAddress() { boolean useIPv4 = true; try {/*from w ww . j ava 2 s . c o m*/ List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for (NetworkInterface intf : interfaces) { List<InetAddress> addrs = Collections.list(intf.getInetAddresses()); for (InetAddress addr : addrs) { if (!addr.isLoopbackAddress()) { String sAddr = addr.getHostAddress().toUpperCase(); boolean isIPv4 = InetAddressUtils.isIPv4Address(sAddr); if (useIPv4) { if (isIPv4) return sAddr; } else { if (!isIPv4) { int delim = sAddr.indexOf('%'); // drop ip6 port suffix return delim < 0 ? sAddr : sAddr.substring(0, delim); } } } } } } catch (Exception ex) { } // for now eat exceptions return ""; }
From source file:Main.java
/** * @return The MAC hardware address of the first network interface of this host. *//*from w ww. ja va2 s .c om*/ public static byte[] getFirstNetworkInterfaceHardwareAddress() { try { Enumeration<NetworkInterface> interfaceEnumeration = NetworkInterface.getNetworkInterfaces(); for (NetworkInterface iface : Collections.list(interfaceEnumeration)) { if (!iface.isLoopback() && iface.isUp() && iface.getHardwareAddress() != null) { return iface.getHardwareAddress(); } } } catch (Exception ex) { throw new RuntimeException("Could not discover first network interface hardware address"); } throw new RuntimeException("Could not discover first network interface hardware address"); }
From source file:Main.java
/** * Convenience method for retrieving a subset of the UIDefaults pertaining to a particular class. * /*from ww w . j a v a2 s. c om*/ * @param className * fully qualified name of the class of interest * @return the UIDefaults of the class named */ public static UIDefaults getUIDefaultsOfClass(String className) { UIDefaults retVal = new UIDefaults(); UIDefaults defaults = UIManager.getLookAndFeelDefaults(); List<?> listKeys = Collections.list(defaults.keys()); for (Object key : listKeys) { if (key instanceof String && ((String) key).startsWith(className)) { String stringKey = (String) key; String property = stringKey; if (stringKey.contains(".")) { //$NON-NLS-1$ property = stringKey.substring(stringKey.indexOf(".") + 1); //$NON-NLS-1$ } retVal.put(property, defaults.get(key)); } } return retVal; }
From source file:Main.java
/** * Convenience method for retrieving a subset of the UIDefaults pertaining * to a particular class./*from w w w .ja va2 s.com*/ * * @param className * fully qualified name of the class of interest * @return the UIDefaults of the class named */ public static UIDefaults getUIDefaultsOfClass(final String className) { final UIDefaults retVal = new UIDefaults(); final UIDefaults defaults = UIManager.getLookAndFeelDefaults(); final List<?> listKeys = Collections.list(defaults.keys()); for (final Object key : listKeys) { if (key instanceof String && ((String) key).startsWith(className)) { final String stringKey = (String) key; String property = stringKey; if (stringKey.contains(".")) { property = stringKey.substring(stringKey.indexOf(".") + 1); } retVal.put(property, defaults.get(key)); } } return retVal; }