@@ -0,0 +1,1664 @@
+/*%0A * Copyright 2011 Greplin, Inc. All Rights Reserved.%0A */%0A%0Apackage com.greplin.lucene.query;%0A%0Aimport com.sun.istack.internal.Nullable;%0Aimport org.apache.lucene.search.BooleanClause;%0Aimport org.apache.lucene.search.BooleanFilter;%0Aimport org.apache.lucene.search.Filter;%0Aimport org.apache.lucene.search.FilterClause;%0A%0A/**%0A * Static utility methods for Filters.%0A */%0Apublic final class Filters %7B%0A%0A  /** Not instantiable. */%0A  private Filters() %7B %7D%0A%0A%0A  /**%0A   * Returns a filter that allows documents that match every constituent%0A   * filter.  For convenience, null values are accepted and ignored.  If%0A   * all values are null, null will be returned.%0A   * @param filters the filters to combine%0A   * @return the combined filter%0A   */%0A  @Nullable public static Filter and(@Nullable final Filter... filters) %7B%0A    final BooleanFilter booleanFilter = new BooleanFilter();%0A%0A    Filter lastFilter = null;%0A    int count = 0;%0A    for (Filter filter : filters) %7B%0A      if (filter != null) %7B%0A        booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST));%0A        count += 1;%0A        lastFilter = filter;%0A      %7D%0A    %7D%0A%0A    if (count == 0) %7B%0A      return null;%0A    %7D else if (count == 1) %7B%0A      return lastFilter;%0A    %7D else %7B%0A      return booleanFilter;%0A    %7D%0A  %7D%0A%0A%0A  /**%0A   * Returns a filter matching the inverse of the given filter.%0A   * @param filter the filter to return the opposite ofnegate%0A   * @return the negated filter%0A   */%0A  public static Filter not(final Filter filter) %7B%0A    final BooleanFilter booleanFilter = new BooleanFilter();%0A    booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST_NOT));%0A    return booleanFilter;%0A  %7D%0A%0A%7D%0A

Add static utility methods for filters