Skip to content

Commit a93c30e

Browse files
committed
Simplify checks in validateDateRange
1 parent f0c34ba commit a93c30e

File tree

1 file changed

+14
-15
lines changed
  • dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector

1 file changed

+14
-15
lines changed

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/connector/Connector.java

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
*/
1717
package com.google.edwmigration.dumper.application.dumper.connector;
1818

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+
2022
import com.google.edwmigration.dumper.application.dumper.ConnectorArguments;
2123
import com.google.edwmigration.dumper.application.dumper.handle.Handle;
2224
import com.google.edwmigration.dumper.application.dumper.task.Task;
@@ -55,22 +57,19 @@ default String getDescription() {
5557
default void validate(@Nonnull ConnectorArguments arguments) {}
5658

5759
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();
6062

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;
7365
}
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);
7473
}
7574

7675
void addTasksTo(@Nonnull List<? super Task<?>> out, @Nonnull ConnectorArguments arguments)

0 commit comments

Comments
 (0)