Add fluent-style ArrayUtils.sort(Object[], Comparable).

This commit is contained in:
Gary Gregory 2020-11-15 12:08:32 -05:00
parent 35799d0958
commit 3bda8be036
4 changed files with 25 additions and 2 deletions

View File

@ -59,7 +59,6 @@ The <action> type attribute can be add,update,fix,remove.
<action issue="LANG-1541" type="fix" dev="ggregory" due-to="Arturo Bernal, Gary Gregory">ArrayUtils.contains() and indexOf() fails to handle Double.NaN #647.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix potential NPE in TypeUtils.isAssignable(Type, ParameterizedType, Map, Type>).</action>
<action issue="LANG-1420" type="fix" dev="ggregory" due-to="Gordon Fraser, Rostislav Krasny, Arturo Bernal, Gary Gregory">TypeUtils.isAssignable returns wrong result for GenericArrayType and ParameterizedType, #643.</action>
<!-- ADDS -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanUtils.booleanValues().</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add BooleanUtils.primitiveValues().</action>
@ -68,6 +67,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="add" dev="ggregory" due-to="Edgar Asatryan">More test coverage for CharSequenceUtils. #631.</action>
<action issue="LANG-1596" type="update" dev="aherbert" due-to="Richard Eckart de Castilho">ArrayUtils.toPrimitive(Object) does not support boolean and other types #607.</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add fluent-style ArrayUtils.sort(Object[]).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add fluent-style ArrayUtils.sort(Object[], Comparable).</action>
<!-- UPDATES -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Enable Dependabot #587.</action>
<action type="update" dev="chtompki">Bump junit-jupiter from 5.6.2 to 5.7.0.</action>

View File

@ -7872,6 +7872,22 @@ public static int indexOf(final int[] array, final int valueToFind, int startInd
return array;
}
/**
* Sorts and returns the given array.
*
* @param <T> the array type.
* @param array the array to sort.
* @param comparator the comparator to determine the order of the array.
* A {@code null} value uses the elements' {@link Comparable natural ordering}.
* @return the given array.
* @see Arrays#sort(Object[])
* @since 3.12
*/
public static <T> T[] sort(T[] array, Comparator<? super T> comparator) {
Arrays.sort(array, comparator);
return array;
}
/**
* <p>Produces a new {@code boolean} array containing the elements
* between the start and end indices.

View File

@ -5120,6 +5120,13 @@ public class ArrayUtilsTest {
assertEquals(array1, ArrayUtils.sort(array2));
}
public void testSortComparable() {
final String[] array1 = ArrayUtils.toArray("foo", "bar");
final String[] array2 = array1.clone();
Arrays.sort(array1);
assertEquals(array1, ArrayUtils.sort(array2, String::compareTo));
}
@Test
public void testSubarrayBoolean() {
final boolean[] nullArray = null;

View File

@ -790,7 +790,7 @@ public class TypeUtilsTest<B> {
assertFalse(paramType.getClass().isAssignableFrom(WildcardType.class));
WildcardType testType = TypeUtils.WILDCARD_ALL;
// TODO This test returns true unlike the test above.
// TODO This test returns true unlike the test above.
// Is this a bug in this test or in the main code?
assertFalse(TypeUtils.isAssignable(paramType, testType),
() -> String.format("TypeUtils.isAssignable(%s, %s)", paramType, testType));