PrefixFilterAdapter extends TypedFilterAdapterBase<PrefixFilter> { @Override public RangeSet<RowKeyWrapper> getIndexScanHint(PrefixFilter filter) { if (filter.getPrefix().length == 0) { return ImmutableRangeSet.of(Range.<RowKeyWrapper>all()); } else { ByteString start = ByteString.copyFrom(filter.getPrefix()); ByteString end = ByteString.copyFrom( RowKeyUtil.calculateTheClosestNextRowKeyForPrefix(filter.getPrefix())); return ImmutableRangeSet.of( Range.closedOpen(new RowKeyWrapper(start), new RowKeyWrapper(end))); } }  @Override Filter adapt(FilterAdapterContext context, PrefixFilter filter); @Override FilterSupportStatus isFilterSupported(FilterAdapterContext context, PrefixFilter filter); @Override RangeSet<RowKeyWrapper> getIndexScanHint(PrefixFilter filter);  }
@Test public void testIndexIsNarrowed() { PrefixFilterAdapter adapter = new PrefixFilterAdapter(); String prefix = "Foobar"; PrefixFilter filter = new PrefixFilter(Bytes.toBytes(prefix)); RangeSet<RowKeyWrapper> hint = adapter.getIndexScanHint(filter); ImmutableRangeSet<RowKeyWrapper> expected = ImmutableRangeSet.<RowKeyWrapper>builder() .add( Range.closedOpen( new RowKeyWrapper(ByteString.copyFromUtf8("Foobar")), new RowKeyWrapper(ByteString.copyFromUtf8("Foobas")))) .build(); Assert.assertEquals(expected, hint); }