Package net.solarnetwork.util
Class SearchFilter
java.lang.Object
net.solarnetwork.util.SearchFilter
Generic search filter supporting LDAP-style search queries.
This filter supports a group of key-value pairs joined by a common logical
operator. The key-value pairs are provided by a Map. Nested
SearchFilter instances can be used as values so that complex logic
can be implemented.
- Version:
- 2.0
- Author:
- matt
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumA comparison operator for a single filter.static enumA filter logic qualifier for multiple filters.static interfaceAPI for visiting all filters as a tree. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSearchFilter(String key, Object value, SearchFilter.CompareOperator compareOp) Construct with a single key-value pair.SearchFilter(Map<String, ?> filter) Construct with a filter.SearchFilter(Map<String, ?> filter, SearchFilter.CompareOperator compareOp, SearchFilter.LogicOperator logicOp) Construct with values.SearchFilter(Map<String, ?> filter, SearchFilter.LogicOperator logicOp) Construct with a filter and logic operator andSearchFilter.CompareOperator.EQUALcomparison operator. -
Method Summary
Modifier and TypeMethodDescriptionvoidAppends this filter as a LDAP query string to a StringBuilder.Return an LDAP search filter string.static SearchFilterParse a LDAP search filter into aSearchFilterinstance.Get the comparison operator.Get the filter values.Get the logic operator.booleanTest if this filter has any nested filters.toString()Return an LDAP search filter string.voidwalk(SearchFilter.VisitorCallback callback) Walk the filter as a tree.
-
Field Details
-
filter
-
-
Constructor Details
-
SearchFilter
Construct with a filter. UsesSearchFilter.CompareOperator.EQUALandSearchFilter.LogicOperator.AND.- Parameters:
filter- the filter value
-
SearchFilter
public SearchFilter(Map<String, ?> filter, SearchFilter.CompareOperator compareOp, SearchFilter.LogicOperator logicOp) Construct with values.- Parameters:
filter- the filter valuecompareOp- the comparison operatorlogicOp- the logical operator
-
SearchFilter
Construct with a single key-value pair.- Parameters:
key- the keyvalue- the valuecompareOp- the comparison operator
-
SearchFilter
Construct with a filter and logic operator andSearchFilter.CompareOperator.EQUALcomparison operator.- Parameters:
filter- the filterlogicOp- the logic operator
-
-
Method Details
-
appendLDAPSearchFilter
Appends this filter as a LDAP query string to a StringBuilder. If any value in thefilteris itself aSearchFilter, the associated key is ignored and theSearchFilteris itself appended to the buffer. If thefilterhas only one key-value pair, thelogicOpis ignored and not appended to the buffer. If thefilterhas more than one key-value pair and thelogicOpisSearchFilter.LogicOperator.NOT, the filter will automatically be written asNOT(AND((x)(y))).- Parameters:
buf- the buffer to append to
-
asLDAPSearchFilterString
Return an LDAP search filter string.- Returns:
- String
- See Also:
-
toString
Return an LDAP search filter string. This simply callsasLDAPSearchFilterString(). -
getCompareOperator
Get the comparison operator.- Returns:
- the comparison
-
getLogicOperator
Get the logic operator.- Returns:
- the logic
-
getFilter
Get the filter values.- Returns:
- the filter
-
hasNestedFilter
public boolean hasNestedFilter()Test if this filter has any nested filters.- Returns:
- true if any nested filters exist within this filter
- Since:
- 1.1
-
walk
Walk the filter as a tree.- Parameters:
callback- the callback
-
forLDAPSearchFilterString
Parse a LDAP search filter into aSearchFilterinstance.- Parameters:
s- the string to parse- Returns:
- the filter, or null if
sis not in a valid format
-