Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/main/java/graphql/schema/GraphqlTypeComparators.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import com.google.common.collect.ImmutableList;
import graphql.Internal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.List;

@Internal
public class GraphqlTypeComparators {

private static final Comparator<? super GraphQLSchemaElement> BY_NAME_ASCENDING =
Comparator.comparing(graphQLSchemaElement ->
((GraphQLNamedSchemaElement) graphQLSchemaElement).getName());

/**
* This sorts the list of {@link graphql.schema.GraphQLType} objects (by name) and allocates a new sorted
* list back.
Expand All @@ -22,9 +25,7 @@ public class GraphqlTypeComparators {
* @return a new allocated list of sorted things
*/
public static <T extends GraphQLSchemaElement> List<T> sortTypes(Comparator<? super GraphQLSchemaElement> comparator, Collection<T> types) {
List<T> sorted = new ArrayList<>(types);
sorted.sort(comparator);
return ImmutableList.copyOf(sorted);
return ImmutableList.sortedCopyOf(comparator, types);
}

/**
Expand All @@ -42,7 +43,7 @@ public static Comparator<? super GraphQLSchemaElement> asIsOrder() {
* @return a comparator that compares {@link graphql.schema.GraphQLType} objects by ascending name
*/
public static Comparator<? super GraphQLSchemaElement> byNameAsc() {
return Comparator.comparing(graphQLSchemaElement -> ((GraphQLNamedSchemaElement) graphQLSchemaElement).getName());
return BY_NAME_ASCENDING;
}

}
Loading