@@ -128,15 +128,21 @@ 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 (
133+ "list_sort" , Collection .class , (list ) -> sort ((Collection <Object >) list ))),
132134 SORT_BY (
133135 CelFunctionDecl .newFunctionDeclaration (
134136 "lists.@sortByAssociatedKeys" ,
135137 CelOverloadDecl .newGlobalOverload (
136138 "list_sortByAssociatedKeys" ,
137139 "Sorts a list by a key value. Used by the 'sortBy' macro" ,
138140 ListType .create (TypeParamType .create ("T" )),
139- ListType .create (TypeParamType .create ("T" )))));
141+ ListType .create (TypeParamType .create ("T" )))),
142+ CelFunctionBinding .from (
143+ "list_sortByAssociatedKeys" ,
144+ Collection .class ,
145+ (list ) -> sortByAssociatedKeys ((Collection <List <Object >>) list )));
140146
141147 private final CelFunctionDecl functionDecl ;
142148 private final ImmutableSet <CelFunctionBinding > functionBindings ;
@@ -147,7 +153,8 @@ String getFunction() {
147153
148154 Function (CelFunctionDecl functionDecl , CelFunctionBinding ... functionBindings ) {
149155 this .functionDecl = functionDecl ;
150- this .functionBindings = ImmutableSet .copyOf (functionBindings );
156+ this .functionBindings =
157+ CelFunctionBinding .fromOverloads (functionDecl .name (), functionBindings );
151158 }
152159 }
153160
@@ -240,32 +247,13 @@ public void setRuntimeOptions(CelRuntimeBuilder runtimeBuilder) {
240247 @ Override
241248 public void setRuntimeOptions (
242249 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- }
250+ functions .forEach (function -> runtimeBuilder .addFunctionBindings (function .functionBindings ));
251+
252+ runtimeBuilder .addFunctionBindings (
253+ CelFunctionBinding .fromOverloads (
254+ "distinct" ,
255+ CelFunctionBinding .from (
256+ "list_distinct" , Collection .class , (list ) -> distinct (list , runtimeEquality ))));
269257 }
270258
271259 private static ImmutableList <Object > slice (Collection <Object > list , long from , long to ) {
@@ -369,22 +357,19 @@ private static List<Object> reverse(Collection<Object> list) {
369357 }
370358 }
371359
372- private static ImmutableList <Object > sort (Collection <Object > objects , CelOptions options ) {
360+ private static ImmutableList <Object > sort (Collection <Object > objects ) {
373361 return ImmutableList .sortedCopyOf (
374- new CelObjectComparator (options . enableHeterogeneousNumericComparisons () ), objects );
362+ new CelObjectComparator (), objects );
375363 }
376364
377365 private static class CelObjectComparator implements Comparator <Object > {
378- private final boolean enableHeterogeneousNumericComparisons ;
379366
380- CelObjectComparator (boolean enableHeterogeneousNumericComparisons ) {
381- this .enableHeterogeneousNumericComparisons = enableHeterogeneousNumericComparisons ;
382- }
367+ CelObjectComparator () {}
383368
384369 @ SuppressWarnings ({"unchecked" })
385370 @ Override
386371 public int compare (Object o1 , Object o2 ) {
387- if (o1 instanceof Number && o2 instanceof Number && enableHeterogeneousNumericComparisons ) {
372+ if (o1 instanceof Number && o2 instanceof Number ) {
388373 return ComparisonFunctions .numericCompare ((Number ) o1 , (Number ) o2 );
389374 }
390375
@@ -444,12 +429,12 @@ private static Optional<CelExpr> sortByMacro(
444429
445430 @ SuppressWarnings ({"unchecked" , "rawtypes" })
446431 private static ImmutableList <Object > sortByAssociatedKeys (
447- Collection <List <Object >> keyValuePairs , CelOptions options ) {
432+ Collection <List <Object >> keyValuePairs ) {
448433 List <Object >[] array = keyValuePairs .toArray (new List [0 ]);
449434 Arrays .sort (
450435 array ,
451436 new CelObjectByKeyComparator (
452- new CelObjectComparator (options . enableHeterogeneousNumericComparisons () )));
437+ new CelObjectComparator ()));
453438 ImmutableList .Builder <Object > builder = ImmutableList .builderWithExpectedSize (array .length );
454439 for (List <Object > pair : array ) {
455440 builder .add (pair .get (1 ));
0 commit comments