2323import com .google .common .base .Splitter ;
2424import com .google .common .collect .ImmutableList ;
2525import com .google .common .collect .ImmutableSet ;
26- import com .google .common .collect .Lists ;
2726import com .google .errorprone .annotations .Immutable ;
2827import dev .cel .checker .CelCheckerBuilder ;
2928import dev .cel .common .CelFunctionDecl ;
3736import dev .cel .runtime .CelFunctionBinding ;
3837import dev .cel .runtime .CelRuntimeBuilder ;
3938import dev .cel .runtime .CelRuntimeLibrary ;
40- import java .util .ArrayList ;
4139import java .util .List ;
4240import java .util .Set ;
4341
@@ -475,7 +473,7 @@ private static String quote(String s) {
475473 sb .append ('"' );
476474 for (int i = 0 ; i < s .length (); ) {
477475 int codePoint = s .codePointAt (i );
478- if (isMalformedUtf16 (s , i , codePoint )) {
476+ if (isMalformedUtf16 (s , i )) {
479477 sb .append ('\uFFFD' );
480478 i ++;
481479 continue ;
@@ -518,7 +516,7 @@ private static String quote(String s) {
518516 return sb .toString ();
519517 }
520518
521- private static boolean isMalformedUtf16 (String s , int index , int codePoint ) {
519+ private static boolean isMalformedUtf16 (String s , int index ) {
522520 char currentChar = s .charAt (index );
523521 if (Character .isLowSurrogate (currentChar )) {
524522 return true ;
@@ -587,14 +585,14 @@ private static String reverse(String s) {
587585 return new StringBuilder (s ).reverse ().toString ();
588586 }
589587
590- private static List <String > split (String str , String separator ) {
588+ private static ImmutableList <String > split (String str , String separator ) {
591589 return split (str , separator , Integer .MAX_VALUE );
592590 }
593591
594592 /**
595593 * @param args Object array with indices of: [0: string], [1: separator], [2: limit]
596594 */
597- private static List <String > split (Object [] args ) throws CelEvaluationException {
595+ private static ImmutableList <String > split (Object [] args ) throws CelEvaluationException {
598596 long limitInLong = (Long ) args [2 ];
599597 int limit ;
600598 try {
@@ -609,16 +607,14 @@ private static List<String> split(Object[] args) throws CelEvaluationException {
609607 return split ((String ) args [0 ], (String ) args [1 ], limit );
610608 }
611609
612- /** Returns a **mutable** list of strings split on the separator */
613- private static List <String > split (String str , String separator , int limit ) {
610+ /** Returns an immutable list of strings split on the separator */
611+ private static ImmutableList <String > split (String str , String separator , int limit ) {
614612 if (limit == 0 ) {
615- return new ArrayList <> ();
613+ return ImmutableList . of ();
616614 }
617615
618616 if (limit == 1 ) {
619- List <String > singleElementList = new ArrayList <>();
620- singleElementList .add (str );
621- return singleElementList ;
617+ return ImmutableList .of (str );
622618 }
623619
624620 if (limit < 0 ) {
@@ -630,7 +626,7 @@ private static List<String> split(String str, String separator, int limit) {
630626 }
631627
632628 Iterable <String > splitString = Splitter .on (separator ).limit (limit ).split (str );
633- return Lists . newArrayList (splitString );
629+ return ImmutableList . copyOf (splitString );
634630 }
635631
636632 /**
@@ -643,8 +639,8 @@ private static List<String> split(String str, String separator, int limit) {
643639 * <p>This exists because neither the built-in String.split nor Guava's splitter is able to deal
644640 * with separating single printable characters.
645641 */
646- private static List <String > explode (String str , int limit ) {
647- List <String > exploded = new ArrayList <> ();
642+ private static ImmutableList <String > explode (String str , int limit ) {
643+ ImmutableList . Builder <String > exploded = ImmutableList . builder ();
648644 CelCodePointArray codePointArray = CelCodePointArray .fromString (str );
649645 if (limit > 0 ) {
650646 limit -= 1 ;
@@ -656,7 +652,7 @@ private static List<String> explode(String str, int limit) {
656652 if (codePointArray .length () > limit ) {
657653 exploded .add (codePointArray .slice (limit , codePointArray .length ()).toString ());
658654 }
659- return exploded ;
655+ return exploded . build () ;
660656 }
661657
662658 private static Object substring (String s , long i ) throws CelEvaluationException {
0 commit comments