WhileMatchFilterAdapter extends TypedFilterAdapterBase<WhileMatchFilter> { @Override public Filters.Filter adapt(FilterAdapterContext context, WhileMatchFilter filter) throws IOException { checkArgument( context.getNumberOfWhileMatchFilters() == 0, "More than one WhileMatchFilter is not supported."); checkNotNull(filter.getFilter(), "The wrapped filter for a WhileMatchFilter cannot be null."); Optional<Filters.Filter> wrappedFilter = subFilterAdapter.adaptFilter(context, filter.getFilter()); checkArgument( wrappedFilter.isPresent(), "Unable to adapted the wrapped filter: " + filter.getFilter()); String whileMatchFilterId = context.getNextUniqueId(); Filters.Filter inLabel = FILTERS.label(whileMatchFilterId + IN_LABEL_SUFFIX); Filters.Filter inLabelAndSink = FILTERS.chain().filter(inLabel).filter(FILTERS.sink()); Filters.Filter outLabel = FILTERS.label(whileMatchFilterId + OUT_LABEL_SUFFIX); Filters.Filter outLabelAndSink = FILTERS.chain().filter(outLabel).filter(FILTERS.sink()); Filters.Filter outInterleave = FILTERS.interleave().filter(outLabelAndSink).filter(FILTERS.pass()); Filters.Filter outChain = FILTERS.chain().filter(wrappedFilter.get()).filter(outInterleave); Filters.Filter finalFilter = FILTERS.interleave().filter(inLabelAndSink).filter(outChain); context.addWhileMatchFilter(filter); return finalFilter; } WhileMatchFilterAdapter(FilterAdapter subFilterAdapter); @Override Filters.Filter adapt(FilterAdapterContext context, WhileMatchFilter filter); @Override FilterSupportStatus isFilterSupported(
      FilterAdapterContext context, WhileMatchFilter filter);  }
@Test public void nullWrappedFilter() throws IOException { thrown.expect(NullPointerException.class); thrown.expectMessage("The wrapped filter for a WhileMatchFilter cannot be null."); WhileMatchFilter filter = new WhileMatchFilter(null); instance.adapt(emptyScanContext, filter); }
@Test public void simpleWrappedFilter() throws IOException { ValueFilter valueFilter = new ValueFilter(CompareFilter.CompareOp.LESS, new BinaryComparator(Bytes.toBytes("12"))); WhileMatchFilter filter = new WhileMatchFilter(valueFilter); Filters.Filter actualFilter = instance.adapt(emptyScanContext, filter); Filters.Filter expectedFilter = buildExpectedRowFilter( filterAdapter.adaptFilter(emptyScanContext, valueFilter).get(), emptyScanContext.getCurrentUniqueId()); assertEquals(expectedFilter.toProto(), actualFilter.toProto()); }
@Test public void twoFiltersNotSupported() throws IOException { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("More than one WhileMatchFilter is not supported."); ValueFilter valueFilter = new ValueFilter(CompareFilter.CompareOp.LESS, new BinaryComparator(Bytes.toBytes("12"))); WhileMatchFilter filter = new WhileMatchFilter(valueFilter); instance.adapt(emptyScanContext, filter); instance.adapt(emptyScanContext, filter); }
@Test public void unableToAdaptWrappedFilter() throws IOException { thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Unable to adapted the wrapped filter: PageFilter 30"); WhileMatchFilter filter = new WhileMatchFilter(new PageFilter(30)); instance.adapt(emptyScanContext, filter); }