|
16 | 16 | */ |
17 | 17 | package com.google.edwmigration.dumper.application.dumper.connector; |
18 | 18 |
|
19 | | -import com.google.common.base.Preconditions; |
| 19 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | +import static com.google.common.base.Preconditions.checkState; |
| 21 | + |
20 | 22 | import com.google.edwmigration.dumper.application.dumper.ConnectorArguments; |
21 | 23 | import com.google.edwmigration.dumper.application.dumper.handle.Handle; |
22 | 24 | import com.google.edwmigration.dumper.application.dumper.task.Task; |
@@ -55,22 +57,19 @@ default String getDescription() { |
55 | 57 | default void validate(@Nonnull ConnectorArguments arguments) {} |
56 | 58 |
|
57 | 59 | static void validateDateRange(@Nonnull ConnectorArguments arguments) { |
58 | | - ZonedDateTime startDate = arguments.getStartDate(); |
59 | | - ZonedDateTime endDate = arguments.getEndDate(); |
| 60 | + ZonedDateTime start = arguments.getStartDate(); |
| 61 | + ZonedDateTime end = arguments.getEndDate(); |
60 | 62 |
|
61 | | - if (startDate != null) { |
62 | | - Preconditions.checkNotNull( |
63 | | - endDate, "End date must be specified with start date, but was null."); |
64 | | - Preconditions.checkState( |
65 | | - startDate.isBefore(endDate), |
66 | | - "Start date [%s] must be before end date [%s].", |
67 | | - startDate, |
68 | | - endDate); |
69 | | - } else { |
70 | | - Preconditions.checkState( |
71 | | - endDate == null, |
72 | | - "End date can be specified only with start date, but start date was null."); |
| 63 | + if (start == null && end == null) { |
| 64 | + return; |
73 | 65 | } |
| 66 | + checkState( |
| 67 | + start != null, "End date can be specified only with start date, but start date was null."); |
| 68 | + // The assignment makes 'end' recognized as @Nonnull. |
| 69 | + end = checkNotNull(end, "End date must be specified with start date, but was null."); |
| 70 | + |
| 71 | + String message = String.format("Start date [%s] must be before end date [%s].", start, end); |
| 72 | + checkState(end.isAfter(start), message); |
74 | 73 | } |
75 | 74 |
|
76 | 75 | void addTasksTo(@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments) |
|
0 commit comments