/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 2.0.5
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */

package org.xapian;

public class Query {
  private long swigCPtr;
  protected boolean swigCMemOwn;

  public Query(long cPtr, boolean cMemoryOwn) {
    swigCMemOwn = cMemoryOwn;
    swigCPtr = cPtr;
  }

  public static long getCPtr(Query obj) {
    return (obj == null) ? 0 : obj.swigCPtr;
  }

  protected void finalize() {
    delete();
  }

  public synchronized void delete() {
    if (swigCPtr != 0) {
      if (swigCMemOwn) {
        swigCMemOwn = false;
        XapianJNI.delete_Query(swigCPtr);
      }
      swigCPtr = 0;
    }
  }

    // For compatibility with the original JNI wrappers.
    public final static op OP_AND = new op("OP_AND");
    public final static op OP_OR = new op("OP_OR");
    public final static op OP_AND_NOT = new op("OP_AND_NOT");
    public final static op OP_XOR = new op("OP_XOR");
    public final static op OP_AND_MAYBE = new op("OP_AND_MAYBE");
    public final static op OP_FILTER = new op("OP_FILTER");
    public final static op OP_NEAR = new op("OP_NEAR");
    public final static op OP_PHRASE = new op("OP_PHRASE");
    public final static op OP_ELITE_SET = new op("OP_ELITE_SET");
    public final static op OP_VALUE_RANGE = new op("OP_VALUE_RANGE");

    public final static Query MatchAll = new Query("");
    public final static Query MatchNothing = new Query();

    protected static long[] cArrayUnwrap(Query[] arrayWrapper) {
	long[] cArray = new long[arrayWrapper.length];
	for (int i=0; i<arrayWrapper.length; i++)
	    cArray[i] = Query.getCPtr(arrayWrapper[i]);
	return cArray;
    }

  public Query(Query copyme) {
    this(XapianJNI.new_Query__SWIG_0(Query.getCPtr(copyme), copyme), true);
  }

  public Query() {
    this(XapianJNI.new_Query__SWIG_1(), true);
  }

  public Query(String tname_, long wqf_, long pos_) {
    this(XapianJNI.new_Query__SWIG_2(tname_, wqf_, pos_), true);
  }

  public Query(String tname_, long wqf_) {
    this(XapianJNI.new_Query__SWIG_3(tname_, wqf_), true);
  }

  public Query(String tname_) {
    this(XapianJNI.new_Query__SWIG_4(tname_), true);
  }

  public Query(Query.op op_, Query left, Query right) {
    this(XapianJNI.new_Query__SWIG_5(op_.swigValue(), Query.getCPtr(left), left, Query.getCPtr(right), right), true);
  }

  public Query(Query.op op_, String left, String right) {
    this(XapianJNI.new_Query__SWIG_6(op_.swigValue(), left, right), true);
  }

  public Query(Query.op op_, Query q, double parameter) {
    this(XapianJNI.new_Query__SWIG_9(op_.swigValue(), Query.getCPtr(q), q, parameter), true);
  }

  public Query(Query.op op_, int slot, String begin, String end) {
    this(XapianJNI.new_Query__SWIG_10(op_.swigValue(), slot, begin, end), true);
  }

  public Query(Query.op op_, int slot, String value) {
    this(XapianJNI.new_Query__SWIG_11(op_.swigValue(), slot, value), true);
  }

  public Query(PostingSource external_source) {
    this(XapianJNI.new_Query__SWIG_12(PostingSource.getCPtr(external_source), external_source), true);
  }

  public long getLength() {
    return XapianJNI.Query_getLength(swigCPtr, this);
  }

  public TermIterator getTermsBegin() {
    return new TermIterator(XapianJNI.Query_getTermsBegin(swigCPtr, this), true);
  }

  public TermIterator getTermsEnd() {
    return new TermIterator(XapianJNI.Query_getTermsEnd(swigCPtr, this), true);
  }

