Repository: commons-lang Updated Branches: refs/heads/master e1bc28624 -> 585b1cb97
[LANG-1332] ImmutableTriple.nullTriple() Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/585b1cb9 Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/585b1cb9 Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/585b1cb9 Branch: refs/heads/master Commit: 585b1cb97b4b9e81b55d68e04b6c1e1195058a8f Parents: e1bc286 Author: Gary Gregory <ggreg...@apache.org> Authored: Sun May 14 20:41:59 2017 -0700 Committer: Gary Gregory <ggreg...@apache.org> Committed: Sun May 14 20:41:59 2017 -0700 ---------------------------------------------------------------------- src/changes/changes.xml | 1 + .../commons/lang3/tuple/ImmutableTriple.java | 18 ++++++++++ .../lang3/tuple/ImmutableTripleTest.java | 35 ++++++++++++++++++++ 3 files changed, 54 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/585b1cb9/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 768644c..c106896 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove. <action issue="LANG-1272" type="add" dev="ebourg">Add shuffle methods to ArrayUtils</action> <action issue="LANG-1317" type="add" dev="pschumacher" due-to="Yasser Zamani">Add MethodUtils#findAnnotation and extend MethodUtils#getMethodsWithAnnotation for non-public, super-class and interface methods</action> <action issue="LANG-1331" type="add" dev="ggregory">Add ImmutablePair.nullPair()</action> + <action issue="LANG-1332" type="add" dev="ggregory">Add ImmutableTriple.nullTriple()</action> </release> <release version="3.5" date="2016-10-13" description="New features including Java 9 detection"> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/585b1cb9/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java b/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java index 68ef742..49f5746 100644 --- a/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java +++ b/src/main/java/org/apache/commons/lang3/tuple/ImmutableTriple.java @@ -34,9 +34,27 @@ package org.apache.commons.lang3.tuple; */ public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> { + /** + * An immutable triple of nulls. + */ + // This is not defined with generics to avoid warnings in call sites. + @SuppressWarnings("rawtypes") + private static final ImmutableTriple NULL = ImmutableTriple.of(null, null, null); + /** Serialization version */ private static final long serialVersionUID = 1L; + /** + * Returns an immutable triple of nulls. + * + * @return an immutable triple of nulls. + * @since 3.6 + */ + @SuppressWarnings("unchecked") + public static <L, M, R> ImmutableTriple<L, M, R> nullTriple() { + return NULL; + } + /** Left object */ public final L left; /** Middle object */ http://git-wip-us.apache.org/repos/asf/commons-lang/blob/585b1cb9/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java index 3e36932..3be6660 100644 --- a/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java +++ b/src/test/java/org/apache/commons/lang3/tuple/ImmutableTripleTest.java @@ -18,7 +18,9 @@ package org.apache.commons.lang3.tuple; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; @@ -86,6 +88,39 @@ public class ImmutableTripleTest { } @Test + public void testNullTripleEquals() { + assertEquals(ImmutableTriple.nullTriple(), ImmutableTriple.nullTriple()); + } + + @Test + public void testNullTripleSame() { + assertSame(ImmutableTriple.nullTriple(), ImmutableTriple.nullTriple()); + } + + @Test + public void testNullTripleLeft() { + assertNull(ImmutableTriple.nullTriple().getLeft()); + } + + @Test + public void testNullTripleMiddle() { + assertNull(ImmutableTriple.nullTriple().getMiddle()); + } + + @Test + public void testNullTripleRight() { + assertNull(ImmutableTriple.nullTriple().getRight()); + } + + @Test + public void testNullTripleTyped() { + // No compiler warnings + // How do we assert that? + ImmutableTriple<String, String, String> triple = ImmutableTriple.nullTriple(); + assertNotNull(triple); + } + + @Test public void testToString() throws Exception { assertEquals("(null,null,null)", ImmutableTriple.of(null, null, null).toString()); assertEquals("(null,two,null)", ImmutableTriple.of(null, "two", null).toString());