Author: erans
Date: Wed Oct 16 08:37:08 2013
New Revision: 1532687

URL: http://svn.apache.org/r1532687
Log:
MATH-1041
Factory method. Thanks to Sean Owen.

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=1532687&r1=1532686&r2=1532687&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 
Wed Oct 16 08:37:08 2013
@@ -138,4 +138,17 @@ public class Pair<K, V> {
     public String toString() {
         return "[" + getKey() + ", " + getValue() + "]";
     }
+
+    /**
+     * Convenience factory method that calls the
+     * {@link #Pair(Object, Object) constructor}.
+     *
+     * @param k First element of the pair.
+     * @param v Second element of the pair.
+     * @return a new {@code Pair} containing {@code k} and {@code v}.
+     * @since 3.3
+     */
+    public static <K, V> Pair<K, V> create(K k, V v) {
+        return new Pair<K, V>(k, v);
+    }
 }

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=1532687&r1=1532686&r2=1532687&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
 Wed Oct 16 08:37:08 2013
@@ -79,6 +79,14 @@ public class PairTest {
         Assert.assertEquals("[foo, 3]", new Pair<String, Integer>("foo", 
3).toString());
     }
 
+    @Test
+    public void testCreate() {
+        final Pair<String, Integer> p1 = Pair.create("foo", 3);
+        Assert.assertNotNull(p1);
+        final Pair<String, Integer> p2 = new Pair<String, Integer>("foo", 3);
+        Assert.assertEquals(p2, p1);
+    }
+
     /**
      * A mutable integer.
      */


Reply via email to