|
From: <pat...@us...> - 2010-09-30 14:54:43
|
Revision: 1139
http://cishell.svn.sourceforge.net/cishell/?rev=1139&view=rev
Author: pataphil
Date: 2010-09-30 14:54:33 +0000 (Thu, 30 Sep 2010)
Log Message:
-----------
* Added DictionaryUtilities.putAll(), and refactored copy() to use it.
* Reviewed by Joseph.
Modified Paths:
--------------
trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java
Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java
===================================================================
--- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java 2010-09-28 22:21:12 UTC (rev 1138)
+++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java 2010-09-30 14:54:33 UTC (rev 1139)
@@ -1,6 +1,7 @@
package org.cishell.utilities.dictionary;
import java.util.Dictionary;
+import java.util.Enumeration;
import java.util.Hashtable;
public class DictionaryUtilities {
@@ -28,14 +29,20 @@
return newDictionary;
}
- public static <K, V> Dictionary<K, V> copy(Dictionary<K, V> originalDictionary) {
- Dictionary<K, V> newDictionary = new Hashtable<K, V>();
+ /**
+ * Uses Hashtable for the copy.
+ */
+ public static<K, V> Dictionary<K, V> copy(Dictionary<K, V> originalDictionary) {
+ Hashtable<K, V> newDictionary = new Hashtable<K, V>();
+ putAll(newDictionary, originalDictionary);
- for (DictionaryEntry<K, V> originalEntry :
- new DictionaryIterator<K, V>(originalDictionary)) {
- newDictionary.put(originalEntry.getKey(), originalEntry.getValue());
- }
-
return newDictionary;
}
+
+ public static<K, V> void putAll(Dictionary<K, V> target, Dictionary<K, V> source) {
+ for (Enumeration<K> keys = source.keys(); keys.hasMoreElements(); ) {
+ K key = keys.nextElement();
+ target.put(key, source.get(key));
+ }
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|