List of usage examples for java.util Dictionary keys
public abstract Enumeration<K> keys();
From source file:Main.java
public static void main(String[] args) { Dictionary d = new Hashtable(); // add some elements d.put("1", "from java2s.com"); d.put("2", "Cocoa"); d.put("5", "Coffee"); // return an enumeration of the keys from this dictionary. for (Enumeration e = d.keys(); e.hasMoreElements();) { System.out.println(e.nextElement()); }//from ww w .ja v a 2 s . co m }
From source file:Main.java
public static final <T, K> boolean containsKey(Dictionary<T, K> collection, T key) { Enumeration<T> e = collection.keys(); while (e.hasMoreElements()) { if (e.nextElement().equals(key)) { return true; }//from w w w.j a v a 2s . c o m } return false; }
From source file:Main.java
/** * Returns a semicolumn separated list of keys and values in the dictionary. * //w w w.java 2s .c o m * Here is an example of returned String "key1 = value1; key2 = value2;" * * * * @param dict * Dictionary<Object,Object> * @return : String. */ public static String dictionaryToString(Dictionary<Object, Object> dict) { Enumeration<Object> keys = dict.keys(); Object key, value; StringBuffer result = new StringBuffer(); while (keys.hasMoreElements()) { key = keys.nextElement(); value = dict.get(key); result.append(key.toString()); result.append(" = "); result.append(value.toString()); result.append("; "); } return result.toString(); }
From source file:org.apache.whirr.karaf.command.support.ConfigurationReader.java
/** * Builds the Configuration from Configuration Admin. * * @param pid//w w w . ja v a2 s .c o m * @return */ public static PropertiesConfiguration fromConfigAdmin(ConfigurationAdmin configurationAdmin, String pid) { List<String> ignoredKeys = Arrays.asList("service.pid", "felix.fileinstall.filename"); PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration(); try { Configuration configuration = configurationAdmin.getConfiguration(pid); Dictionary properties = configuration.getProperties(); Enumeration keys = properties.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = properties.get(key); if (!ignoredKeys.contains(key)) { propertiesConfiguration.addProperty(String.valueOf(key), value); } } } catch (IOException e) { System.err.println(String.format("No configuration found for pid:%s.", pid)); return null; } return propertiesConfiguration; }
From source file:org.eclipse.virgo.snaps.SnapsTagTests.java
private static ServiceReference<?> createServiceReference(Dictionary<?, ?> properties) { ServiceReference<?> serviceReference = createMock(ServiceReference.class); String[] keys = toArray(properties.keys()); expect(serviceReference.getPropertyKeys()).andReturn(keys); for (String key : keys) { expect(serviceReference.getProperty(key)).andReturn(properties.get(key)); }//from w w w. j av a 2 s .co m return serviceReference; }
From source file:com.basistech.yca.JsonNodeFlattener.java
public static JsonNode unflatten(Dictionary<String, ?> config) { Enumeration<String> keyEnum = config.keys(); List<String> keys = new ArrayList<>(); while (keyEnum.hasMoreElements()) { keys.add(keyEnum.nextElement()); }//from w w w. j a v a2 s . com Collections.sort(keys); ObjectMapper mapper = new ObjectMapper(); ObjectNode root = mapper.createObjectNode(); for (String key : keys) { Object value = config.get(key); addNode(root, key, value); } return root; }
From source file:org.openhab.binding.insteonhub.internal.InsteonHubProxyFactory.java
public static Map<String, InsteonHubProxy> createInstances(Dictionary<String, ?> config) { Map<String, InsteonHubProxy> proxies = new HashMap<String, InsteonHubProxy>(); // parse all configured receivers // ( insteonhub:<hubid>.host=10.0.0.2 ) Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (key.endsWith(CONFIG_KEY_HOST)) { // parse host String host = (String) config.get(key); int separatorIdx = key.indexOf('.'); String hubId, keyPrefix; if (separatorIdx == -1) { // no prefix/hubid => one hub => use default hub ID hubId = InsteonHubBinding.DEFAULT_HUB_ID; keyPrefix = ""; } else { // prefix => use it as the hub ID hubId = key.substring(0, separatorIdx); keyPrefix = hubId + "."; }//www. j ava 2 s .co m String portStr = (String) config.get(keyPrefix + CONFIG_KEY_PORT); int port = StringUtils.isBlank(portStr) ? InsteonHubSerialProxy.DEFAULT_PORT : Integer.parseInt(config.get(keyPrefix + CONFIG_KEY_PORT).toString()); // Create proxy, and add it to map InsteonHubProxy proxy = new InsteonHubSerialProxy(host, port); proxies.put(hubId, proxy); } } return proxies; }
From source file:org.osgi.jmx.codec.Util.java
public static Map<String, String> getBundleHeaders(Bundle b) { Map<String, String> headers = new Hashtable<String, String>(); Dictionary h = b.getHeaders(); for (Enumeration keys = h.keys(); keys.hasMoreElements();) { String key = (String) keys.nextElement(); headers.put(key, (String) h.get(key)); }/*from w ww. ja v a2s . c o m*/ return headers; }
From source file:Main.java
/** * Dictionary does not have an equals.//from w w w .j av a 2 s. c om * 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:Main.java
/** * Dictionary does not have an equals.//from w ww . j av a 2s . c om * Please use Map.equals(). * * <p>Follows the equals contract of Java 2's Map.</p> * @param d1 the first directory. * @param d2 the second directory. * @return true if the directories are equal. * @since Ant 1.5 * @deprecated since 1.6.x. */ 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; }