Author: ggregory
Date: Mon Apr 25 16:00:32 2011
New Revision: 1096506

URL: http://svn.apache.org/viewvc?rev=1096506&view=rev
Log:
Add back Pair#toString(String format).

Modified:
    
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/tuple/Pair.java
    
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/tuple/PairTest.java

Modified: 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/tuple/Pair.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/tuple/Pair.java?rev=1096506&r1=1096505&r2=1096506&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/tuple/Pair.java
 (original)
+++ 
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/tuple/Pair.java
 Mon Apr 25 16:00:32 2011
@@ -180,4 +180,15 @@ public abstract class Pair<L, R> impleme
                 formatter, flags, width, precision);
     }
 
+    /**
+     * Formats the receiver using the given string.
+     * 
+     * @param format
+     *            The format string where <code>%1$</code> is the key (left) 
and <code>%2$</code> is the value (right).
+     * @return The formatted string
+     */
+    public Object toString(String format) {
+        return String.format(format, getLeft(), getRight());
+    }
+
 }

Modified: 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/tuple/PairTest.java?rev=1096506&r1=1096505&r2=1096506&view=diff
==============================================================================
--- 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
 (original)
+++ 
commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/tuple/PairTest.java
 Mon Apr 25 16:00:32 2011
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+import java.util.Calendar;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map.Entry;
@@ -29,6 +30,7 @@ import org.junit.Test;
 
 /**
  * Test the Pair class.
+ * 
  * @version $Id$
  */
 public class PairTest {
@@ -96,4 +98,12 @@ public class PairTest {
         assertEquals("(Key,Value)", pair.toString());
     }
 
+    @Test
+    public void testToStringCustom() throws Exception {
+        Calendar date = Calendar.getInstance();
+        date.set(2011, Calendar.APRIL, 25);
+        Pair<String, Calendar> pair = Pair.of("DOB", date);
+        assertEquals("Test created on " + "04-25-2011", pair.toString("Test 
created on %2$tm-%2$td-%2$tY"));
+    }
+    
 }


Reply via email to