Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Fix ComputedFieldAppender as it is used in public API. Add missing Nullable annotation.

Switch to switch expressions.

Original pull request #4751
See #4745
  • Loading branch information
mp911de committed Aug 29, 2024
1 parent f17c125 commit 56b55e3
Showing 1 changed file with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public ComputedFieldAppender within(Window window) {
/**
* Tiny little helper to allow fluent API usage for {@link #append(ComputedField)}.
*/
interface ComputedFieldAppender {
public interface ComputedFieldAppender {

/**
* Specify the target field name.
Expand Down Expand Up @@ -249,6 +249,7 @@ public AggregationExpression getWindowOperator() {
return windowOperator;
}

@Nullable
public Window getWindow() {
return window;
}
Expand Down Expand Up @@ -638,20 +639,15 @@ static WindowUnit from(TimeUnit timeUnit) {

Assert.notNull(timeUnit, "TimeUnit must not be null");

switch (timeUnit) {
case DAYS:
return WindowUnits.DAY;
case HOURS:
return WindowUnits.HOUR;
case MINUTES:
return WindowUnits.MINUTE;
case SECONDS:
return WindowUnits.SECOND;
case MILLISECONDS:
return WindowUnits.MILLISECOND;
}
return switch (timeUnit) {
case DAYS -> WindowUnits.DAY;
case HOURS -> WindowUnits.HOUR;
case MINUTES -> WindowUnits.MINUTE;
case SECONDS -> WindowUnits.SECOND;
case MILLISECONDS -> WindowUnits.MILLISECOND;
default -> throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", timeUnit));
};

throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", timeUnit));
}

/**
Expand All @@ -664,26 +660,18 @@ static WindowUnit from(TimeUnit timeUnit) {
*/
static WindowUnit from(ChronoUnit chronoUnit) {

switch (chronoUnit) {
case YEARS:
return WindowUnits.YEAR;
case WEEKS:
return WindowUnits.WEEK;
case MONTHS:
return WindowUnits.MONTH;
case DAYS:
return WindowUnits.DAY;
case HOURS:
return WindowUnits.HOUR;
case MINUTES:
return WindowUnits.MINUTE;
case SECONDS:
return WindowUnits.SECOND;
case MILLIS:
return WindowUnits.MILLISECOND;
}
return switch (chronoUnit) {
case YEARS -> WindowUnits.YEAR;
case WEEKS -> WindowUnits.WEEK;
case MONTHS -> WindowUnits.MONTH;
case DAYS -> WindowUnits.DAY;
case HOURS -> WindowUnits.HOUR;
case MINUTES -> WindowUnits.MINUTE;
case SECONDS -> WindowUnits.SECOND;
case MILLIS -> WindowUnits.MILLISECOND;
default -> throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", chronoUnit));
};

throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", chronoUnit));
}
}

Expand Down

0 comments on commit 56b55e3

Please sign in to comment.