commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1477599 - in /commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue: AbstractKeyValue.java AbstractMapEntry.java DefaultKeyValue.java
Date Tue, 30 Apr 2013 12:44:13 GMT
Author: sebb
Date: Tue Apr 30 12:44:12 2013
New Revision: 1477599

URL: http://svn.apache.org/r1477599
Log:
Privatise key & value; add protected setters (fields were protected)

Modified:
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java
    commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java?rev=1477599&r1=1477598&r2=1477599&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractKeyValue.java
Tue Apr 30 12:44:12 2013
@@ -28,9 +28,9 @@ import org.apache.commons.collections4.K
 public abstract class AbstractKeyValue<K, V> implements KeyValue<K, V> {
 
     /** The key */
-    protected K key;
+    private K key;
     /** The value */
-    protected V value;
+    private V value;
 
     /**
      * Constructs a new pair with the specified key and given value.
@@ -53,6 +53,12 @@ public abstract class AbstractKeyValue<K
         return key;
     }
 
+    protected K setKey(K key) {
+        final K old = this.key;
+        this.key = key;
+        return old;
+    }
+
     /**
      * Gets the value from the pair.
      *
@@ -62,6 +68,12 @@ public abstract class AbstractKeyValue<K
         return value;
     }
 
+    protected V setValue(V value) {
+        final V old = this.value;
+        this.value = value;
+        return old;
+    }
+
     /**
      * Gets a debugging String view of the pair.
      * 

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java?rev=1477599&r1=1477598&r2=1477599&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/AbstractMapEntry.java
Tue Apr 30 12:44:12 2013
@@ -39,7 +39,7 @@ public abstract class AbstractMapEntry<K
 
     // Map.Entry interface
     //-------------------------------------------------------------------------
-    /** 
+    /**
      * Sets the value stored in this <code>Map.Entry</code>.
      * <p>
      * This <code>Map.Entry</code> is not connected to a Map, so only the
@@ -48,10 +48,9 @@ public abstract class AbstractMapEntry<K
      * @param value  the new value
      * @return the previous value
      */
+    @Override
     public V setValue(final V value) {
-        final V answer = this.value;
-        this.value = value;
-        return answer;
+        return super.setValue(value);
     }
 
     /**

Modified: commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java
URL: http://svn.apache.org/viewvc/commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java?rev=1477599&r1=1477598&r2=1477599&view=diff
==============================================================================
--- commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java
(original)
+++ commons/proper/collections/trunk/src/main/java/org/apache/commons/collections4/keyvalue/DefaultKeyValue.java
Tue Apr 30 12:44:12 2013
@@ -77,14 +77,13 @@ public class DefaultKeyValue<K, V> exten
      * @return the old key
      * @throws IllegalArgumentException if key is this object
      */
+    @Override
     public K setKey(final K key) {
         if (key == this) {
             throw new IllegalArgumentException("DefaultKeyValue may not contain itself as
a key.");
         }
 
-        final K old = this.key;
-        this.key = key;
-        return old;
+        return super.setKey(key);
     }
 
     /** 
@@ -94,14 +93,13 @@ public class DefaultKeyValue<K, V> exten
      * @param value the new value
      * @throws IllegalArgumentException if value is this object
      */
+    @Override
     public V setValue(final V value) {
         if (value == this) {
             throw new IllegalArgumentException("DefaultKeyValue may not contain itself as
a value.");
         }
 
-        final V old = this.value;
-        this.value = value;
-        return old;
+        return super.setValue(value);
     }
 
     //-----------------------------------------------------------------------



Mime
View raw message