diff --git a/s3stream/src/main/java/com/automq/stream/s3/model/StreamRecordBatch.java b/s3stream/src/main/java/com/automq/stream/s3/model/StreamRecordBatch.java index 20c10addd..091b4e97f 100644 --- a/s3stream/src/main/java/com/automq/stream/s3/model/StreamRecordBatch.java +++ b/s3stream/src/main/java/com/automq/stream/s3/model/StreamRecordBatch.java @@ -18,9 +18,11 @@ package com.automq.stream.s3.model; import com.automq.stream.s3.StreamRecordBatchCodec; +import com.automq.stream.utils.biniarysearch.StreamRecordBatchList; +import com.automq.stream.utils.biniarysearch.primitive.LongComparableItem; import io.netty.buffer.ByteBuf; -public class StreamRecordBatch implements Comparable { +public class StreamRecordBatch implements Comparable, LongComparableItem { private final long streamId; private final long epoch; private final long baseOffset; @@ -113,4 +115,14 @@ public String toString() { ", count=" + count + ", size=" + size() + '}'; } + + @Override + public boolean isLessThan(long value) { + return getLastOffset() <= value; + } + + @Override + public boolean isGreaterThan(long value) { + return getBaseOffset() > value; + } } diff --git a/s3stream/src/main/java/com/automq/stream/utils/biniarysearch/StreamRecordBatchList.java b/s3stream/src/main/java/com/automq/stream/utils/biniarysearch/StreamRecordBatchList.java index 18428ab64..539886ae9 100644 --- a/s3stream/src/main/java/com/automq/stream/utils/biniarysearch/StreamRecordBatchList.java +++ b/s3stream/src/main/java/com/automq/stream/utils/biniarysearch/StreamRecordBatchList.java @@ -22,7 +22,6 @@ import com.automq.stream.utils.biniarysearch.primitive.LongOrderedCollection; import java.util.List; -import java.util.Objects; public class StreamRecordBatchList extends LongOrderedCollection { @@ -41,51 +40,7 @@ public int size() { @Override protected LongComparableItem get(int index) { - return new ComparableStreamRecordBatch(records.get(index)); + return records.get(index); } - - private static final class ComparableStreamRecordBatch implements LongComparableItem { - private final StreamRecordBatch recordBatch; - - private ComparableStreamRecordBatch(StreamRecordBatch recordBatch) { - this.recordBatch = recordBatch; - } - - @Override - public boolean isLessThan(long value) { - return recordBatch.getLastOffset() <= value; - } - - @Override - public boolean isGreaterThan(long value) { - return recordBatch.getBaseOffset() > value; - } - - public StreamRecordBatch recordBatch() { - return recordBatch; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) - return true; - if (obj == null || obj.getClass() != this.getClass()) - return false; - var that = (ComparableStreamRecordBatch) obj; - return Objects.equals(this.recordBatch, that.recordBatch); - } - - @Override - public int hashCode() { - return recordBatch.hashCode(); - } - - @Override - public String toString() { - return "ComparableStreamRecordBatch[" + - "recordBatch=" + recordBatch + ']'; - } - - } }