@@ -52,7 +52,8 @@ public final class CelComprehensionsExtensions
5252 private static final TypeParamType TYPE_PARAM_V = TypeParamType .create ("V" );
5353 private static final MapType MAP_KV_TYPE = MapType .create (TYPE_PARAM_K , TYPE_PARAM_V );
5454
55- enum Function {
55+ /** Enumeration of functions for Comprehensions extension. */
56+ public enum Function {
5657 MAP_INSERT (
5758 CelFunctionDecl .newFunctionDeclaration (
5859 MAP_INSERT_FUNCTION ,
@@ -72,6 +73,10 @@ enum Function {
7273
7374 private final CelFunctionDecl functionDecl ;
7475
76+ public CelFunctionDecl functionDecl () {
77+ return functionDecl ;
78+ }
79+
7580 String getFunction () {
7681 return functionDecl .name ();
7782 }
@@ -81,20 +86,25 @@ String getFunction() {
8186 }
8287 }
8388
84- private static final CelExtensionLibrary <CelComprehensionsExtensions > LIBRARY =
85- new CelExtensionLibrary <CelComprehensionsExtensions >() {
86- private final CelComprehensionsExtensions version0 = new CelComprehensionsExtensions ();
89+ private static final class Library implements CelExtensionLibrary <CelComprehensionsExtensions > {
90+ private final CelComprehensionsExtensions version0 ;
8791
88- @ Override
89- public String name () {
90- return "comprehensions" ;
91- }
92+ Library () {
93+ version0 = new CelComprehensionsExtensions ();
94+ }
9295
93- @ Override
94- public ImmutableSet <CelComprehensionsExtensions > versions () {
95- return ImmutableSet .of (version0 );
96- }
97- };
96+ @ Override
97+ public String name () {
98+ return "comprehensions" ;
99+ }
100+
101+ @ Override
102+ public ImmutableSet <CelComprehensionsExtensions > versions () {
103+ return ImmutableSet .of (version0 );
104+ }
105+ }
106+
107+ private static final Library LIBRARY = new Library ();
98108
99109 static CelExtensionLibrary <CelComprehensionsExtensions > library () {
100110 return LIBRARY ;
@@ -103,7 +113,7 @@ static CelExtensionLibrary<CelComprehensionsExtensions> library() {
103113 private final ImmutableSet <Function > functions ;
104114
105115 CelComprehensionsExtensions () {
106- this .functions = ImmutableSet .copyOf (Function .values () );
116+ this .functions = ImmutableSet .of (Function .MAP_INSERT );
107117 }
108118
109119 @ Override
@@ -175,10 +185,10 @@ public void setParserOptions(CelParserBuilder parserBuilder) {
175185 private static Map <Object , Object > mapInsertMap (
176186 Map <?, ?> targetMap , Map <?, ?> mapToMerge , RuntimeEquality equality ) {
177187 for (Object key : mapToMerge .keySet ()) {
178- if ( equality . findInMap ( targetMap , key ). isPresent ()) {
179- throw new IllegalArgumentException (
180- String . format ( "insert failed: key '%s' already exists" , key ));
181- }
188+ checkArgument (
189+ ! equality . findInMap ( targetMap , key ). isPresent (),
190+ "insert failed: key '%s' already exists" ,
191+ key );
182192 }
183193
184194 if (targetMap instanceof MutableMapValue ) {
@@ -198,10 +208,10 @@ private static Map<Object, Object> mapInsertKeyValue(Object[] args, RuntimeEqual
198208 Object key = args [1 ];
199209 Object value = args [2 ];
200210
201- if ( equality . findInMap ( mapArg , key ). isPresent ()) {
202- throw new IllegalArgumentException (
203- String . format ( "insert failed: key '%s' already exists" , key ));
204- }
211+ checkArgument (
212+ ! equality . findInMap ( mapArg , key ). isPresent (),
213+ "insert failed: key '%s' already exists" ,
214+ key );
205215
206216 if (mapArg instanceof MutableMapValue ) {
207217 MutableMapValue mutableMap = (MutableMapValue ) mapArg ;
0 commit comments