From da0bbbb9a6de9fe587d091debca65e53adf4d384 Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Wed, 16 Oct 2013 08:08:07 +0000 Subject: [PATCH] MATH-1041 Added "toString" method. Thanks to Sean Owen. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1532679 13f79535-47bb-0310-9956-ffa450edef68 --- src/main/java/org/apache/commons/math3/util/Pair.java | 5 +++++ src/test/java/org/apache/commons/math3/util/PairTest.java | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/org/apache/commons/math3/util/Pair.java b/src/main/java/org/apache/commons/math3/util/Pair.java index 1e233e661..f174b2f34 100644 --- a/src/main/java/org/apache/commons/math3/util/Pair.java +++ b/src/main/java/org/apache/commons/math3/util/Pair.java @@ -133,4 +133,9 @@ public class Pair { return result; } + + @Override + public String toString() { + return "[" + getKey() + ", " + getValue() + "]"; + } } diff --git a/src/test/java/org/apache/commons/math3/util/PairTest.java b/src/test/java/org/apache/commons/math3/util/PairTest.java index 1f3a8fed7..e349fd767 100644 --- a/src/test/java/org/apache/commons/math3/util/PairTest.java +++ b/src/test/java/org/apache/commons/math3/util/PairTest.java @@ -73,6 +73,12 @@ public class PairTest { Assert.assertFalse(p1.hashCode() == p2.hashCode()); } + @Test + public void testToString() { + Assert.assertEquals("[null, null]", new Pair(null, null).toString()); + Assert.assertEquals("[foo, 3]", new Pair("foo", 3).toString()); + } + /** * A mutable integer. */