[LANG-1561] use List.sort instead of Collection.sort (#546)
* use_List_sort * Update MethodUtils.java * Update ObjectToStringComparatorTest.java
This commit is contained in:
parent
2d21e19f06
commit
7651124bec
|
@ -25,7 +25,6 @@ import java.lang.reflect.Type;
|
||||||
import java.lang.reflect.TypeVariable;
|
import java.lang.reflect.TypeVariable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
@ -694,7 +693,7 @@ public class MethodUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort methods by signature to force deterministic result
|
// Sort methods by signature to force deterministic result
|
||||||
Collections.sort(matchingMethods, METHOD_BY_SIGNATURE);
|
matchingMethods.sort(METHOD_BY_SIGNATURE);
|
||||||
|
|
||||||
Method bestMatch = null;
|
Method bestMatch = null;
|
||||||
for (final Method method : matchingMethods) {
|
for (final Method method : matchingMethods) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.apache.commons.lang3.compare;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
@ -47,7 +46,7 @@ public class ObjectToStringComparatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNull() {
|
public void testNull() {
|
||||||
final List<Thing> things = Arrays.asList(null, new Thing("y"), null);
|
final List<Thing> things = Arrays.asList(null, new Thing("y"), null);
|
||||||
Collections.sort(things, ObjectToStringComparator.INSTANCE);
|
things.sort(ObjectToStringComparator.INSTANCE);
|
||||||
assertEquals("y", things.get(0).string);
|
assertEquals("y", things.get(0).string);
|
||||||
assertEquals(null, things.get(1));
|
assertEquals(null, things.get(1));
|
||||||
assertEquals(null, things.get(2));
|
assertEquals(null, things.get(2));
|
||||||
|
@ -56,7 +55,7 @@ public class ObjectToStringComparatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNullToString() {
|
public void testNullToString() {
|
||||||
final List<Thing> things = Arrays.asList(new Thing(null), new Thing("y"), new Thing(null));
|
final List<Thing> things = Arrays.asList(new Thing(null), new Thing("y"), new Thing(null));
|
||||||
Collections.sort(things, ObjectToStringComparator.INSTANCE);
|
things.sort(ObjectToStringComparator.INSTANCE);
|
||||||
assertEquals("y", things.get(0).string);
|
assertEquals("y", things.get(0).string);
|
||||||
assertEquals(null, things.get(1).string);
|
assertEquals(null, things.get(1).string);
|
||||||
assertEquals(null, things.get(2).string);
|
assertEquals(null, things.get(2).string);
|
||||||
|
@ -65,7 +64,7 @@ public class ObjectToStringComparatorTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSortCollection() {
|
public void testSortCollection() {
|
||||||
final List<Thing> things = Arrays.asList(new Thing("z"), new Thing("y"), new Thing("x"));
|
final List<Thing> things = Arrays.asList(new Thing("z"), new Thing("y"), new Thing("x"));
|
||||||
Collections.sort(things, ObjectToStringComparator.INSTANCE);
|
things.sort(ObjectToStringComparator.INSTANCE);
|
||||||
assertEquals("x", things.get(0).string);
|
assertEquals("x", things.get(0).string);
|
||||||
assertEquals("y", things.get(1).string);
|
assertEquals("y", things.get(1).string);
|
||||||
assertEquals("z", things.get(2).string);
|
assertEquals("z", things.get(2).string);
|
||||||
|
|
Loading…
Reference in New Issue