TupleRange { @Nonnull public Range toRange() { return toRange( low == null ? null : low.pack(), high == null ? null : high.pack(), lowEndpoint, highEndpoint ); } TupleRange(@Nullable Tuple low, @Nullable Tuple high,
                      @Nonnull EndpointType lowEndpoint, @Nonnull EndpointType highEndpoint); @Nullable Tuple getLow(); @Nullable Tuple getHigh(); @Nonnull EndpointType getLowEndpoint(); @Nonnull EndpointType getHighEndpoint(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); @SuppressWarnings("PMD.UnusedNullCheckInEquals") // uses TupleHelpers::equals for efficiency reasons boolean isEquals(); @Nonnull @SuppressWarnings("PMD.UnusedNullCheckInEquals") // uses TupleHelpers::equals for efficiency reasons TupleRange prepend(@Nonnull Tuple beginning); @Nonnull static TupleRange allOf(@Nullable Tuple prefix); static TupleRange between(@Nullable Tuple low, @Nullable Tuple high); @Nonnull static TupleRange prefixedBy(@Nonnull String prefixString); @Nonnull Range toRange(); @Nonnull Range toRange(@Nonnull Subspace subspace); @Nonnull static Range toRange(@Nullable byte[] lowBytes, @Nullable byte[] highBytes,
                                @Nonnull EndpointType lowEndpoint, @Nonnull EndpointType highEndpoint); static final TupleRange ALL; }
@Test public void toRange() { final Tuple a = Tuple.from("a"); final Tuple b = Tuple.from("b"); List<Pair<TupleRange, Range>> testCases = Arrays.asList( Pair.of(TupleRange.allOf(null), new Range(new byte[0], new byte[]{(byte)0xff})), Pair.of(TupleRange.allOf(PREFIX_TUPLE), Range.startsWith(PREFIX_BYTES)), Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_EXCLUSIVE), new Range(a.pack(), b.pack())), Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.RANGE_INCLUSIVE), new Range(a.pack(), ByteArrayUtil.strinc(b.pack()))), Pair.of(new TupleRange(a, b, EndpointType.RANGE_EXCLUSIVE, EndpointType.RANGE_EXCLUSIVE), new Range(ByteArrayUtil.strinc(a.pack()), b.pack())), Pair.of(new TupleRange(a, b, EndpointType.RANGE_EXCLUSIVE, EndpointType.RANGE_INCLUSIVE), new Range(ByteArrayUtil.strinc(a.pack()), ByteArrayUtil.strinc(b.pack()))), Pair.of(new TupleRange(null, b, EndpointType.TREE_START, EndpointType.RANGE_EXCLUSIVE), new Range(new byte[0], b.pack())), Pair.of(new TupleRange(a, null, EndpointType.RANGE_INCLUSIVE, EndpointType.TREE_END), new Range(a.pack(), new byte[]{(byte)0xff})), Pair.of(new TupleRange(a, b, EndpointType.CONTINUATION, EndpointType.RANGE_EXCLUSIVE), new Range(ByteArrayUtil.join(a.pack(), new byte[]{0x00}), b.pack())), Pair.of(new TupleRange(a, b, EndpointType.RANGE_INCLUSIVE, EndpointType.CONTINUATION), new Range(a.pack(), b.pack())), Pair.of(TupleRange.prefixedBy("a"), new Range(new byte[]{0x02, (byte)'a'}, new byte[]{0x02, (byte)'b'})), Pair.of(new TupleRange(Tuple.from("apple"), a, EndpointType.CONTINUATION, EndpointType.PREFIX_STRING), new Range(ByteArrayUtil.join(Tuple.from("apple").pack(), new byte[]{0x00}), new byte[]{0x02, (byte)'b'})), Pair.of(new TupleRange(a, Tuple.from("apple"), EndpointType.PREFIX_STRING, EndpointType.CONTINUATION), new Range(new byte[]{0x02, (byte)'a'}, Tuple.from("apple").pack())) ); testCases.forEach(pair -> { assertEquals(pair.getRight(), pair.getLeft().toRange()); TupleRange expectedRange = pair.getLeft().prepend(PREFIX_TUPLE); assertEquals(expectedRange.toRange(), pair.getLeft().toRange(PREFIX_SUBSPACE)); }); }