out.writeBoolean(closed);
final int closedSize = closedTransactions.size();
- final int purgedSize = purgedTransactions.size();
+ final int purgedSize = purgedTransactions.rangeSize();
WritableObjects.writeLongs(out, closedSize, purgedSize);
closedTransactions.writeEntriesTo(out, closedSize);
purgedTransactions.writeRangesTo(out, purgedSize);
if (mutable.isEmpty()) {
return of();
}
- if (mutable.size() <= ARRAY_MAX_ELEMENTS) {
+ if (mutable.rangeSize() <= ARRAY_MAX_ELEMENTS) {
return new ImmutableUnsignedLongSet(ImmutableSortedSet.copyOfSorted(mutable.trustedRanges()));
}
return new ImmutableUnsignedLongSet(new TreeSet<>(mutable.trustedRanges()));
@Override
public void writeTo(final DataOutput out) throws IOException {
- out.writeInt(size());
+ out.writeInt(rangeSize());
writeRanges(out);
}
public void writeRangesTo(final @NonNull DataOutput out, final int size) throws IOException {
- if (size != size()) {
- throw new IOException("Mismatched size: expected " + size() + ", got " + size);
+ final int rangeSize = rangeSize();
+ if (size != rangeSize) {
+ throw new IOException("Mismatched size: expected " + rangeSize + ", got " + size);
}
writeRanges(out);
}
import com.google.common.annotations.Beta;
import com.google.common.collect.Collections2;
import com.google.common.collect.ImmutableRangeSet;
+import com.google.common.collect.Range;
import com.google.common.primitives.UnsignedLong;
import java.util.NavigableSet;
import java.util.TreeSet;
return Entry.of(lowerBits, newUpper);
}
+ // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
public ImmutableRangeSet<UnsignedLong> toRangeSet() {
- return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), Entry::toUnsigned));
+ return ImmutableRangeSet.copyOf(Collections2.transform(trustedRanges(), entry -> Range.closedOpen(
+ UnsignedLong.fromLongBits(entry.lowerBits), UnsignedLong.fromLongBits(entry.upperBits + 1))));
}
}
import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects;
-import com.google.common.collect.Range;
import com.google.common.collect.RangeSet;
-import com.google.common.primitives.UnsignedLong;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
@Beta
@VisibleForTesting
public static final class Entry implements Comparable<Entry>, Immutable {
- final long lowerBits;
- final long upperBits;
+ public final long lowerBits;
+ public final long upperBits;
private Entry(final long lowerBits, final long upperBits) {
this.lowerBits = lowerBits;
return new Entry(lowerBits, upperBits);
}
- @VisibleForTesting
- public @NonNull UnsignedLong lower() {
- return UnsignedLong.fromLongBits(lowerBits);
- }
-
- @VisibleForTesting
- public @NonNull UnsignedLong upper() {
- return UnsignedLong.fromLongBits(upperBits);
- }
-
@NonNull Entry withLower(final long newLowerBits) {
return of(newLowerBits, upperBits);
}
return of(lowerBits, newUpperBits);
}
- // Provides compatibility with RangeSet<UnsignedLong> using [lower, upper + 1)
- @NonNull Range<UnsignedLong> toUnsigned() {
- return Range.closedOpen(UnsignedLong.fromLongBits(lowerBits), UnsignedLong.fromLongBits(upperBits + 1));
- }
-
// These two methods provide the same serialization format as the one we've used to serialize
// Range<UnsignedLong>
static @NonNull Entry readUnsigned(final DataInput in) throws IOException {
return ranges.isEmpty();
}
- public final int size() {
+ public final int rangeSize() {
return ranges.size();
}