/*
 * Copyright 2012 Greplin, Inc. All Rights Reserved.
 */

package com.greplin.lucene.predicate;

import org.apache.lucene.search.BooleanClause;

/**
 * Common predicates.
 */
public final class Predicates {

  /** Not instantiable. */
  private Predicates() { }


  /**
   * Creates a new predicate bits provider that matches documents
   * matched by all of the arguments.
   * @param bitsProviders the sub-predicates.
   * @return a new predicate bits provider that matches documents
   * matched by all of the arguments.
   */
  public static BitsProvider and(final BitsProvider... bitsProviders) {
    BooleanBitsProvider result = new BooleanBitsProvider();
    for (BitsProvider provider : bitsProviders) {
      result.add(provider, BooleanClause.Occur.MUST);
    }
    return result;
  }


  /**
   * Creates a new predicate bits provider that matches documents
   * matched by any of the arguments.
   * @param bitsProviders the sub-predicates.
   * @return a new predicate bits provider that matches documents
   * matched by any of the arguments.
   */
  public static BitsProvider or(final BitsProvider... bitsProviders) {
    BooleanBitsProvider result = new BooleanBitsProvider();
    for (BitsProvider provider : bitsProviders) {
      result.add(provider, BooleanClause.Occur.SHOULD);
    }
    return result;
  }

}

@@ -122,28 +122,137 @@
 ene.
-search.BooleanClause
+index.IndexReader;%0Aimport org.apache.lucene.search.BooleanClause;%0Aimport org.apache.lucene.util.Bits;%0A%0Aimport java.io.IOException
 ;%0A%0A/
@@ -1403,32 +1403,32 @@
 .SHOULD);%0A    %7D%0A
-
     return resul
@@ -1435,10 +1435,1634 @@
 t;%0A  %7D%0A%0A
+%0A  /**%0A   * Creates a new predicate bits provider that matches documents%0A   * not matched by the argument.%0A   * @param bitsProvider the predicate to negate.%0A   * @return a new predicate bits provider that matches documents%0A   * not matched by the argument.%0A   */%0A  public static BitsProvider not(final BitsProvider bitsProvider) %7B%0A    return new InverseBitsProvider(bitsProvider);%0A  %7D%0A%0A%0A  /**%0A   * BitsProvider that matches the opposite set of bits as its%0A   * argument.%0A   */%0A  private static final class InverseBitsProvider extends BitsProvider %7B%0A%0A    /**%0A     * The original bits to negate.%0A     */%0A    private final BitsProvider original;%0A%0A%0A    /**%0A     * Creates a BitsProvider that negates its argument.%0A     * @param original the bits to negate.%0A     */%0A    private InverseBitsProvider(final BitsProvider original) %7B%0A      this.original = original;%0A    %7D%0A%0A%0A    @Override%0A    public Bits get(final IndexReader reader) throws IOException %7B%0A      return new InverseBits(this.original.get(reader));%0A    %7D%0A%0A  %7D%0A%0A%0A  /**%0A   * Bits that matches the opposite set of bits as its argument.%0A   */%0A  private static final class InverseBits implements Bits %7B%0A%0A    /**%0A     * The original bits to negate.%0A     */%0A    private final Bits original;%0A%0A%0A    /**%0A     * Creates Bits that negate the argument.%0A     * @param original the bits to negate.%0A     */%0A    private InverseBits(final Bits original) %7B%0A      this.original = original;%0A    %7D%0A%0A%0A    @Override%0A    public boolean get(final int index) %7B%0A      return !this.original.get(index);%0A    %7D%0A%0A%0A    @Override%0A    public int length() %7B%0A      return this.original.length();%0A    %7D%0A%0A  %7D%0A%0A
 %7D%0A

Predicate that matches the opposite of its argument