  public boolean empty() {
    return XapianJNI.Query_empty(swigCPtr, this);
  }

  public String serialise() {
    return XapianJNI.Query_serialise(swigCPtr, this);
  }

  public static Query unserialise(String s) {
    return new Query(XapianJNI.Query_unserialise__SWIG_0(s), true);
  }

  public static Query unserialise(String s, Registry registry) {
    return new Query(XapianJNI.Query_unserialise__SWIG_1(s, Registry.getCPtr(registry), registry), true);
  }

  public String toString() {
    return XapianJNI.Query_toString(swigCPtr, this);
  }

  public Query(Query.op op, String[] subqs, long param) {
    this(XapianJNI.new_Query__SWIG_13(op.swigValue(), subqs, param), true);
  }

  public Query(Query.op op, String[] subqs) {
    this(XapianJNI.new_Query__SWIG_14(op.swigValue(), subqs), true);
  }

  public Query(Query.op op, Query[] subqs, long param) {
    this(XapianJNI.new_Query__SWIG_15(op.swigValue(), Query.cArrayUnwrap(subqs), param), true);
  }

  public Query(Query.op op, Query[] subqs) {
    this(XapianJNI.new_Query__SWIG_16(op.swigValue(), Query.cArrayUnwrap(subqs)), true);
  }

  public final static class op {
    public final static Query.op OP_AND = new Query.op("OP_AND");
    public final static Query.op OP_OR = new Query.op("OP_OR");
    public final static Query.op OP_AND_NOT = new Query.op("OP_AND_NOT");
    public final static Query.op OP_XOR = new Query.op("OP_XOR");
    public final static Query.op OP_AND_MAYBE = new Query.op("OP_AND_MAYBE");
    public final static Query.op OP_FILTER = new Query.op("OP_FILTER");
    public final static Query.op OP_NEAR = new Query.op("OP_NEAR");
    public final static Query.op OP_PHRASE = new Query.op("OP_PHRASE");
    public final static Query.op OP_VALUE_RANGE = new Query.op("OP_VALUE_RANGE");
    public final static Query.op OP_SCALE_WEIGHT = new Query.op("OP_SCALE_WEIGHT");
    public final static Query.op OP_ELITE_SET = new Query.op("OP_ELITE_SET");
    public final static Query.op OP_VALUE_GE = new Query.op("OP_VALUE_GE");
    public final static Query.op OP_VALUE_LE = new Query.op("OP_VALUE_LE");
    public final static Query.op OP_SYNONYM = new Query.op("OP_SYNONYM");

    public final int swigValue() {
      return swigValue;
    }

    public String toString() {
      return swigName;
    }

    public static op swigToEnum(int swigValue) {
      if (swigValue < swigValues.length && swigValue >= 0 && swigValues[swigValue].swigValue == swigValue)
        return swigValues[swigValue];
      for (int i = 0; i < swigValues.length; i++)
        if (swigValues[i].swigValue == swigValue)
          return swigValues[i];
      throw new IllegalArgumentException("No enum " + op.class + " with value " + swigValue);
    }

    private op(String swigName) {
      this.swigName = swigName;
      this.swigValue = swigNext++;
    }

    private op(String swigName, int swigValue) {
      this.swigName = swigName;
      this.swigValue = swigValue;
      swigNext = swigValue+1;
    }

    private op(String swigName, op swigEnum) {
      this.swigName = swigName;
      this.swigValue = swigEnum.swigValue;
      swigNext = this.swigValue+1;
    }

    private static op[] swigValues = { OP_AND, OP_OR, OP_AND_NOT, OP_XOR, OP_AND_MAYBE, OP_FILTER, OP_NEAR, OP_PHRASE, OP_VALUE_RANGE, OP_SCALE_WEIGHT, OP_ELITE_SET, OP_VALUE_GE, OP_VALUE_LE, OP_SYNONYM };
    private static int swigNext = 0;
    private final int swigValue;
    private final String swigName;
  }

}
