@Test public void testFilterDictionary() throws Exception { final Hashtable<String, String> h = new Hashtable<>(); h.put("w.p.key1", "1"); h.put("x", "2"); h.put("w.p.key2", "2"); h.put("y", "2"); final Map<String, String> f = OsgiUtil.filterByPrefix(h, "w.p."); assertEquals(2, f.size()); assertEquals("1", f.get("key1")); assertEquals("2", f.get("key2")); }
public static Map<String, String> filterByPrefix(Dictionary d, String prefix) { final Map<String, String> filtered = new HashMap<>(); final int prefixLength = prefix.length(); final Enumeration keys = d.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement().toString(); if (key.startsWith(prefix)) { filtered.put(key.substring(prefixLength), d.get(key).toString()); } } return filtered; }
OsgiUtil { public static Map<String, String> filterByPrefix(Dictionary d, String prefix) { final Map<String, String> filtered = new HashMap<>(); final int prefixLength = prefix.length(); final Enumeration keys = d.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement().toString(); if (key.startsWith(prefix)) { filtered.put(key.substring(prefixLength), d.get(key).toString()); } } return filtered; } }
OsgiUtil { public static Map<String, String> filterByPrefix(Dictionary d, String prefix) { final Map<String, String> filtered = new HashMap<>(); final int prefixLength = prefix.length(); final Enumeration keys = d.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement().toString(); if (key.startsWith(prefix)) { filtered.put(key.substring(prefixLength), d.get(key).toString()); } } return filtered; } private  OsgiUtil(); }
OsgiUtil { public static Map<String, String> filterByPrefix(Dictionary d, String prefix) { final Map<String, String> filtered = new HashMap<>(); final int prefixLength = prefix.length(); final Enumeration keys = d.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement().toString(); if (key.startsWith(prefix)) { filtered.put(key.substring(prefixLength), d.get(key).toString()); } } return filtered; } private  OsgiUtil(); static String getContextProperty(ComponentContext cc, String key); static Option<String> getOptContextProperty(ComponentContext cc, String key); static String getComponentContextProperty(ComponentContext cc, String key); static String getComponentContextProperty(ComponentContext cc, String key, String defaultValue); static String getCfg(Dictionary d, String key); static Option<String> getOptCfg(Dictionary d, String key); static Option<Integer> getOptCfgAsInt(Dictionary d, String key); static Map<String, String> filterByPrefix(Dictionary d, String prefix); static Option<Boolean> getOptCfgAsBoolean(Dictionary d, String key); static int getCfgAsInt(Dictionary d, String key); static ServiceRegistration<?> registerServlet(BundleContext bundleContext, Object service, String alias); }
OsgiUtil { public static Map<String, String> filterByPrefix(Dictionary d, String prefix) { final Map<String, String> filtered = new HashMap<>(); final int prefixLength = prefix.length(); final Enumeration keys = d.keys(); while (keys.hasMoreElements()) { final String key = keys.nextElement().toString(); if (key.startsWith(prefix)) { filtered.put(key.substring(prefixLength), d.get(key).toString()); } } return filtered; } private  OsgiUtil(); static String getContextProperty(ComponentContext cc, String key); static Option<String> getOptContextProperty(ComponentContext cc, String key); static String getComponentContextProperty(ComponentContext cc, String key); static String getComponentContextProperty(ComponentContext cc, String key, String defaultValue); static String getCfg(Dictionary d, String key); static Option<String> getOptCfg(Dictionary d, String key); static Option<Integer> getOptCfgAsInt(Dictionary d, String key); static Map<String, String> filterByPrefix(Dictionary d, String prefix); static Option<Boolean> getOptCfgAsBoolean(Dictionary d, String key); static int getCfgAsInt(Dictionary d, String key); static ServiceRegistration<?> registerServlet(BundleContext bundleContext, Object service, String alias);  }