private Comparator<Type> comparingTypes() { return comparing(type -> TypeInfo.typeInfo(type).getName()); }
private SelectionSet sortSelectionSet(SelectionSet selectionSet) { if (selectionSet == null) { return null; } List<Selection> selections = sort(selectionSet.getSelections(), comparingSelections()); return selectionSet.transform(builder -> builder.selections(selections)); }
private SelectionSet sortSelectionSet(SelectionSet selectionSet) { if (selectionSet == null) { return null; } List<Selection> selections = sort(selectionSet.getSelections(), comparingSelections()); return selectionSet.transform(builder -> builder.selections(selections)); }
private Comparator<Selection> comparingSelections() { Function<Selection, String> byName = s -> { if (s instanceof FragmentSpread) { return ((FragmentSpread) s).getName(); } if (s instanceof Field) { return ((Field) s).getName(); } if (s instanceof InlineFragment) { TypeName typeCondition = ((InlineFragment) s).getTypeCondition(); return typeCondition == null ? "" : typeCondition.getName(); } return ""; }; Function<Selection, Integer> byType = s -> { if (s instanceof Field) { return 1; } if (s instanceof FragmentSpread) { return 2; } if (s instanceof InlineFragment) { return 3; } return 4; }; return comparing(byType).thenComparing(comparing(byName)); }
return comparing(byType).thenComparing(byName);
private Comparator<Type> comparingTypes() { return comparing(type -> TypeInfo.typeInfo(type).getName()); }
private Comparator<Selection> comparingSelections() { Function<Selection, String> byName = s -> { if (s instanceof FragmentSpread) { return ((FragmentSpread) s).getName(); } if (s instanceof Field) { return ((Field) s).getName(); } if (s instanceof InlineFragment) { TypeName typeCondition = ((InlineFragment) s).getTypeCondition(); return typeCondition == null ? "" : typeCondition.getName(); } return ""; }; Function<Selection, Integer> byType = s -> { if (s instanceof Field) { return 1; } if (s instanceof FragmentSpread) { return 2; } if (s instanceof InlineFragment) { return 3; } return 4; }; return comparing(byType).thenComparing(comparing(byName)); }
return comparing(byType).thenComparing(byName);