Reuse constants

This commit is contained in:
Gary Gregory 2022-11-25 09:19:47 -05:00
parent a8c0df14ca
commit 6031f5395b
8 changed files with 17 additions and 10 deletions

View File

@ -54,6 +54,7 @@ import org.apache.commons.collections4.collection.TransformedCollection;
import org.apache.commons.collections4.collection.UnmodifiableCollection;
import org.apache.commons.collections4.functors.DefaultEquator;
import org.apache.commons.collections4.queue.CircularFifoQueue;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -1029,7 +1030,7 @@ public class CollectionUtilsTest extends MockTestCase {
@Test
public void reverse() {
CollectionUtils.reverseArray(new Object[] {});
final Integer[] a = collectionA.toArray(new Integer[collectionA.size()]);
final Integer[] a = collectionA.toArray(ArrayUtils.EMPTY_INTEGER_OBJECT_ARRAY);
CollectionUtils.reverseArray(a);
// assume our implementation is correct if it returns the same order as the Java function
Collections.reverse(collectionA);

View File

@ -167,7 +167,7 @@ public class MapUtilsTest {
() -> assertThrows(NullPointerException.class, () -> MapUtils.putAll(null, new Object[0]))
);
Map<String, String> test = MapUtils.putAll(new HashMap<String, String>(), new String[0]);
Map<String, String> test = MapUtils.putAll(new HashMap<String, String>(), org.apache.commons.lang3.ArrayUtils.EMPTY_STRING_ARRAY);
assertEquals(0, test.size());
// sub array

View File

@ -35,6 +35,7 @@ import org.apache.commons.collections4.Bag;
import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
/**
@ -503,7 +504,7 @@ public abstract class AbstractBagTest<T> extends AbstractCollectionTest<T> {
bag.add((T) "B");
bag.add((T) "B");
bag.add((T) "C");
final String[] array = bag.toArray(new String[0]);
final String[] array = bag.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
int a = 0, b = 0, c = 0;
for (final String element : array) {
a += element.equals("A") ? 1 : 0;

View File

@ -39,6 +39,7 @@ import java.util.Objects;
import java.util.function.Predicate;
import org.apache.commons.collections4.AbstractObjectTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
@ -1120,7 +1121,7 @@ public abstract class AbstractCollectionTest<E> extends AbstractObjectTest {
"toArray(null) should raise NPE");
verify();
array = getCollection().toArray(new Object[0]);
array = getCollection().toArray(ArrayUtils.EMPTY_OBJECT_ARRAY);
a = getCollection().toArray();
if ((getIterationBehaviour() & UNORDERED) != 0) {

View File

@ -24,6 +24,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
/**
@ -170,7 +171,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
assertEquals(FixedOrderComparator.UnknownObjectBehavior.BEFORE, comparator.getUnknownObjectBehavior());
LinkedList<String> keys = new LinkedList<>(Arrays.asList(topCities));
keys.addFirst("Minneapolis");
assertComparatorYieldsOrder(keys.toArray(new String[0]), comparator);
assertComparatorYieldsOrder(keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY), comparator);
assertEquals(-1, comparator.compare("Minneapolis", "New York"));
assertEquals( 1, comparator.compare("New York", "Minneapolis"));
@ -180,7 +181,7 @@ public class FixedOrderComparatorTest extends AbstractComparatorTest<String> {
comparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.AFTER);
keys = new LinkedList<>(Arrays.asList(topCities));
keys.add("Minneapolis");
assertComparatorYieldsOrder(keys.toArray(new String[0]), comparator);
assertComparatorYieldsOrder(keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY), comparator);
assertEquals( 1, comparator.compare("Minneapolis", "New York"));
assertEquals(-1, comparator.compare("New York", "Minneapolis"));

View File

@ -28,6 +28,7 @@ import java.util.NoSuchElementException;
import org.apache.commons.collections4.Predicate;
import org.apache.commons.collections4.functors.NotNullPredicate;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -105,7 +106,7 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
@Test
public void testReturnValues() {
verifyElementsInPredicate(new String[0]);
verifyElementsInPredicate(ArrayUtils.EMPTY_STRING_ARRAY);
verifyElementsInPredicate(new String[] { "a" });
verifyElementsInPredicate(new String[] { "b" });
verifyElementsInPredicate(new String[] { "c" });

View File

@ -29,6 +29,7 @@ import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.apache.commons.collections4.BulkTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -1390,7 +1391,7 @@ public class CursorableLinkedListTest<E> extends AbstractLinkedListTest<E> {
assertEquals("5", elts[4]);
assertEquals(5, elts.length);
final String[] elts2 = list.toArray(new String[0]);
final String[] elts2 = list.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
assertEquals("1", elts2[0]);
assertEquals("2", elts2[1]);
assertEquals("3", elts2[2]);
@ -1513,7 +1514,7 @@ public class CursorableLinkedListTest<E> extends AbstractLinkedListTest<E> {
list.add(prefix + bulk + element);
list.add(prefix + bulk + bulk + element);
}
return list.toArray(new String[0]);
return list.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
}
@Override

View File

@ -34,6 +34,7 @@ import org.apache.commons.collections4.BulkTest;
import org.apache.commons.collections4.MultiSet;
import org.apache.commons.collections4.collection.AbstractCollectionTest;
import org.apache.commons.collections4.set.AbstractSetTest;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
/**
@ -517,7 +518,7 @@ public abstract class AbstractMultiSetTest<T> extends AbstractCollectionTest<T>
multiset.add((T) "B");
multiset.add((T) "B");
multiset.add((T) "C");
final String[] array = multiset.toArray(new String[0]);
final String[] array = multiset.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
int a = 0, b = 0, c = 0;
for (final String element : array) {
a += element.equals("A") ? 1 : 0;