OPENDJ-2965 Simplify OR and AND filters when only one element is provided in the expression
| | |
| | | } |
| | | else |
| | | { |
| | | subComps = new ArrayList<>(filterComponents.size()); |
| | | int compSize = filterComponents.size(); |
| | | if (compSize == 1) |
| | | { |
| | | // the filter can be simplified to the single component |
| | | return filterComponents.get(0).toSearchFilter(); |
| | | } |
| | | subComps = new ArrayList<>(compSize); |
| | | for (RawFilter f : filterComponents) |
| | | { |
| | | subComps.add(f.toSearchFilter()); |
| | |
| | | return new SearchFilter(filterType, null, notComponent, null, |
| | | null, null, null, null, null, false); |
| | | } |
| | | else if ((filterType == FilterType.AND || filterType == FilterType.OR) && filterComponents.size() == 1) |
| | | { |
| | | return filterComponents.get(0); |
| | | } |
| | | else |
| | | { |
| | | return new SearchFilter(filterType, filterComponents, null, |
| | |
| | | {"(!(sn=test))", "(!(sn=test))"}, |
| | | {"(|(sn=test)(sn=test2))", "(|(sn=test)(sn=test2))"}, |
| | | |
| | | {"(&(sn=test))", "(&(sn=test))"}, |
| | | {"(|(sn=test))", "(|(sn=test))"}, |
| | | {"(&(sn=test))", "(sn=test)"}, |
| | | {"(|(sn=test))", "(sn=test)"}, |
| | | {"(&(objectclass=person)(|(sn=test)))", "(&(objectClass=person)(sn=test))"}, |
| | | }; |
| | | } |
| | | |
| | |
| | | |
| | | private static final Object[][] TEST_EQUALS_PARAMS = new Object[][]{ |
| | | // These have duplicates, and their String representation should even reflect that. |
| | | {"(&(sn=Smith))", "(&(sn=Smith)(sn=Smith))", true, true}, |
| | | {"(|(sn=Smith))", "(|(sn=Smith)(sn=Smith))", true, true}, |
| | | {"(&(sn=Smith))", "(sn=Smith)", true, true}, |
| | | {"(|(sn=Smith))", "(sn=Smith)", true, true}, |
| | | |
| | | // These are reordered, so they are equivalent, but their String representations will differ |
| | | {"(&(sn=Smith)(sn<=Aus))", "(&(sn<=Aus)(sn=Smith))", true, false}, |