[LANG-1332] ImmutableTriple.nullTriple()

This commit is contained in:
Gary Gregory 2017-05-14 20:41:59 -07:00
parent e1bc286245
commit 585b1cb97b
3 changed files with 54 additions and 0 deletions

View File

@ -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">

View File

@ -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 */

View File

@ -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;
@ -85,6 +87,39 @@ public class ImmutableTripleTest {
assertEquals(ImmutableTriple.of(null, "foo", Boolean.TRUE).hashCode(), ImmutableTriple.of(null, "foo", Boolean.TRUE).hashCode());
}
@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());