Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
strategy:
max-parallel: 4
matrix:
java-version: [21, 24]
java-version: [21, 25]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ Build requirements:

Runtime requirements:

- Java 8 or newer
- Java 17 or newer

`./gradlew publishToMavenLocal` deploys the current development version to the local Maven
repository, in case you want to use CEL-Java snapshot artifacts from another project.
Expand Down
6 changes: 3 additions & 3 deletions build-logic/src/main/kotlin/Java.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun Project.nessieConfigureJava() {

tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
options.release.set(8)
options.release.set(17)
}

tasks.withType<Javadoc>().configureEach {
Expand All @@ -59,8 +59,8 @@ fun Project.nessieConfigureJava() {
configure<JavaPluginExtension> {
withJavadocJar()
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
modularity.inferModulePath.set(true)
}
}
Expand Down
6 changes: 2 additions & 4 deletions core/src/main/java/org/projectnessie/cel/Library.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.projectnessie.cel;

import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.projectnessie.cel.EnvOption.declarations;
import static org.projectnessie.cel.EnvOption.macros;
import static org.projectnessie.cel.ProgramOption.functions;
Expand Down Expand Up @@ -79,13 +77,13 @@ final class StdLibrary implements Library {
/** EnvOptions returns options for the standard CEL function declarations and macros. */
@Override
public List<EnvOption> getCompileOptions() {
return asList(declarations(StandardDeclarations), macros(AllMacros));
return List.of(declarations(StandardDeclarations), macros(AllMacros));
}

/** ProgramOptions returns function implementations for the standard CEL functions. */
@Override
public List<ProgramOption> getProgramOptions() {
return singletonList(functions(standardOverloads()));
return List.of(functions(standardOverloads()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
*/
package org.projectnessie.cel.common.operators;

import static java.util.Map.copyOf;
import static java.util.Map.entry;
import static java.util.Map.ofEntries;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -71,30 +75,26 @@ public enum Operator {
}

static {
{
Map<String, Operator> m = new HashMap<>();
m.put("+", Add);
m.put("/", Divide);
m.put("==", Equals);
m.put(">", Greater);
m.put(">=", GreaterEquals);
m.put("in", In);
m.put("<", Less);
m.put("<=", LessEquals);
m.put("%", Modulo);
m.put("*", Multiply);
m.put("!=", NotEquals);
m.put("-", Subtract);
operators = m;
}
operators =
ofEntries(
entry("+", Add),
entry("/", Divide),
entry("==", Equals),
entry(">", Greater),
entry(">=", GreaterEquals),
entry("in", In),
entry("<", Less),
entry("<=", LessEquals),
entry("%", Modulo),
entry("*", Multiply),
entry("!=", NotEquals),
entry("-", Subtract));

{
Map<String, Operator> m = new HashMap<>();
for (Operator op : Operator.values()) {
m.put(op.id, op);
}
operatorsById = m;
Map<String, Operator> byId = new HashMap<>();
for (Operator op : Operator.values()) {
byId.put(op.id, op);
}
operatorsById = copyOf(byId);
}

public static Operator byId(String id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -101,15 +100,16 @@ public static DurationT durationOf(Duration d) {
return new DurationT(d);
}

private static final Map<String, Function<Duration, Val>> durationZeroArgOverloads;

static {
durationZeroArgOverloads = new HashMap<>();
durationZeroArgOverloads.put(Overloads.TimeGetHours, DurationT::timeGetHours);
durationZeroArgOverloads.put(Overloads.TimeGetMinutes, DurationT::timeGetMinutes);
durationZeroArgOverloads.put(Overloads.TimeGetSeconds, DurationT::timeGetSeconds);
durationZeroArgOverloads.put(Overloads.TimeGetMilliseconds, DurationT::timeGetMilliseconds);
}
private static final Map<String, Function<Duration, Val>> durationZeroArgOverloads =
Map.of(
Overloads.TimeGetHours,
DurationT::timeGetHours,
Overloads.TimeGetMinutes,
DurationT::timeGetMinutes,
Overloads.TimeGetSeconds,
DurationT::timeGetSeconds,
Overloads.TimeGetMilliseconds,
DurationT::timeGetMilliseconds);

private final Duration d;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.google.protobuf.StringValue;
import com.google.protobuf.Value;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.BiFunction;
Expand Down Expand Up @@ -62,14 +61,14 @@ public final class StringT extends BaseVal implements Adder, Comparer, Matcher,
Trait.ReceiverType,
Trait.SizerType);

private static final Map<String, BiFunction<String, Val, Val>> stringOneArgOverloads;

static {
stringOneArgOverloads = new HashMap<>();
stringOneArgOverloads.put(Overloads.Contains, StringT::stringContains);
stringOneArgOverloads.put(Overloads.EndsWith, StringT::stringEndsWith);
stringOneArgOverloads.put(Overloads.StartsWith, StringT::stringStartsWith);
}
private static final Map<String, BiFunction<String, Val, Val>> stringOneArgOverloads =
Map.of(
Overloads.Contains,
StringT::stringContains,
Overloads.EndsWith,
StringT::stringEndsWith,
Overloads.StartsWith,
StringT::stringStartsWith);

public static StringT stringOf(String s) {
return new StringT(s);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import java.time.zone.ZoneRulesException;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
Expand Down Expand Up @@ -122,42 +121,51 @@ public static TimestampT timestampOf(ZonedDateTime t) {
return new TimestampT(t);
}

private static final Map<String, Function<ZonedDateTime, Val>> timestampZeroArgOverloads;
private static final Map<String, BiFunction<ZonedDateTime, Val, Val>> timestampOneArgOverloads;

static {
timestampZeroArgOverloads = new HashMap<>();
timestampZeroArgOverloads.put(Overloads.TimeGetFullYear, TimestampT::timestampGetFullYear);
timestampZeroArgOverloads.put(Overloads.TimeGetMonth, TimestampT::timestampGetMonth);
timestampZeroArgOverloads.put(Overloads.TimeGetDayOfYear, TimestampT::timestampGetDayOfYear);
timestampZeroArgOverloads.put(
Overloads.TimeGetDate, TimestampT::timestampGetDayOfMonthOneBased);
timestampZeroArgOverloads.put(
Overloads.TimeGetDayOfMonth, TimestampT::timestampGetDayOfMonthZeroBased);
timestampZeroArgOverloads.put(Overloads.TimeGetDayOfWeek, TimestampT::timestampGetDayOfWeek);
timestampZeroArgOverloads.put(Overloads.TimeGetHours, TimestampT::timestampGetHours);
timestampZeroArgOverloads.put(Overloads.TimeGetMinutes, TimestampT::timestampGetMinutes);
timestampZeroArgOverloads.put(Overloads.TimeGetSeconds, TimestampT::timestampGetSeconds);
timestampZeroArgOverloads.put(
Overloads.TimeGetMilliseconds, TimestampT::timestampGetMilliseconds);

timestampOneArgOverloads = new HashMap<>();
timestampOneArgOverloads.put(Overloads.TimeGetFullYear, TimestampT::timestampGetFullYearWithTz);
timestampOneArgOverloads.put(Overloads.TimeGetMonth, TimestampT::timestampGetMonthWithTz);
timestampOneArgOverloads.put(
Overloads.TimeGetDayOfYear, TimestampT::timestampGetDayOfYearWithTz);
timestampOneArgOverloads.put(
Overloads.TimeGetDate, TimestampT::timestampGetDayOfMonthOneBasedWithTz);
timestampOneArgOverloads.put(
Overloads.TimeGetDayOfMonth, TimestampT::timestampGetDayOfMonthZeroBasedWithTz);
timestampOneArgOverloads.put(
Overloads.TimeGetDayOfWeek, TimestampT::timestampGetDayOfWeekWithTz);
timestampOneArgOverloads.put(Overloads.TimeGetHours, TimestampT::timestampGetHoursWithTz);
timestampOneArgOverloads.put(Overloads.TimeGetMinutes, TimestampT::timestampGetMinutesWithTz);
timestampOneArgOverloads.put(Overloads.TimeGetSeconds, TimestampT::timestampGetSecondsWithTz);
timestampOneArgOverloads.put(
Overloads.TimeGetMilliseconds, TimestampT::timestampGetMillisecondsWithTz);
}
private static final Map<String, Function<ZonedDateTime, Val>> timestampZeroArgOverloads =
Map.of(
Overloads.TimeGetFullYear,
TimestampT::timestampGetFullYear,
Overloads.TimeGetMonth,
TimestampT::timestampGetMonth,
Overloads.TimeGetDayOfYear,
TimestampT::timestampGetDayOfYear,
Overloads.TimeGetDate,
TimestampT::timestampGetDayOfMonthOneBased,
Overloads.TimeGetDayOfMonth,
TimestampT::timestampGetDayOfMonthZeroBased,
Overloads.TimeGetDayOfWeek,
TimestampT::timestampGetDayOfWeek,
Overloads.TimeGetHours,
TimestampT::timestampGetHours,
Overloads.TimeGetMinutes,
TimestampT::timestampGetMinutes,
Overloads.TimeGetSeconds,
TimestampT::timestampGetSeconds,
Overloads.TimeGetMilliseconds,
TimestampT::timestampGetMilliseconds);

private static final Map<String, BiFunction<ZonedDateTime, Val, Val>> timestampOneArgOverloads =
Map.of(
Overloads.TimeGetFullYear,
TimestampT::timestampGetFullYearWithTz,
Overloads.TimeGetMonth,
TimestampT::timestampGetMonthWithTz,
Overloads.TimeGetDayOfYear,
TimestampT::timestampGetDayOfYearWithTz,
Overloads.TimeGetDate,
TimestampT::timestampGetDayOfMonthOneBasedWithTz,
Overloads.TimeGetDayOfMonth,
TimestampT::timestampGetDayOfMonthZeroBasedWithTz,
Overloads.TimeGetDayOfWeek,
TimestampT::timestampGetDayOfWeekWithTz,
Overloads.TimeGetHours,
TimestampT::timestampGetHoursWithTz,
Overloads.TimeGetMinutes,
TimestampT::timestampGetMinutesWithTz,
Overloads.TimeGetSeconds,
TimestampT::timestampGetSecondsWithTz,
Overloads.TimeGetMilliseconds,
TimestampT::timestampGetMillisecondsWithTz);

private final ZonedDateTime t;

Expand Down
61 changes: 28 additions & 33 deletions core/src/main/java/org/projectnessie/cel/extension/StringsLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,41 +247,39 @@ public class StringsLib implements Library {
// whitespace characters definition from
// https://en.wikipedia.org/wiki/Whitespace_character#Unicode
private static final Set<Character> UNICODE_WHITE_SPACES =
new HashSet<>(
Arrays.asList(
(char) 0x0009,
(char) 0x000A,
(char) 0x000B,
(char) 0x000C,
(char) 0x000D,
(char) 0x0020,
(char) 0x0085,
(char) 0x00A0,
(char) 0x1680,
(char) 0x2000,
(char) 0x2001,
(char) 0x2002,
(char) 0x2003,
(char) 0x2004,
(char) 0x2005,
(char) 0x2006,
(char) 0x2007,
(char) 0x2008,
(char) 0x2009,
(char) 0x200A,
(char) 0x2028,
(char) 0x2029,
(char) 0x202F,
(char) 0x205F,
(char) 0x3000));
Set.of(
(char) 0x0009,
(char) 0x000A,
(char) 0x000B,
(char) 0x000C,
(char) 0x000D,
(char) 0x0020,
(char) 0x0085,
(char) 0x00A0,
(char) 0x1680,
(char) 0x2000,
(char) 0x2001,
(char) 0x2002,
(char) 0x2003,
(char) 0x2004,
(char) 0x2005,
(char) 0x2006,
(char) 0x2007,
(char) 0x2008,
(char) 0x2009,
(char) 0x200A,
(char) 0x2028,
(char) 0x2029,
(char) 0x202F,
(char) 0x205F,
(char) 0x3000);

public static EnvOption strings() {
return Library.Lib(new StringsLib());
}

@Override
public List<EnvOption> getCompileOptions() {
List<EnvOption> list = new ArrayList<>();
EnvOption option =
EnvOption.declarations(
Decls.newFunction(
Expand Down Expand Up @@ -352,13 +350,11 @@ public List<EnvOption> getCompileOptions() {
UPPER_ASCII,
Decls.newInstanceOverload(
"string_upper_ascii", Arrays.asList(Decls.String), Decls.String)));
list.add(option);
return list;
return List.of(option);
}

@Override
public List<ProgramOption> getProgramOptions() {
List<ProgramOption> list = new ArrayList<>();
ProgramOption functions =
ProgramOption.functions(
Overload.binary(CHAR_AT, Guards.callInStrIntOutStr(StringsLib::charAt)),
Expand Down Expand Up @@ -409,8 +405,7 @@ public List<ProgramOption> getProgramOptions() {
Guards.callInStrIntIntOutStr(StringsLib::substrRange)),
Overload.unary(TRIM_SPACE, Guards.callInStrOutStr(StringsLib::trimSpace)),
Overload.unary(UPPER_ASCII, Guards.callInStrOutStr(StringsLib::upperASCII)));
list.add(functions);
return list;
return List.of(functions);
}

static String charAt(String str, int index) {
Expand Down
5 changes: 1 addition & 4 deletions core/src/main/java/org/projectnessie/cel/parser/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ public Builder macros(List<Macro> macros) {

public Options build() {
return new Options(
maxRecursionDepth,
errorRecoveryLimit,
expressionSizeCodePointLimit,
new HashMap<>(macros));
maxRecursionDepth, errorRecoveryLimit, expressionSizeCodePointLimit, Map.copyOf(macros));
}
}
}
Loading
Loading