chia7712 commented on code in PR #16207:
URL: https://github.com/apache/kafka/pull/16207#discussion_r1628201256


##########
storage/src/test/java/org/apache/kafka/server/log/remote/storage/RemoteTopicPartitionDirectory.java:
##########
@@ -95,7 +95,7 @@ boolean delete() {
 
     void traverse(final LocalTieredStorageTraverser traverser) {
         traverser.visitTopicIdPartition(topicIdPartition);
-        listFilesets().stream().forEach(fileset -> 
traverser.visitSegment(fileset));
+        listFilesets().forEach(fileset -> traverser.visitSegment(fileset));

Review Comment:
   how about: `listFilesets().forEach(traverser::visitSegment);`



##########
storage/src/main/java/org/apache/kafka/storage/internals/epoch/LeaderEpochFileCache.java:
##########
@@ -176,14 +176,14 @@ public Optional<EpochEntry> latestEntry() {
      */
     public OptionalInt latestEpoch() {
         Optional<EpochEntry> entry = latestEntry();
-        return entry.isPresent() ? OptionalInt.of(entry.get().epoch) : 
OptionalInt.empty();
+        return entry.map(epochEntry -> 
OptionalInt.of(epochEntry.epoch)).orElseGet(OptionalInt::empty);
     }
 
     public OptionalInt previousEpoch() {
         lock.readLock().lock();
         try {
             Optional<Map.Entry<Integer, EpochEntry>> lowerEntry = 
latestEntry().flatMap(entry -> 
Optional.ofNullable(epochs.lowerEntry(entry.epoch)));
-            return lowerEntry.isPresent() ? 
OptionalInt.of(lowerEntry.get().getKey()) : OptionalInt.empty();
+            return lowerEntry.map(integerEpochEntryEntry -> 
OptionalInt.of(integerEpochEntryEntry.getKey())).orElseGet(OptionalInt::empty);

Review Comment:
   maybe we can eliminate local variable `lowerEntry`
   
   ```java
               return latestEntry().flatMap(entry -> 
Optional.ofNullable(epochs.lowerEntry(entry.epoch)))
                   .map(entry -> OptionalInt.of(entry.getKey()))
                   .orElseGet(OptionalInt::empty);
   ```



##########
storage/src/main/java/org/apache/kafka/storage/internals/log/LogSegment.java:
##########
@@ -459,9 +459,7 @@ public FetchDataInfo read(long startOffset, int maxSize, 
Optional<Long> maxPosit
 
     public OptionalLong fetchUpperBoundOffset(OffsetPosition 
startOffsetPosition, int fetchSize) throws IOException {
         Optional<OffsetPosition> position = 
offsetIndex().fetchUpperBoundOffset(startOffsetPosition, fetchSize);
-        if (position.isPresent())
-            return OptionalLong.of(position.get().offset);
-        return OptionalLong.empty();
+        return position.map(offsetPosition -> 
OptionalLong.of(offsetPosition.offset)).orElseGet(OptionalLong::empty);

Review Comment:
   ditto
   ```java
           return offsetIndex().fetchUpperBoundOffset(startOffsetPosition, 
fetchSize)
               .map(offsetPosition -> 
OptionalLong.of(offsetPosition.offset)).orElseGet(OptionalLong::empty);
   ```



##########
storage/src/main/java/org/apache/kafka/storage/internals/epoch/LeaderEpochFileCache.java:
##########
@@ -176,14 +176,14 @@ public Optional<EpochEntry> latestEntry() {
      */
     public OptionalInt latestEpoch() {
         Optional<EpochEntry> entry = latestEntry();
-        return entry.isPresent() ? OptionalInt.of(entry.get().epoch) : 
OptionalInt.empty();
+        return entry.map(epochEntry -> 
OptionalInt.of(epochEntry.epoch)).orElseGet(OptionalInt::empty);

Review Comment:
   ditto
   ```java
   latestEntry().map(epochEntry -> 
OptionalInt.of(epochEntry.epoch)).orElseGet(OptionalInt::empty);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to