Java Code Examples for java.util.Dictionary#size()
The following examples show how to use
java.util.Dictionary#size() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkUtil.java From sling-whiteboard with Apache License 2.0 | 6 votes |
/** * Create a case insensitive map from the specified dictionary. * * @param dictionary * @throws IllegalArgumentException If {@code dictionary} contains case * variants of the same key name. */ CaseInsensitiveMap(Dictionary<String, ?> dictionary) { if (dictionary == null) { this.dictionary = null; this.keys = new String[0]; return; } this.dictionary = dictionary; List<String> keyList = new ArrayList<String>(dictionary.size()); for (Enumeration<?> e = dictionary.keys(); e.hasMoreElements();) { Object k = e.nextElement(); if (k instanceof String) { String key = (String) k; for (String i : keyList) { if (key.equalsIgnoreCase(i)) { throw new IllegalArgumentException(); } } keyList.add(key); } } this.keys = keyList.toArray(new String[0]); }
Example 2
Source File: EventProperties.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Create an EventProperties from the specified dictionary. * * <p> * The specified properties will be copied into this EventProperties. * Properties whose key is not of type {@code String} will be ignored. A * property with the key "event.topics" will be ignored. * * @param properties The properties to use for this EventProperties object * (may be {@code null}). */ EventProperties(Dictionary<String, ?> properties) { int size = (properties == null) ? 0 : properties.size(); Map<String, Object> p = new HashMap<String, Object>(size); if (size > 0) { for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); if ((key instanceof String) && !EVENT_TOPIC.equals(key)) { Object value = properties.get(key); p.put((String) key, value); } } } // safely publish the map this.properties = Collections.unmodifiableMap(p); }
Example 3
Source File: FrameworkUtil.java From concierge with Eclipse Public License 1.0 | 6 votes |
/** * Create a case insensitive map from the specified dictionary. * * @param dictionary * @throws IllegalArgumentException If {@code dictionary} contains case * variants of the same key name. */ CaseInsensitiveMap(Dictionary<String, ?> dictionary) { if (dictionary == null) { this.dictionary = null; this.keys = new String[0]; return; } this.dictionary = dictionary; List<String> keyList = new ArrayList<String>(dictionary.size()); for (Enumeration<?> e = dictionary.keys(); e.hasMoreElements();) { Object k = e.nextElement(); if (k instanceof String) { String key = (String) k; for (String i : keyList) { if (key.equalsIgnoreCase(i)) { throw new IllegalArgumentException(); } } keyList.add(key); } } this.keys = keyList.toArray(new String[keyList.size()]); }
Example 4
Source File: EventProperties.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create an EventProperties from the specified dictionary. * * <p> * The specified properties will be copied into this EventProperties. * Properties whose key is not of type {@code String} will be ignored. A * property with the key "event.topics" will be ignored. * * @param properties The properties to use for this EventProperties object * (may be {@code null}). */ EventProperties(Dictionary<String, ?> properties) { int size = (properties == null) ? 0 : properties.size(); Map<String, Object> p = new HashMap<String, Object>(size); if (size > 0) { for (Enumeration<?> e = properties.keys(); e.hasMoreElements();) { Object key = e.nextElement(); if ((key instanceof String) && !EVENT_TOPIC.equals(key)) { Object value = properties.get(key); p.put((String) key, value); } } } // safely publish the map this.properties = Collections.unmodifiableMap(p); }
Example 5
Source File: CMCommands.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void printDictionary(PrintWriter out, Dictionary<String, Object> d, boolean printTypes) { final String[] keyNames = new String[d.size()]; int i = 0; for (final Enumeration<String> keys = d.keys(); keys.hasMoreElements();) { keyNames[i++] = keys.nextElement(); } Sort.sortStringArray(keyNames); for (i = 0; i < keyNames.length; i++) { out.print(" "); out.print(keyNames[i]); final Object value = d.get(keyNames[i]); if (printTypes) { out.print(":"); printValueType(out, value); } out.print("= "); printValue(out, value); out.println(); } }
Example 6
Source File: FrameworkUtil.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create a case insensitive map from the specified dictionary. * * @param dictionary * @throws IllegalArgumentException If {@code dictionary} contains case * variants of the same key name. */ CaseInsensitiveMap(Dictionary<String, ?> dictionary) { if (dictionary == null) { this.dictionary = null; this.keys = new String[0]; return; } this.dictionary = dictionary; List<String> keyList = new ArrayList<String>(dictionary.size()); for (Enumeration<?> e = dictionary.keys(); e.hasMoreElements();) { Object k = e.nextElement(); if (k instanceof String) { String key = (String) k; for (String i : keyList) { if (key.equalsIgnoreCase(i)) { throw new IllegalArgumentException(); } } keyList.add(key); } } this.keys = keyList.toArray(new String[keyList.size()]); }
Example 7
Source File: PropertyConglomerate.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
void savePropertyDefault(TransactionController tc, String key, Serializable value) throws StandardException { if (saveServiceProperty(key,value)) return; Dictionary defaults = (Dictionary)readProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME); if (defaults == null) defaults = new FormatableHashtable(); if (value==null) defaults.remove(key); else defaults.put(key,value); if (defaults.size() == 0) defaults = null; saveProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME,(Serializable)defaults); }
Example 8
Source File: MqttitudeBinding.java From openhab1-addons with Eclipse Public License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { // no mandatory binding properties - so fine to get nothing here if (properties == null || properties.size() == 0) { return; } float homeLat = Float.parseFloat(getOptionalProperty(properties, "home.lat", "0")); float homeLon = Float.parseFloat(getOptionalProperty(properties, "home.lon", "0")); if (homeLat == 0 || homeLon == 0) { homeLocation = null; geoFence = 0; logger.debug( "Mqttitude binding configuration updated, no 'home' location specified. All item bindings must be configured with a <region>."); } else { homeLocation = new Location(homeLat, homeLon); geoFence = Float.parseFloat(getOptionalProperty(properties, "geofence", "100")); logger.debug( "Mqttitude binding configuration updated, 'home' location specified ({}) with a geofence of {}m.", homeLocation.toString(), geoFence); } // need to re-register all the consumers/topics if the home location has changed unregisterAll(); registerAll(); }
Example 9
Source File: ManagedProcessEngineFactoryImpl.java From camunda-bpm-platform-osgi with Apache License 2.0 | 5 votes |
/** * It happends that the factory get called with properties that only contain * service.pid and service.factoryPid. If that happens we don't want to create * an engine. * * @param properties * @return */ @SuppressWarnings("unchecked") private boolean hasPropertiesConfiguration(Dictionary properties) { HashMap<Object, Object> mapProperties = new HashMap<Object, Object>(properties.size()); for (Object key : Collections.list(properties.keys())) { mapProperties.put(key, properties.get(key)); } mapProperties.remove(Constants.SERVICE_PID); mapProperties.remove("service.factoryPid"); return !mapProperties.isEmpty(); }
Example 10
Source File: ConfigurationService.java From smarthome with Eclipse Public License 2.0 | 5 votes |
private Configuration toConfiguration(Dictionary<String, Object> dictionary) { if (dictionary == null) { return null; } Map<String, Object> properties = new HashMap<>(dictionary.size()); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (!key.equals(Constants.SERVICE_PID)) { properties.put(key, dictionary.get(key)); } } return new Configuration(properties); }
Example 11
Source File: ServiceReferenceImpl.java From AtlasForAndroid with MIT License | 5 votes |
ServiceReferenceImpl(Bundle bundle, Object obj, Dictionary<String, ?> dictionary, String[] strArr) { this.useCounters = new HashMap(0); this.cachedServices = null; if (obj instanceof ServiceFactory) { this.isServiceFactory = true; } else { this.isServiceFactory = false; checkService(obj, strArr); } this.bundle = bundle; this.service = obj; this.properties = dictionary == null ? new Hashtable() : new Hashtable(dictionary.size()); if (dictionary != null) { Enumeration keys = dictionary.keys(); while (keys.hasMoreElements()) { String str = (String) keys.nextElement(); this.properties.put(str, dictionary.get(str)); } } this.properties.put(Constants.OBJECTCLASS, strArr); Dictionary dictionary2 = this.properties; String str2 = Constants.SERVICE_ID; long j = nextServiceID + 1; nextServiceID = j; dictionary2.put(str2, Long.valueOf(j)); Integer num = dictionary == null ? null : (Integer) dictionary.get(Constants.SERVICE_RANKING); this.properties.put(Constants.SERVICE_RANKING, Integer.valueOf(num == null ? 0 : num.intValue())); this.registration = new ServiceRegistrationImpl(); }
Example 12
Source File: Dictionaries.java From packagedrone with Eclipse Public License 1.0 | 5 votes |
public static Hashtable<String, Object> copy ( final Dictionary<String, ?> properties ) { final Hashtable<String, Object> newProps = new Hashtable<> ( properties.size () ); final Enumeration<String> en = properties.keys (); while ( en.hasMoreElements () ) { final String key = en.nextElement (); newProps.put ( key, properties.get ( key ) ); } return newProps; }
Example 13
Source File: PropertyConglomerate.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
void savePropertyDefault(TransactionController tc, String key, Serializable value) throws StandardException { if (saveServiceProperty(key,value)) return; Dictionary defaults = (Dictionary)readProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME); if (defaults == null) defaults = new FormatableHashtable(); if (value==null) defaults.remove(key); else defaults.put(key,value); if (defaults.size() == 0) defaults = null; saveProperty(tc,AccessFactoryGlobals.DEFAULT_PROPERTY_NAME,(Serializable)defaults); }
Example 14
Source File: PropertiesDictionary.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
PropertiesDictionary(@SuppressWarnings("rawtypes") Dictionary in, String[] classes, Long sid, Long bid, String scope) { final int max_size = (in != null ? in.size() : 0) + size; keys = new String[max_size]; values = new Object[max_size]; keys[ocIndex] = Constants.OBJECTCLASS; values[ocIndex] = classes; keys[sidIndex] = Constants.SERVICE_ID; values[sidIndex] = sid != null ? sid : new Long(nextServiceID++); keys[sbidIndex] = Constants.SERVICE_BUNDLEID; values[sbidIndex] = bid; keys[ssIndex] = Constants.SERVICE_SCOPE; values[ssIndex] = scope; if (in != null) { try { for (@SuppressWarnings("rawtypes") final Enumeration e = in.keys(); e.hasMoreElements();) { final String key = (String) e.nextElement(); if (!key.equalsIgnoreCase(Constants.OBJECTCLASS) && !key.equalsIgnoreCase(Constants.SERVICE_ID) && !key.equalsIgnoreCase(Constants.SERVICE_BUNDLEID) && !key.equalsIgnoreCase(Constants.SERVICE_SCOPE)) { for (int i = size - 1; i >= 0; i--) { if (key.equalsIgnoreCase(keys[i])) { throw new IllegalArgumentException( "Several entries for property: " + key); } } keys[size] = key; values[size++] = in.get(key); } } } catch (final ClassCastException ignore) { throw new IllegalArgumentException( "Properties contains key that is not of type java.lang.String"); } } }
Example 15
Source File: RequestImpl.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Cookie[] getCookies() { Dictionary<String, Cloneable> d; if (cookies == null && !(d = base.getCookies()).isEmpty()) { cookies = new Cookie[d.size()]; final Enumeration<Cloneable> e = d.elements(); for (int i = 0; i < cookies.length; i++) { cookies[i] = (Cookie) e.nextElement(); } } return cookies; }
Example 16
Source File: ConfigurationService.java From openhab-core with Eclipse Public License 2.0 | 5 votes |
private @Nullable Configuration toConfiguration(Dictionary<String, Object> dictionary) { if (dictionary == null) { return null; } Map<String, Object> properties = new HashMap<>(dictionary.size()); Enumeration<String> keys = dictionary.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); if (!Constants.SERVICE_PID.equals(key)) { properties.put(key, dictionary.get(key)); } } return new Configuration(properties); }
Example 17
Source File: AbstractOSGiResource.java From concierge with Eclipse Public License 1.0 | 5 votes |
protected Map<String, String> mapFromDict( final Dictionary<String, String> headers) { final HashMap<String, String> map = new HashMap<String, String>( headers.size()); final Enumeration<String> keyE = headers.keys(); while (keyE.hasMoreElements()) { final String key = keyE.nextElement(); map.put(key, headers.get(key)); } return map; }
Example 18
Source File: DictionaryUtils.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
static private boolean sizeIsNotEqual(Dictionary<?, ?> first, Dictionary<?, ?> second) { return first.size() != second.size(); }
Example 19
Source File: DictionaryProxy.java From flex-blazeds with Apache License 2.0 | 4 votes |
public List getPropertyNames(Object instance) { if (instance == null) return null; List propertyNames = null; List excludes = null; if (descriptor != null) { excludes = descriptor.getExcludesForInstance(instance); if (excludes == null) excludes = descriptor.getExcludes(); } // Add all Dictionary keys as properties if (instance instanceof Dictionary) { Dictionary dictionary = (Dictionary)instance; propertyNames = new ArrayList(dictionary.size()); Enumeration keys = dictionary.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); if (key != null) { if (excludes != null && excludes.contains(key)) continue; propertyNames.add(key.toString()); } } } // Then, check for bean properties List beanProperties = super.getPropertyNames(instance); if (propertyNames == null) { propertyNames = beanProperties; } else { propertyNames.addAll(beanProperties); } return propertyNames; }
Example 20
Source File: ServiceReferenceImpl.java From concierge with Eclipse Public License 1.0 | 4 votes |
/** * create a new service reference implementation instance. * * @param bundle * the bundle. * @param service * the service object. * @param props * the service properties. * @param clazzes * the interface classes that the service is registered under. * @throws ClassNotFoundException */ ServiceReferenceImpl(final Concierge framework, final Bundle bundle, final S service, final Dictionary<String, ?> props, final String[] clazzes) { String scope = "singleton"; if (service instanceof PrototypeServiceFactory) { isServiceFactory = true; isPrototype = true; scope = "prototype"; } else if(service instanceof ServiceFactory) { isServiceFactory = true; isPrototype = false; scope = "bundle"; } else { isServiceFactory = false; isPrototype = false; checkService(service, clazzes); } this.framework = framework; this.bundle = bundle; this.service = service; this.properties = new HashMap<String, Object>(props == null ? 5 : props.size() + 5); if (props != null) { for (final Enumeration<String> keys = props.keys(); keys .hasMoreElements();) { final String key = keys.nextElement(); properties.put(key, props.get(key)); } } properties.put(Constants.OBJECTCLASS, clazzes); properties.put(Constants.SERVICE_BUNDLEID, bundle.getBundleId()); properties.put(Constants.SERVICE_ID, new Long(++nextServiceID)); final Integer ranking = props == null ? null : (Integer) props .get(Constants.SERVICE_RANKING); properties.put(Constants.SERVICE_RANKING, ranking == null ? new Integer(0) : ranking); properties.put(Constants.SERVICE_SCOPE, scope); this.registration = new ServiceRegistrationImpl(); }