Use ArraySorter.

This commit is contained in:
Gary Gregory 2020-12-22 16:06:55 -05:00
parent 5aab41b365
commit 44b0bb5273
4 changed files with 8 additions and 11 deletions

View File

@ -5231,8 +5231,7 @@ static Object removeAll(final Object array, final BitSet indices) {
static Object removeAll(final Object array, final int... indices) {
final int length = getLength(array);
int diff = 0; // number of distinct indexes, i.e. number of entries that will be removed
final int[] clonedIndices = clone(indices);
Arrays.sort(clonedIndices);
final int[] clonedIndices = ArraySorter.sort(clone(indices));
// identify length of result array
if (isNotEmpty(clonedIndices)) {

View File

@ -20,12 +20,12 @@
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.lang3.ArraySorter;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.Validate;
@ -191,8 +191,7 @@ private static void reflectionAppend(final Object object, final Class<?> clazz,
try {
register(object);
// The elements in the returned array are not sorted and are not in any particular order.
final Field[] fields = clazz.getDeclaredFields();
Arrays.sort(fields, Comparator.comparing(Field::getName));
final Field[] fields = ArraySorter.sort(clazz.getDeclaredFields(), Comparator.comparing(Field::getName));
AccessibleObject.setAccessible(fields, true);
for (final Field field : fields) {
if (!ArrayUtils.contains(excludeFields, field.getName())

View File

@ -26,6 +26,7 @@
import java.util.Comparator;
import java.util.List;
import org.apache.commons.lang3.ArraySorter;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.Validate;
@ -640,8 +641,7 @@ protected void appendFieldsIn(final Class<?> clazz) {
return;
}
// The elements in the returned array are not sorted and are not in any particular order.
final Field[] fields = clazz.getDeclaredFields();
Arrays.sort(fields, Comparator.comparing(Field::getName));
final Field[] fields = ArraySorter.sort(clazz.getDeclaredFields(), Comparator.comparing(Field::getName));
AccessibleObject.setAccessible(fields, true);
for (final Field field : fields) {
final String fieldName = field.getName();
@ -801,8 +801,7 @@ public ReflectionToStringBuilder setExcludeFieldNames(final String... excludeFie
this.excludeFieldNames = null;
} else {
//clone and remove nulls
this.excludeFieldNames = toNoNullStringArray(excludeFieldNamesParam);
Arrays.sort(this.excludeFieldNames);
this.excludeFieldNames = ArraySorter.sort(toNoNullStringArray(excludeFieldNamesParam));
}
return this;
}

View File

@ -18,6 +18,7 @@
import java.util.Arrays;
import org.apache.commons.lang3.ArraySorter;
import org.apache.commons.lang3.StringUtils;
/**
@ -284,8 +285,7 @@ static final class CharSetMatcher extends StrMatcher {
* @param chars the characters to match, must not be null
*/
CharSetMatcher(final char[] chars) {
this.chars = chars.clone();
Arrays.sort(this.chars);
this.chars = ArraySorter.sort(chars.clone());
}
/**