You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/07/04 01:03:57 UTC

svn commit: r1357004 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/util/Pair.java test/java/org/apache/commons/math3/util/PairTest.java

Author: erans
Date: Tue Jul  3 23:03:55 2012
New Revision: 1357004

URL: http://svn.apache.org/viewvc?rev=1357004&view=rev
Log:
MATH-810
Added new accessors.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Pair.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PairTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Pair.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Pair.java?rev=1357004&r1=1357003&r2=1357004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Pair.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/util/Pair.java Tue Jul  3 23:03:55 2012
@@ -39,8 +39,8 @@ public class Pair<K, V> {
      * Create an entry representing a mapping from the specified key to the
      * specified value.
      *
-     * @param k Key.
-     * @param v Value.
+     * @param k Key (first element of the pair).
+     * @param v Value (second element of the pair).
      */
     public Pair(K k, V v) {
         key = k;
@@ -59,7 +59,7 @@ public class Pair<K, V> {
     /**
      * Get the key.
      *
-     * @return the key.
+     * @return the key (first element of the pair).
      */
     public K getKey() {
         return key;
@@ -68,13 +68,31 @@ public class Pair<K, V> {
     /**
      * Get the value.
      *
-     * @return the value.
+     * @return the value (second element of the pair).
      */
     public V getValue() {
         return value;
     }
 
     /**
+     * Get the first element of the pair.
+     *
+     * @return the first element of the pair.
+     */
+    public K getFirst() {
+        return key;
+    }
+
+    /**
+     * Get the second element of the pair.
+     *
+     * @return the second element of the pair.
+     */
+    public V getSecond() {
+        return value;
+    }
+
+    /**
      * Compare the specified object with this entry for equality.
      *
      * @param o Object.

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PairTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PairTest.java?rev=1357004&r1=1357003&r2=1357004&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PairTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/util/PairTest.java Tue Jul  3 23:03:55 2012
@@ -30,6 +30,17 @@ public class PairTest {
     }
 
     @Test
+    public void testAccessor2() {
+        final Pair<Integer, Double> p
+            = new Pair<Integer, Double>(new Integer(1), new Double(2));
+
+        // Check that both APIs refer to the same data.
+
+        Assert.assertTrue(p.getFirst() == p.getKey());
+        Assert.assertTrue(p.getSecond() == p.getValue());
+    }
+
+    @Test
     public void testEquals() {
         Pair<Integer, Double> p1 = new Pair<Integer, Double>(null, null);
         Assert.assertFalse(p1.equals(null));