List of usage examples for java.util Dictionary size
public abstract int size();
From source file:Main.java
public static void main(String[] args) { // Create a new hasthtable Dictionary d = new Hashtable(); // Put some elements d.put("1", "from java2s.com"); d.put("2", "Cocoa"); d.put("5", "Coffee"); // print the size of the dictionary System.out.println("Size of dictionary:" + d.size()); ;/*from ww w. java2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { Dictionary d = new Hashtable(); // put some elements d.put("1", "from java2s.com"); d.put("2", "Cocoa"); d.put("5", "Coffee"); // print how many times put was called System.out.println("Number of times put was called:" + d.size()); }
From source file:Main.java
/** * Dictionary does not have an equals./*from www . j a v a 2 s . com*/ * 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 ww w.j a v a 2 s. c o m*/ * 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; }
From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java
public void testStoreAsNew() throws Exception { String newPid = "edu.nwu.psc.numbers"; {//from w ww . j av a 2 s . co m Dictionary d = new Hashtable(); d.put("aleph", (byte) 0); d.put("nature", new int[] { 2, 72 }); d.put("pie", new Vector(Arrays.asList("chess", "key lime"))); manager.store(newPid, d); } Dictionary loaded = manager.load(newPid); assertEquals("Wrong reloaded contents: " + loaded, 3, loaded.size()); assertEquals("Missing aleph", (byte) 0, loaded.get("aleph")); assertTrue("Missing nature", loaded.get("nature") instanceof int[]); int[] actualNature = (int[]) loaded.get("nature"); assertEquals("Wrong value 0 in nature", 2, actualNature[0]); assertEquals("Wrong value 1 in nature", 72, actualNature[1]); assertTrue("Missing pie", loaded.get("pie") instanceof Vector); List actualPie = (List) loaded.get("pie"); assertEquals("Wrong value 0 in pie", "chess", actualPie.get(0)); assertEquals("Wrong value 1 in pie", "key lime", actualPie.get(1)); }
From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java
public void testLoadFiltersOutBundleLocation() throws Exception { String pid = "edu.nwu.psc.thoughts"; Map<String, Object> inDb = getJdbcTemplate().queryForMap( "SELECT id FROM osgi_cm_properties WHERE name=? AND service_pid=?", new Object[] { BUNDLE_LOCATION_PROPERTY, pid }); // The inferred type for ID is different for oracle vs. others assertEquals("Test setup failure", -101, ((Number) inDb.get("ID")).intValue()); Dictionary loaded = manager.load(pid); assertNull("Bundle location present", loaded.get(BUNDLE_LOCATION_PROPERTY)); assertEquals("Wrong loaded contents", 1, loaded.size()); }
From source file:edu.northwestern.bioinformatics.studycalendar.osgi.felixcm.internal.PscFelixPersistenceManagerTest.java
public void testLoadForExisting() throws Exception { Dictionary actual = manager.load(GOOD_PID); assertNotNull(actual);// w w w .ja va2 s .co m assertTrue("Missing letters array: " + actual.get("letters"), actual.get("letters") instanceof char[]); assertEquals("Missing favorite value", "godspeed", actual.get("favorite")); assertEquals("Wrong number of items", 2, actual.size()); }
From source file:org.opencastproject.capture.impl.SchedulerImpl.java
/** * Updates the scheduler with new configuration data. {@inheritDoc} * //from www. j a v a2 s.c o m * @see org.osgi.service.cm.ManagedService#updated(Dictionary) */ //@Override @SuppressWarnings("unchecked") private void updated(Dictionary properties) throws ConfigurationException { log.debug("Scheduler updated."); if (properties == null) { log.debug("Null properties in updated!"); throw new ConfigurationException("Null properties in updated!", "null"); } else if (properties.size() == 0) { log.debug("0 size properties in updated!"); throw new ConfigurationException( "Properties object empty in updated, this should be a scheduler configuration!", "empty"); } // Clone the properties. Note that we can't use serialization to do this because the Dictionary above is actually a // org.apache.felix.cm.impl.CaseInsensitiveDictionary schedProps = new Properties(); Enumeration<String> keys = properties.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); schedProps.put(key, properties.get(key)); } try { localCalendarCacheURL = new File(configService.getItem(CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL)) .toURI().toURL(); } catch (NullPointerException e) { log.warn("Invalid location specified for {} unable to cache scheduling data.", CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL); } catch (MalformedURLException e) { log.warn("Invalid location specified for {} unable to cache scheduling data.", CaptureParameters.CAPTURE_SCHEDULE_CACHE_URL); } updateCalendar(); }
From source file:org.codice.ddf.configuration.admin.ImportMigrationConfigurationAdminEntry.java
private boolean propertiesMatch() { final Dictionary<String, Object> props = memoryConfiguration.getProperties(); if (props == null) { return false; }//from ww w .j a va 2s . c om // remove bundle location, factory pid, and pid from the dictionary as we do not want to match // these props.remove(ConfigurationAdmin.SERVICE_FACTORYPID); props.remove(ConfigurationAdmin.SERVICE_BUNDLELOCATION); props.remove(Constants.SERVICE_PID); if (properties.size() != props.size()) { return false; } // @formatter:off - to shut up checkstyle!!!!!!! for (final Enumeration<String> e = properties.keys(); e.hasMoreElements();) { // @formatter:on final String key = e.nextElement(); if (!Objects.deepEquals(properties.get(key), props.get(key))) { return false; } } return true; }
From source file:org.codice.ddf.configuration.persistence.felix.FelixPersistenceStrategy.java
private void checkForInvalidProperties(Set<String> expectedPropertyName, Dictionary properties) throws ConfigurationFileException { if (properties.size() != expectedPropertyName.size()) { @SuppressWarnings("unchecked") Set<String> propertyNames = new HashSet<>(Collections.list(properties.keys())); LOGGER.error("Unable to convert all config file properties. One of [{}] is invalid", expectedPropertyName.removeAll(propertyNames)); throw new ConfigurationFileException("Unable to convert all config file properties."); }/*from w w w . j ava 2s .com*/ }