mirror of
https://github.com/apache/commons-lang.git
synced 2025-02-10 03:55:10 +00:00
[LANG-1332] ImmutableTriple.nullTriple()
This commit is contained in:
parent
e1bc286245
commit
585b1cb97b
@ -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-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-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-1331" type="add" dev="ggregory">Add ImmutablePair.nullPair()</action>
|
||||||
|
<action issue="LANG-1332" type="add" dev="ggregory">Add ImmutableTriple.nullTriple()</action>
|
||||||
</release>
|
</release>
|
||||||
|
|
||||||
<release version="3.5" date="2016-10-13" description="New features including Java 9 detection">
|
<release version="3.5" date="2016-10-13" description="New features including Java 9 detection">
|
||||||
|
@ -34,9 +34,27 @@
|
|||||||
*/
|
*/
|
||||||
public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
|
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 */
|
/** Serialization version */
|
||||||
private static final long serialVersionUID = 1L;
|
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 */
|
/** Left object */
|
||||||
public final L left;
|
public final L left;
|
||||||
/** Middle object */
|
/** Middle object */
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
@ -85,6 +87,39 @@ public void testHashCode() throws Exception {
|
|||||||
assertEquals(ImmutableTriple.of(null, "foo", Boolean.TRUE).hashCode(), ImmutableTriple.of(null, "foo", Boolean.TRUE).hashCode());
|
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
|
@Test
|
||||||
public void testToString() throws Exception {
|
public void testToString() throws Exception {
|
||||||
assertEquals("(null,null,null)", ImmutableTriple.of(null, null, null).toString());
|
assertEquals("(null,null,null)", ImmutableTriple.of(null, null, null).toString());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user