@@ -128,15 +128,20 @@ public enum Function {
128128 "list_sort" ,
129129 "Sorts a list with comparable elements." ,
130130 ListType .create (TypeParamType .create ("T" )),
131- ListType .create (TypeParamType .create ("T" ))))),
131+ ListType .create (TypeParamType .create ("T" )))),
132+ CelFunctionBinding .from ("list_sort" , Collection .class , CelListsExtensions ::sort )),
132133 SORT_BY (
133134 CelFunctionDecl .newFunctionDeclaration (
134135 "lists.@sortByAssociatedKeys" ,
135136 CelOverloadDecl .newGlobalOverload (
136137 "list_sortByAssociatedKeys" ,
137138 "Sorts a list by a key value. Used by the 'sortBy' macro" ,
138139 ListType .create (TypeParamType .create ("T" )),
139- ListType .create (TypeParamType .create ("T" )))));
140+ ListType .create (TypeParamType .create ("T" )))),
141+ CelFunctionBinding .from (
142+ "list_sortByAssociatedKeys" ,
143+ Collection .class ,
144+ CelListsExtensions ::sortByAssociatedKeys ));
140145
141146 private final CelFunctionDecl functionDecl ;
142147 private final ImmutableSet <CelFunctionBinding > functionBindings ;
@@ -147,12 +152,13 @@ String getFunction() {
147152
148153 Function (CelFunctionDecl functionDecl , CelFunctionBinding ... functionBindings ) {
149154 this .functionDecl = functionDecl ;
150- this .functionBindings = ImmutableSet .copyOf (functionBindings );
155+ this .functionBindings =
156+ CelFunctionBinding .fromOverloads (functionDecl .name (), functionBindings );
151157 }
152158 }
153159
154160 private static final CelExtensionLibrary <CelListsExtensions > LIBRARY =
155- new CelExtensionLibrary <CelListsExtensions >() {
161+ new CelExtensionLibrary <>() {
156162 private final CelListsExtensions version0 =
157163 new CelListsExtensions (0 , ImmutableSet .of (Function .SLICE ));
158164 private final CelListsExtensions version1 =
@@ -240,32 +246,13 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
240246 @ Override
241247 public void setRuntimeOptions (
242248 CelRuntimeBuilder runtimeBuilder , RuntimeEquality runtimeEquality , CelOptions celOptions ) {
243- for (Function function : functions ) {
244- runtimeBuilder .addFunctionBindings (function .functionBindings );
245- for (CelOverloadDecl overload : function .functionDecl .overloads ()) {
246- switch (overload .overloadId ()) {
247- case "list_distinct" :
248- runtimeBuilder .addFunctionBindings (
249- CelFunctionBinding .from (
250- "list_distinct" , Collection .class , (list ) -> distinct (list , runtimeEquality )));
251- break ;
252- case "list_sort" :
253- runtimeBuilder .addFunctionBindings (
254- CelFunctionBinding .from (
255- "list_sort" , Collection .class , (list ) -> sort (list , celOptions )));
256- break ;
257- case "list_sortByAssociatedKeys" :
258- runtimeBuilder .addFunctionBindings (
259- CelFunctionBinding .from (
260- "list_sortByAssociatedKeys" ,
261- Collection .class ,
262- (list ) -> sortByAssociatedKeys (list , celOptions )));
263- break ;
264- default :
265- // Nothing to add
266- }
267- }
268- }
249+ functions .forEach (function -> runtimeBuilder .addFunctionBindings (function .functionBindings ));
250+
251+ runtimeBuilder .addFunctionBindings (
252+ CelFunctionBinding .fromOverloads (
253+ "distinct" ,
254+ CelFunctionBinding .from (
255+ "list_distinct" , Collection .class , (list ) -> distinct (list , runtimeEquality ))));
269256 }
270257
271258 private static ImmutableList <Object > slice (Collection <Object > list , long from , long to ) {
@@ -369,22 +356,18 @@ private static List<Object> reverse(Collection<Object> list) {
369356 }
370357 }
371358
372- private static ImmutableList <Object > sort (Collection <Object > objects , CelOptions options ) {
373- return ImmutableList .sortedCopyOf (
374- new CelObjectComparator (options .enableHeterogeneousNumericComparisons ()), objects );
359+ private static ImmutableList <Object > sort (Collection <Object > objects ) {
360+ return ImmutableList .sortedCopyOf (new CelObjectComparator (), objects );
375361 }
376362
377363 private static class CelObjectComparator implements Comparator <Object > {
378- private final boolean enableHeterogeneousNumericComparisons ;
379364
380- CelObjectComparator (boolean enableHeterogeneousNumericComparisons ) {
381- this .enableHeterogeneousNumericComparisons = enableHeterogeneousNumericComparisons ;
382- }
365+ CelObjectComparator () {}
383366
384367 @ SuppressWarnings ({"unchecked" })
385368 @ Override
386369 public int compare (Object o1 , Object o2 ) {
387- if (o1 instanceof Number && o2 instanceof Number && enableHeterogeneousNumericComparisons ) {
370+ if (o1 instanceof Number && o2 instanceof Number ) {
388371 return ComparisonFunctions .numericCompare ((Number ) o1 , (Number ) o2 );
389372 }
390373
@@ -444,12 +427,9 @@ private static Optional<CelExpr> sortByMacro(
444427
445428 @ SuppressWarnings ({"unchecked" , "rawtypes" })
446429 private static ImmutableList <Object > sortByAssociatedKeys (
447- Collection <List <Object >> keyValuePairs , CelOptions options ) {
430+ Collection <List <Object >> keyValuePairs ) {
448431 List <Object >[] array = keyValuePairs .toArray (new List [0 ]);
449- Arrays .sort (
450- array ,
451- new CelObjectByKeyComparator (
452- new CelObjectComparator (options .enableHeterogeneousNumericComparisons ())));
432+ Arrays .sort (array , new CelObjectByKeyComparator (new CelObjectComparator ()));
453433 ImmutableList .Builder <Object > builder = ImmutableList .builderWithExpectedSize (array .length );
454434 for (List <Object > pair : array ) {
455435 builder .add (pair .get (1 ));
0 commit comments