[LANG-1458] Add EMPTY_ARRAY constants to classes in

org.apache.commons.lang3.tuple
This commit is contained in:
Gary Gregory 2019-05-10 08:27:33 -04:00
parent f2b7f98840
commit 86cf126f13
9 changed files with 142 additions and 1 deletions

View File

@ -47,7 +47,8 @@ The <action> type attribute can be add,update,fix,remove.
<release version="3.10" date="YYYY-MM-DD" description="TBD">
<action issue="LANG-1450" type="fix" dev="chtompki">Generate javadoc jar on build.</action>
<action issue="LANG-1457" type="fix" dev="ggregory">Add ExceptionUtils.throwableOfType(Throwable, Class) and friends.</action>
<action issue="LANG-1457" type="add" dev="ggregory">Add ExceptionUtils.throwableOfType(Throwable, Class) and friends.</action>
<action issue="LANG-1458" type="add" dev="ggregory">Add EMPTY_ARRAY constants to classes in org.apache.commons.lang3.tuple.</action>
</release>
<release version="3.9" date="2019-04-09" description="New features and bug fixes. Requires Java 8, supports Java 9, 10, 11">

View File

@ -33,6 +33,28 @@
*/
public final class ImmutablePair<L, R> extends Pair<L, R> {
/**
* An empty array.
* <p>
* Consider using {@link #emptyArray()} to avoid generics warnings.
* </p>
*
* @since 3.10.
*/
public static final ImmutablePair<?, ?>[] EMPTY_ARRAY = new ImmutablePair[0];
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @return the empty array singleton that can be assigned without compiler warning.
*
* @since 3.10.
*/
@SuppressWarnings("unchecked")
public static final <L, R> ImmutablePair<L, R>[] emptyArray() {
return (ImmutablePair<L, R>[]) EMPTY_ARRAY;
}
/**
* An immutable pair of nulls.
*/

View File

@ -34,6 +34,28 @@
*/
public final class ImmutableTriple<L, M, R> extends Triple<L, M, R> {
/**
* An empty array.
* <p>
* Consider using {@link #emptyArray()} to avoid generics warnings.
* </p>
*
* @since 3.10.
*/
public static final ImmutableTriple<?, ?, ?>[] EMPTY_ARRAY = new ImmutableTriple[0];
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @return the empty array singleton that can be assigned without compiler warning.
*
* @since 3.10.
*/
@SuppressWarnings("unchecked")
public static final <L, M, R> ImmutableTriple<L, M, R>[] emptyArray() {
return (ImmutableTriple<L, M, R>[]) EMPTY_ARRAY;
}
/**
* An immutable triple of nulls.
*/

View File

@ -28,6 +28,28 @@
*/
public class MutablePair<L, R> extends Pair<L, R> {
/**
* An empty array.
* <p>
* Consider using {@link #emptyArray()} to avoid generics warnings.
* </p>
*
* @since 3.10.
*/
public static final MutablePair<?, ?>[] EMPTY_ARRAY = new MutablePair[0];
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @return the empty array singleton that can be assigned without compiler warning.
*
* @since 3.10.
*/
@SuppressWarnings("unchecked")
public static final <L, R> MutablePair<L, R>[] emptyArray() {
return (MutablePair<L, R>[]) EMPTY_ARRAY;
}
/** Serialization version */
private static final long serialVersionUID = 4954918890077093841L;

View File

@ -29,6 +29,28 @@
*/
public class MutableTriple<L, M, R> extends Triple<L, M, R> {
/**
* The empty array singleton.
* <p>
* Consider using {@link #emptyArray()} to avoid generics warnings.
* </p>
*
* @since 3.10.
*/
public static final MutableTriple<?, ?, ?>[] EMPTY_ARRAY = new MutableTriple[0];
/**
* Returns the empty array singleton that can be assigned without compiler warning.
*
* @return the empty array singleton that can be assigned without compiler warning.
*
* @since 3.10.
*/
@SuppressWarnings("unchecked")
public static final <L, M, R> MutableTriple<L, M, R>[] emptyArray() {
return (MutableTriple<L, M, R>[]) EMPTY_ARRAY;
}
/** Serialization version */
private static final long serialVersionUID = 1L;

View File

@ -39,6 +39,19 @@
*/
public class ImmutablePairTest {
@Test
public void testEmptyArrayLength() {
@SuppressWarnings("unchecked")
final ImmutablePair<Integer, String>[] empty = (ImmutablePair<Integer, String>[]) ImmutablePair.EMPTY_ARRAY;
assertEquals(0, empty.length);
}
@Test
public void testEmptyArrayGenerics() {
final ImmutablePair<Integer, String>[] empty = ImmutablePair.emptyArray();
assertEquals(0, empty.length);
}
@Test
public void testBasic() {
final ImmutablePair<Integer, String> pair = new ImmutablePair<>(0, "foo");

View File

@ -39,6 +39,19 @@
*/
public class ImmutableTripleTest {
@Test
public void testEmptyArrayLength() {
@SuppressWarnings("unchecked")
final ImmutableTriple<Integer, String, Boolean>[] empty = (ImmutableTriple<Integer, String, Boolean>[]) ImmutableTriple.EMPTY_ARRAY;
assertEquals(0, empty.length);
}
@Test
public void testEmptyArrayGenerics() {
final ImmutableTriple<Integer, String, Boolean>[] empty = ImmutableTriple.emptyArray();
assertEquals(0, empty.length);
}
@Test
public void testBasic() {
final ImmutableTriple<Integer, String, Boolean> triple = new ImmutableTriple<>(0, "foo", Boolean.TRUE);

View File

@ -32,6 +32,19 @@
*/
public class MutablePairTest {
@Test
public void testEmptyArrayLength() {
@SuppressWarnings("unchecked")
final MutablePair<Integer, String>[] empty = (MutablePair<Integer, String>[]) MutablePair.EMPTY_ARRAY;
assertEquals(0, empty.length);
}
@Test
public void testEmptyArrayGenerics() {
final MutablePair<Integer, String>[] empty = MutablePair.emptyArray();
assertEquals(0, empty.length);
}
@Test
public void testBasic() {
final MutablePair<Integer, String> pair = new MutablePair<>(0, "foo");

View File

@ -32,6 +32,19 @@
*/
public class MutableTripleTest {
@Test
public void testEmptyArrayLength() {
@SuppressWarnings("unchecked")
final MutableTriple<Integer, String, Boolean>[] empty = (MutableTriple<Integer, String, Boolean>[]) MutableTriple.EMPTY_ARRAY;
assertEquals(0, empty.length);
}
@Test
public void testEmptyArrayGenerics() {
final MutableTriple<Integer, String, Boolean>[] empty = MutableTriple.emptyArray();
assertEquals(0, empty.length);
}
@Test
public void testBasic() {
final MutableTriple<Integer, String, Boolean> triple = new MutableTriple<>(0, "foo", Boolean.FALSE);