Skip to content

Commit

Permalink
Use nullable Boolean instead of Optional
Browse files Browse the repository at this point in the history
  • Loading branch information
guillermocalvo committed Aug 22, 2023
1 parent 5d50906 commit 6647ef5
Showing 1 changed file with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public boolean perform(@NonNull KafkaSeekOperation operation) {
try {
final TopicPartition tp = operation.topicPartition();
if (operation.offset() == 0) {
Optional<Boolean> performed = performForZeroOffset(operation, tp);
if (performed.isPresent()) {
return performed.get();
Boolean performed = performForZeroOffset(operation, tp);
if (performed != null) {
return performed;
}
}
final long offset = offset(operation, tp);
Expand All @@ -72,32 +72,32 @@ public boolean perform(@NonNull KafkaSeekOperation operation) {
}
}

@NonNull
private Optional<Boolean> performForZeroOffset(@NonNull KafkaSeekOperation operation,
@Nullable TopicPartition tp) {
@Nullable
private Boolean performForZeroOffset(@NonNull KafkaSeekOperation operation,
@NonNull TopicPartition tp) {
final String topic = operation.topic();
final int partition = operation.partition();
switch (operation.offsetType()) {
case FORWARD, BACKWARD -> {
// Special case: relative zero-offset
LOG.debug("Relative zero-offset seek operation dropped: {}", operation);
return Optional.of(false);
return Boolean.FALSE;
}
case BEGINNING -> {
// Optimized case: seek to the beginning
consumer.seekToBeginning(singletonList(tp));
LOG.debug("Seek to the beginning operation succeeded: {}-{}", topic, partition);
return Optional.of(true);
return Boolean.TRUE;
}
case END -> {
// Optimized case: seek to the end
consumer.seekToEnd(singletonList(tp));
LOG.debug("Seek to the end operation succeeded: {}-{}", topic, partition);
return Optional.of(true);
return Boolean.TRUE;
}
default -> {
/* Perform operation regularly */
return Optional.empty();
return null;
}
}
}
Expand Down

0 comments on commit 6647ef5

Please sign in to comment.