Skip to content

Commit ffca3db

Browse files
committed
Polishing.
Fix ComputedFieldAppender as it is used in public API. Add missing Nullable annotation. Switch to switch expressions. Original pull request spring-projects#4751 See spring-projects#4745
1 parent f392984 commit ffca3db

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/aggregation/SetWindowFieldsOperation.java

+21-33
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public ComputedFieldAppender within(Window window) {
175175
/**
176176
* Tiny little helper to allow fluent API usage for {@link #append(ComputedField)}.
177177
*/
178-
interface ComputedFieldAppender {
178+
public interface ComputedFieldAppender {
179179

180180
/**
181181
* Specify the target field name.
@@ -249,6 +249,7 @@ public AggregationExpression getWindowOperator() {
249249
return windowOperator;
250250
}
251251

252+
@Nullable
252253
public Window getWindow() {
253254
return window;
254255
}
@@ -638,20 +639,15 @@ static WindowUnit from(TimeUnit timeUnit) {
638639

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

641-
switch (timeUnit) {
642-
case DAYS:
643-
return WindowUnits.DAY;
644-
case HOURS:
645-
return WindowUnits.HOUR;
646-
case MINUTES:
647-
return WindowUnits.MINUTE;
648-
case SECONDS:
649-
return WindowUnits.SECOND;
650-
case MILLISECONDS:
651-
return WindowUnits.MILLISECOND;
652-
}
642+
return switch (timeUnit) {
643+
case DAYS -> WindowUnits.DAY;
644+
case HOURS -> WindowUnits.HOUR;
645+
case MINUTES -> WindowUnits.MINUTE;
646+
case SECONDS -> WindowUnits.SECOND;
647+
case MILLISECONDS -> WindowUnits.MILLISECOND;
648+
default -> throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", timeUnit));
649+
};
653650

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

657653
/**
@@ -664,26 +660,18 @@ static WindowUnit from(TimeUnit timeUnit) {
664660
*/
665661
static WindowUnit from(ChronoUnit chronoUnit) {
666662

667-
switch (chronoUnit) {
668-
case YEARS:
669-
return WindowUnits.YEAR;
670-
case WEEKS:
671-
return WindowUnits.WEEK;
672-
case MONTHS:
673-
return WindowUnits.MONTH;
674-
case DAYS:
675-
return WindowUnits.DAY;
676-
case HOURS:
677-
return WindowUnits.HOUR;
678-
case MINUTES:
679-
return WindowUnits.MINUTE;
680-
case SECONDS:
681-
return WindowUnits.SECOND;
682-
case MILLIS:
683-
return WindowUnits.MILLISECOND;
684-
}
663+
return switch (chronoUnit) {
664+
case YEARS -> WindowUnits.YEAR;
665+
case WEEKS -> WindowUnits.WEEK;
666+
case MONTHS -> WindowUnits.MONTH;
667+
case DAYS -> WindowUnits.DAY;
668+
case HOURS -> WindowUnits.HOUR;
669+
case MINUTES -> WindowUnits.MINUTE;
670+
case SECONDS -> WindowUnits.SECOND;
671+
case MILLIS -> WindowUnits.MILLISECOND;
672+
default -> throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", chronoUnit));
673+
};
685674

686-
throw new IllegalArgumentException(String.format("Cannot create WindowUnit from %s", chronoUnit));
687675
}
688676
}
689677

0 commit comments

Comments
 (0)