Author: rwhitcomb
Date: Tue Feb  6 22:05:12 2018
New Revision: 1823398

URL: http://svn.apache.org/viewvc?rev=1823398&view=rev
Log:
PIVOT-999: Remove the really unnecessary "putInt" and "putBoolean" methods
from Dictionary and Component.StyleDictionary, because the default "put"
method (with autoboxing) is perfectly able to handle those values.

Add a default "copy" method to the Dictionary interface to copy a key/value
pair from another dictionary.  Also add the "Style" overload of this method
to Component.StyleDictionary for completeness.

Modified:
    pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
    pivot/trunk/core/test/org/apache/pivot/collections/test/DictionaryTest.java
    pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java

Modified: pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java?rev=1823398&r1=1823397&r2=1823398&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/collections/Dictionary.java Tue Feb  
6 22:05:12 2018
@@ -159,19 +159,6 @@ public interface Dictionary<K, V> {
     }
 
     /**
-     * Using the other methods in this interface, put an integer value
-     * into this dictionary.
-     *
-     * @param key The key for the <tt>Integer</tt> value to save.
-     * @param value The int value to be saved.
-     * @return The previous value for this key.
-     */
-    @SuppressWarnings("unchecked")
-    default V putInt(K key, int value) {
-        return put(key, (V)Integer.valueOf(value));
-    }
-
-    /**
      * Using the other methods in this interface, retrieve a boolean value
      * from this dictionary; returning false if the key does not exist.
      *
@@ -200,19 +187,6 @@ public interface Dictionary<K, V> {
     }
 
     /**
-     * Using the other methods in this interface, put a boolean value
-     * into this dictionary.
-     *
-     * @param key The key for the <tt>Boolean</tt> value to save.
-     * @param value The value to be saved.
-     * @return The previous value for this key.
-     */
-    @SuppressWarnings("unchecked")
-    default V putBoolean(K key, boolean value) {
-        return put(key, (V)Boolean.valueOf(value));
-    }
-
-    /**
      * Using the other methods in this interface, retrieve a {@link Color} 
value
      * from this dictionary; returning <tt>null</tt> if the key does not exist.
      *
@@ -246,4 +220,16 @@ public interface Dictionary<K, V> {
             put(key, map.get(key));
         }
     }
+
+    /**
+     * Copy the value from one dictionary to this one.
+     *
+     * @param key Key for value to be copied.
+     * @param source The source to copy from.
+     * @return The previous value in the target dictionary.
+     */
+    default Object copy(K key, Dictionary<K, V> source) {
+        return put(key, source.get(key));
+    }
+
 }

Modified: 
pivot/trunk/core/test/org/apache/pivot/collections/test/DictionaryTest.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/core/test/org/apache/pivot/collections/test/DictionaryTest.java?rev=1823398&r1=1823397&r2=1823398&view=diff
==============================================================================
--- pivot/trunk/core/test/org/apache/pivot/collections/test/DictionaryTest.java 
(original)
+++ pivot/trunk/core/test/org/apache/pivot/collections/test/DictionaryTest.java 
Tue Feb  6 22:05:12 2018
@@ -28,9 +28,9 @@ public class DictionaryTest {
     @Test
     public void test() {
         HashMap<String, Integer> map = new HashMap<>();
-        map.putInt("one", 1);
-        map.putInt("two", 2);
-        map.putInt("three", 300);
+        map.put("one", 1);
+        map.put("two", 2);
+        map.put("three", 300);
         assertEquals(map.getInt("one"), 1);
         assertEquals(map.getInt("two"), 2);
         assertEquals(map.getInt("three"), 300);
@@ -39,9 +39,9 @@ public class DictionaryTest {
     @Test
     public void boolTest() {
         HashMap<String, Boolean> map = new HashMap<>();
-        map.putBoolean("true", false);
-        map.putBoolean("false", true);
-        map.putBoolean("other", true);
+        map.put("true", false);
+        map.put("false", true);
+        map.put("other", true);
         assertEquals(map.getBoolean("true"), false);
         assertEquals(map.getBoolean("false"), true);
         assertEquals(map.getBoolean("other"), true);

Modified: pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java
URL: 
http://svn.apache.org/viewvc/pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java?rev=1823398&r1=1823397&r2=1823398&view=diff
==============================================================================
--- pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java (original)
+++ pivot/trunk/wtk/src/org/apache/pivot/wtk/Component.java Tue Feb  6 22:05:12 
2018
@@ -118,12 +118,16 @@ public abstract class Component implemen
             return previousValue;
         }
 
-        public Object putInt(Style key, int value) {
-            return putInt(key.toString(), value);
-        }
-
-        public Object putBoolean(Style key, boolean value) {
-            return putBoolean(key.toString(), value);
+        /**
+         * Copy the named style from one style dictionary to this one.
+         *
+         * @param key Style value to be copied.
+         * @param source The source to copy from.
+         * @return The previous value in the target dictionary (but note
+         * the caveats from the {@link #put(String,Object)} method.
+         */
+        public Object copy(Style key, Dictionary<String,Object> source) {
+            return copy(key.toString(), source);
         }
 
         /**


Reply via email to