BooleanNormalizer { public static BooleanNormalizer forConfiguration(RecordQueryPlannerConfiguration configuration) { if (configuration.getComplexityThreshold() == DEFAULT_SIZE_LIMIT && !configuration.shouldCheckForDuplicateConditions()) { return DEFAULT; } return new BooleanNormalizer(configuration.getComplexityThreshold(), configuration.shouldCheckForDuplicateConditions()); } private  BooleanNormalizer(int sizeLimit, boolean checkForDuplicateConditions); @Nonnull static BooleanNormalizer getDefaultInstance(); @Nonnull static BooleanNormalizer withLimit(int sizeLimit); static BooleanNormalizer forConfiguration(RecordQueryPlannerConfiguration configuration); int getSizeLimit(); boolean isCheckForDuplicateConditions(); @Nullable QueryComponent normalizeIfPossible(@Nullable final QueryComponent predicate); @Nullable QueryComponent normalize(@Nullable final QueryComponent predicate); static final int DEFAULT_SIZE_LIMIT; }
@Test public void redundant() { final BooleanNormalizer eliminator = BooleanNormalizer.forConfiguration( RecordQueryPlannerConfiguration.builder().setCheckForDuplicateConditions(true).build()); assertExpectedNormalization(Query.or(Query.and(P1, P2, P3), Query.and(P1, P2, P4, P3)), Query.and(P1, Query.or(Query.and(P2, P3), Query.and(P2, P4, P3)))); assertExpectedNormalization(eliminator, Query.and(P1, P2, P3), Query.and(P1, Query.or(Query.and(P2, P3), Query.and(P2, P4, P3)))); }