Class SearchFilter

java.lang.Object
net.solarnetwork.util.SearchFilter

public class SearchFilter extends Object
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
  • Field Details

    • filter

      protected final Map<String,?> filter
  • Constructor Details

  • Method Details

    • appendLDAPSearchFilter

      public void appendLDAPSearchFilter(StringBuilder buf)
      Appends this filter as a LDAP query string to a StringBuilder. If any value in the filter is itself a SearchFilter, the associated key is ignored and the SearchFilter is itself appended to the buffer. If the filter has only one key-value pair, the logicOp is ignored and not appended to the buffer. If the filter has more than one key-value pair and the logicOp is SearchFilter.LogicOperator.NOT, the filter will automatically be written as NOT(AND((x)(y))).
      Parameters:
      buf - the buffer to append to
    • asLDAPSearchFilterString

      public String asLDAPSearchFilterString()
      Return an LDAP search filter string.
      Returns:
      String
      See Also:
    • toString

      public String toString()
      Return an LDAP search filter string. This simply calls asLDAPSearchFilterString().
      Overrides:
      toString in class Object
      Returns:
      String
    • getCompareOperator

      public SearchFilter.CompareOperator getCompareOperator()
      Get the comparison operator.
      Returns:
      the comparison
    • getLogicOperator

      public SearchFilter.LogicOperator getLogicOperator()
      Get the logic operator.
      Returns:
      the logic
    • getFilter

      public Map<String,?> 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

      public void walk(SearchFilter.VisitorCallback callback)
      Walk the filter as a tree.
      Parameters:
      callback - the callback
    • forLDAPSearchFilterString

      public static SearchFilter forLDAPSearchFilterString(String s)
      Parse a LDAP search filter into a SearchFilter instance.
      Parameters:
      s - the string to parse
      Returns:
      the filter, or null if s is not in a valid format