Skip to content

Commit

Permalink
[LANG-1561] use List.sort instead of Collection.sort (#546)
Browse files Browse the repository at this point in the history
* use_List_sort

* Update MethodUtils.java

* Update ObjectToStringComparatorTest.java
  • Loading branch information
XenoAmess committed Jun 13, 2020
1 parent 2d21e19 commit 7651124
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -694,7 +693,7 @@ public static Method getMatchingAccessibleMethod(final Class<?> cls,
}

// Sort methods by signature to force deterministic result
Collections.sort(matchingMethods, METHOD_BY_SIGNATURE);
matchingMethods.sort(METHOD_BY_SIGNATURE);

Method bestMatch = null;
for (final Method method : matchingMethods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;
Expand All @@ -47,7 +46,7 @@ public String toString() {
@Test
public void testNull() {
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(null, things.get(1));
assertEquals(null, things.get(2));
Expand All @@ -56,7 +55,7 @@ public void testNull() {
@Test
public void testNullToString() {
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(null, things.get(1).string);
assertEquals(null, things.get(2).string);
Expand All @@ -65,7 +64,7 @@ public void testNullToString() {
@Test
public void testSortCollection() {
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("y", things.get(1).string);
assertEquals("z", things.get(2).string);
Expand Down

0 comments on commit 7651124

Please sign in to comment.