Skip to content

Commit

Permalink
Use Comparators.lexicographical instead of Ordering.from in DeclaredM…
Browse files Browse the repository at this point in the history
…embers
  • Loading branch information
panic08 committed Oct 24, 2024
1 parent d83f677 commit f2a71af
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions core/src/com/google/inject/internal/DeclaredMembers.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.google.inject.internal;

import com.google.common.collect.Ordering;
import com.google.common.collect.Comparators;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
Expand All @@ -34,26 +34,26 @@
*/
public final class DeclaredMembers {

private DeclaredMembers() {}
private DeclaredMembers() {}

public static Field[] getDeclaredFields(Class<?> type) {
return Arrays.stream(type.getDeclaredFields())
.sorted(
Comparator.comparing(Field::getName)
.thenComparing(Field::getType, Comparator.comparing(Class::getName)))
.toArray(Field[]::new);
}
public static Field[] getDeclaredFields(Class<?> type) {
return Arrays.stream(type.getDeclaredFields())
.sorted(
Comparator.comparing(Field::getName)
.thenComparing(Field::getType, Comparator.comparing(Class::getName)))
.toArray(Field[]::new);
}

public static Method[] getDeclaredMethods(Class<?> type) {
return Arrays.stream(type.getDeclaredMethods())
.sorted(
Comparator.comparing(Method::getName)
.thenComparing(Method::getReturnType, Comparator.comparing(Class::getName))
.thenComparing(
method -> Arrays.asList(method.getParameterTypes()),
// TODO: use Comparators.lexicographical when it's not @Beta.
Ordering.<Class<?>>from(Comparator.comparing(Class::getName))
.lexicographical()))
.toArray(Method[]::new);
}
public static Method[] getDeclaredMethods(Class<?> type) {
return Arrays.stream(type.getDeclaredMethods())
.sorted(
Comparator.comparing(Method::getName)
.thenComparing(Method::getReturnType, Comparator.comparing(Class::getName))
.thenComparing(
method -> Arrays.asList(method.getParameterTypes()),
Comparators.lexicographical(Comparator.comparing(Class::getName))
)
)
.toArray(Method[]::new);
}
}

0 comments on commit f2a71af

Please sign in to comment.