/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

/** A passage search result.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class Passage extends SearchResult {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Passage.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected Passage() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public Passage(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public Passage(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: title

  /** getter for title - gets The title of the document that contains this passage.
   * @generated
   * @return value of the feature
   */
  public String getTitle() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_title == null)
      jcasType.jcas.throwFeatMissing("title", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Passage_Type)jcasType).casFeatCode_title);}

  /** setter for title - sets The title of the document that contains this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setTitle(String v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_title == null)
      jcasType.jcas.throwFeatMissing("title", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setStringValue(addr, ((Passage_Type)jcasType).casFeatCode_title, v);}

  //*--------------*
  //* Feature: docId

  /** getter for docId - gets A unique identifier for the document that conatins this passage.
   * @generated
   * @return value of the feature
   */
  public String getDocId() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Passage_Type)jcasType).casFeatCode_docId);}

  /** setter for docId - sets A unique identifier for the document that conatins this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setDocId(String v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setStringValue(addr, ((Passage_Type)jcasType).casFeatCode_docId, v);}

  //*--------------*
  //* Feature: offsetInBeginSection

  /** getter for offsetInBeginSection - gets Character offset of the start of this passage within the section that contains this passage.
   * @generated
   * @return value of the feature
   */
  public int getOffsetInBeginSection() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_offsetInBeginSection == null)
      jcasType.jcas.throwFeatMissing("offsetInBeginSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getIntValue(addr, ((Passage_Type)jcasType).casFeatCode_offsetInBeginSection);}

  /** setter for offsetInBeginSection - sets Character offset of the start of this passage within the section that contains this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setOffsetInBeginSection(int v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_offsetInBeginSection == null)
      jcasType.jcas.throwFeatMissing("offsetInBeginSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setIntValue(addr, ((Passage_Type)jcasType).casFeatCode_offsetInBeginSection, v);}

  //*--------------*
  //* Feature: offsetInEndSection

  /** getter for offsetInEndSection - gets Character offset of the end of this passage within the section that contains this passage.
   * @generated
   * @return value of the feature
   */
  public int getOffsetInEndSection() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_offsetInEndSection == null)
      jcasType.jcas.throwFeatMissing("offsetInEndSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getIntValue(addr, ((Passage_Type)jcasType).casFeatCode_offsetInEndSection);}

  /** setter for offsetInEndSection - sets Character offset of the end of this passage within the section that contains this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setOffsetInEndSection(int v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_offsetInEndSection == null)
      jcasType.jcas.throwFeatMissing("offsetInEndSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setIntValue(addr, ((Passage_Type)jcasType).casFeatCode_offsetInEndSection, v);}

  //*--------------*
  //* Feature: beginSection

  /** getter for beginSection - gets The start section of this passage within the document that contains this passage.
   * @generated
   * @return value of the feature
   */
  public String getBeginSection() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_beginSection == null)
      jcasType.jcas.throwFeatMissing("beginSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Passage_Type)jcasType).casFeatCode_beginSection);}

  /** setter for beginSection - sets The start section of this passage within the document that contains this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setBeginSection(String v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_beginSection == null)
      jcasType.jcas.throwFeatMissing("beginSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setStringValue(addr, ((Passage_Type)jcasType).casFeatCode_beginSection, v);}

  //*--------------*
  //* Feature: endSection

  /** getter for endSection - gets The end section of this passage within the document that contains this passage.
   * @generated
   * @return value of the feature
   */
  public String getEndSection() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_endSection == null)
      jcasType.jcas.throwFeatMissing("endSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Passage_Type)jcasType).casFeatCode_endSection);}

  /** setter for endSection - sets The end section of this passage within the document that contains this passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setEndSection(String v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_endSection == null)
      jcasType.jcas.throwFeatMissing("endSection", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setStringValue(addr, ((Passage_Type)jcasType).casFeatCode_endSection, v);}

  //*--------------*
  //* Feature: aspects

  /** getter for aspects - gets Aspects of the gold standard passage.
   * @generated
   * @return value of the feature
   */
  public String getAspects() {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_aspects == null)
      jcasType.jcas.throwFeatMissing("aspects", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Passage_Type)jcasType).casFeatCode_aspects);}

  /** setter for aspects - sets Aspects of the gold standard passage.
   * @generated
   * @param v value to set into the feature
   */
  public void setAspects(String v) {
    if (Passage_Type.featOkTst && ((Passage_Type)jcasType).casFeat_aspects == null)
      jcasType.jcas.throwFeatMissing("aspects", "edu.cmu.lti.oaqa.type.retrieval.Passage");
    jcasType.ll_cas.ll_setStringValue(addr, ((Passage_Type)jcasType).casFeatCode_aspects, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import edu.cmu.lti.oaqa.type.kb.Triple;

/** A search result from a triple store, e.g., an RDF store.
 * Updated by JCasGen Sun Apr 19 19:46:51 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class TripleSearchResult extends AnswerSearchResult {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(TripleSearchResult.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected TripleSearchResult() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public TripleSearchResult(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public TripleSearchResult(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: triple

  /** getter for triple - gets The relevant triple searched in the RDF store.
   * @generated
   * @return value of the feature
   */
  public Triple getTriple() {
    if (TripleSearchResult_Type.featOkTst && ((TripleSearchResult_Type)jcasType).casFeat_triple == null)
      jcasType.jcas.throwFeatMissing("triple", "edu.cmu.lti.oaqa.type.retrieval.TripleSearchResult");
    return (Triple)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((TripleSearchResult_Type)jcasType).casFeatCode_triple)));}

  /** setter for triple - sets The relevant triple searched in the RDF store.
   * @generated
   * @param v value to set into the feature
   */
  public void setTriple(Triple v) {
    if (TripleSearchResult_Type.featOkTst && ((TripleSearchResult_Type)jcasType).casFeat_triple == null)
      jcasType.jcas.throwFeatMissing("triple", "edu.cmu.lti.oaqa.type.retrieval.TripleSearchResult");
    jcasType.ll_cas.ll_setRefValue(addr, ((TripleSearchResult_Type)jcasType).casFeatCode_triple, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import edu.cmu.lti.oaqa.type.kb.Triple;

/** A passage search result that was the result of a search from the subject and object of a triple
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class PassageFromRelation extends Passage {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(PassageFromRelation.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected PassageFromRelation() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public PassageFromRelation(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public PassageFromRelation(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: sourceRelation

  /** getter for sourceRelation - gets The triple from which the search result was generated
   * @generated
   * @return value of the feature
   */
  public Triple getSourceRelation() {
    if (PassageFromRelation_Type.featOkTst && ((PassageFromRelation_Type)jcasType).casFeat_sourceRelation == null)
      jcasType.jcas.throwFeatMissing("sourceRelation", "edu.cmu.lti.oaqa.type.retrieval.PassageFromRelation");
    return (Triple)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((PassageFromRelation_Type)jcasType).casFeatCode_sourceRelation)));}

  /** setter for sourceRelation - sets The triple from which the search result was generated
   * @generated
   * @param v value to set into the feature
   */
  public void setSourceRelation(Triple v) {
    if (PassageFromRelation_Type.featOkTst && ((PassageFromRelation_Type)jcasType).casFeat_sourceRelation == null)
      jcasType.jcas.throwFeatMissing("sourceRelation", "edu.cmu.lti.oaqa.type.retrieval.PassageFromRelation");
    jcasType.ll_cas.ll_setRefValue(addr, ((PassageFromRelation_Type)jcasType).casFeatCode_sourceRelation, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.kb;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.TOP;

/** A triple, e.g., and RDF triple.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class Triple extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Triple.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected Triple() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public Triple(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public Triple(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: subject

  /** getter for subject - gets The subject of the triple - always a URI.
   * @generated
   * @return value of the feature
   */
  public String getSubject() {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_subject == null)
      jcasType.jcas.throwFeatMissing("subject", "edu.cmu.lti.oaqa.type.kb.Triple");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Triple_Type)jcasType).casFeatCode_subject);}

  /** setter for subject - sets The subject of the triple - always a URI.
   * @generated
   * @param v value to set into the feature
   */
  public void setSubject(String v) {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_subject == null)
      jcasType.jcas.throwFeatMissing("subject", "edu.cmu.lti.oaqa.type.kb.Triple");
    jcasType.ll_cas.ll_setStringValue(addr, ((Triple_Type)jcasType).casFeatCode_subject, v);}

  //*--------------*
  //* Feature: predicate

  /** getter for predicate - gets The predicate of the triple - always a URI.
   * @generated
   * @return value of the feature
   */
  public String getPredicate() {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_predicate == null)
      jcasType.jcas.throwFeatMissing("predicate", "edu.cmu.lti.oaqa.type.kb.Triple");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Triple_Type)jcasType).casFeatCode_predicate);}

  /** setter for predicate - sets The predicate of the triple - always a URI.
   * @generated
   * @param v value to set into the feature
   */
  public void setPredicate(String v) {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_predicate == null)
      jcasType.jcas.throwFeatMissing("predicate", "edu.cmu.lti.oaqa.type.kb.Triple");
    jcasType.ll_cas.ll_setStringValue(addr, ((Triple_Type)jcasType).casFeatCode_predicate, v);}

  //*--------------*
  //* Feature: object

  /** getter for object - gets The object of the triple - may be a URI or an xml datatype (string, int, etc.). See isObjeUri to determine if object is a URI.
   * @generated
   * @return value of the feature
   */
  public String getObject() {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_object == null)
      jcasType.jcas.throwFeatMissing("object", "edu.cmu.lti.oaqa.type.kb.Triple");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Triple_Type)jcasType).casFeatCode_object);}

  /** setter for object - sets The object of the triple - may be a URI or an xml datatype (string, int, etc.). See isObjeUri to determine if object is a URI.
   * @generated
   * @param v value to set into the feature
   */
  public void setObject(String v) {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_object == null)
      jcasType.jcas.throwFeatMissing("object", "edu.cmu.lti.oaqa.type.kb.Triple");
    jcasType.ll_cas.ll_setStringValue(addr, ((Triple_Type)jcasType).casFeatCode_object, v);}

  //*--------------*
  //* Feature: isObjUri

  /** getter for isObjUri - gets Boolean flag - true of object field is a URI, false otherwise.
   * @generated
   * @return value of the feature
   */
  public boolean getIsObjUri() {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_isObjUri == null)
      jcasType.jcas.throwFeatMissing("isObjUri", "edu.cmu.lti.oaqa.type.kb.Triple");
    return jcasType.ll_cas.ll_getBooleanValue(addr, ((Triple_Type)jcasType).casFeatCode_isObjUri);}

  /** setter for isObjUri - sets Boolean flag - true of object field is a URI, false otherwise.
   * @generated
   * @param v value to set into the feature
   */
  public void setIsObjUri(boolean v) {
    if (Triple_Type.featOkTst && ((Triple_Type)jcasType).casFeat_isObjUri == null)
      jcasType.jcas.throwFeatMissing("isObjUri", "edu.cmu.lti.oaqa.type.kb.Triple");
    jcasType.ll_cas.ll_setBooleanValue(addr, ((Triple_Type)jcasType).casFeatCode_isObjUri, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.FSList;

/** A hierarchical query concept represented by a query operation on a list of concepts
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class ComplexQueryConcept extends QueryConcept {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(ComplexQueryConcept.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected ComplexQueryConcept() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public ComplexQueryConcept(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public ComplexQueryConcept(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: operator

  /** getter for operator - gets The operator associated with this concept.
   * @generated
   * @return value of the feature
   */
  public QueryOperator getOperator() {
    if (ComplexQueryConcept_Type.featOkTst && ((ComplexQueryConcept_Type)jcasType).casFeat_operator == null)
      jcasType.jcas.throwFeatMissing("operator", "edu.cmu.lti.oaqa.type.retrieval.ComplexQueryConcept");
    return (QueryOperator)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((ComplexQueryConcept_Type)jcasType).casFeatCode_operator)));}

  /** setter for operator - sets The operator associated with this concept.
   * @generated
   * @param v value to set into the feature
   */
  public void setOperator(QueryOperator v) {
    if (ComplexQueryConcept_Type.featOkTst && ((ComplexQueryConcept_Type)jcasType).casFeat_operator == null)
      jcasType.jcas.throwFeatMissing("operator", "edu.cmu.lti.oaqa.type.retrieval.ComplexQueryConcept");
    jcasType.ll_cas.ll_setRefValue(addr, ((ComplexQueryConcept_Type)jcasType).casFeatCode_operator, jcasType.ll_cas.ll_getFSRef(v));}

  //*--------------*
  //* Feature: operatorArgs

  /** getter for operatorArgs - gets The operator arguments in a complex query concept.
   * @generated
   * @return value of the feature
   */
  public FSList getOperatorArgs() {
    if (ComplexQueryConcept_Type.featOkTst && ((ComplexQueryConcept_Type)jcasType).casFeat_operatorArgs == null)
      jcasType.jcas.throwFeatMissing("operatorArgs", "edu.cmu.lti.oaqa.type.retrieval.ComplexQueryConcept");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((ComplexQueryConcept_Type)jcasType).casFeatCode_operatorArgs)));}

  /** setter for operatorArgs - sets The operator arguments in a complex query concept.
   * @generated
   * @param v value to set into the feature
   */
  public void setOperatorArgs(FSList v) {
    if (ComplexQueryConcept_Type.featOkTst && ((ComplexQueryConcept_Type)jcasType).casFeat_operatorArgs == null)
      jcasType.jcas.throwFeatMissing("operatorArgs", "edu.cmu.lti.oaqa.type.retrieval.ComplexQueryConcept");
    jcasType.ll_cas.ll_setRefValue(addr, ((ComplexQueryConcept_Type)jcasType).casFeatCode_operatorArgs, jcasType.ll_cas.ll_getFSRef(v));}
  }


/**
 * Copyright © 2013 Sven Ruppert (sven.ruppert@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.rapidpm.microservice.optionals.metrics.performance;

import com.codahale.metrics.Histogram;
import com.codahale.metrics.MetricRegistry;
import com.codahale.metrics.Snapshot;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import org.rapidpm.ddi.DI;
import org.rapidpm.proxybuilder.core.metrics.RapidPMMetricsRegistry;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
import java.util.SortedMap;

@Path("/metrics/performance/histogramms")
public class Histogramms {

  public static final Type HISTORY_SNAPSHOT_LIST_TYPE = new TypeToken<List<HistogrammSnapshot>>() {
  }.getType();
  public static final Type STRING_SET_TYPE = new TypeToken<Set<String>>() {
  }.getType();

  public static final String LIST_ALL_HISTOGRAMMS = "listAllHistogramms";
  public static final String LIST_ALL_HISTOGRAMM_NAMES = "listAllHistogrammNames";
  public static final String LIST_ALL_ACTIVATED_METRICS = "listAllActivateMetrics";

  public static final String LIST_ONE_HISTOGRAMMS = "listOneHistogramm";
  public static final String REMOVE_ONE_HISTOGRAMMS = "removeOneHistogramm";

  public static final String QUERY_PARAM_HISTOGRAMM_NAME = "histogrammName";
  public static final String QUERY_PARAM_CLASS_FQ_NAME = "classFQN";
  public static final String QUERY_PARAM_PKG_NAME = "pkgFQN";

  public static final String ACTIVATE_METRICS_FOR_CLASS = "activateMetricsForClass";
  public static final String ACTIVATE_METRICS_FOR_PKG = "activateMetricsForPKG";

  public static final String DE_ACTIVATE_METRICS_FOR_CLASS = "deActivateMetricsForClass";
  public static final String DE_ACTIVATE_METRICS_FOR_PKG = "deActivateMetricsForPKG";
  public static final String OK = "OK";
  public static final String NOT_OK = "pkgName null or empty";

  @GET()
  @Path(LIST_ALL_HISTOGRAMMS)
  @Produces(MediaType.APPLICATION_JSON)
  public String listAll() {
    final SortedMap<String, Histogram> histogramMap = RapidPMMetricsRegistry.getInstance().getMetrics().getHistograms();
    final List<HistogrammSnapshot> histogrammSnapshots = new ArrayList<>();
    for (Entry<String, Histogram> entry : histogramMap.entrySet()) {
      final String key = entry.getKey();
      final Histogram histogram = entry.getValue();
      histogrammSnapshots.add(mapData(key, histogram));
    }
    return new Gson().toJson(histogrammSnapshots, HISTORY_SNAPSHOT_LIST_TYPE);
  }

  private HistogrammSnapshot mapData(final String key, final Histogram histogram) {
    final Snapshot histogramSnapshot = histogram.getSnapshot();
    return emptyHistogrammSnapshot(key)
        .histogramCount(histogram.getCount())
        .histogramSnapshot75thPercentile(histogramSnapshot.get75thPercentile())
        .histogramSnapshot95thPercentile(histogramSnapshot.get95thPercentile())
        .histogramSnapshot98thPercentile(histogramSnapshot.get98thPercentile())
        .histogramSnapshot99thPercentile(histogramSnapshot.get99thPercentile())
        .histogramSnapshot999thPercentile(histogramSnapshot.get999thPercentile())
        .histogramSnapshotMax(histogramSnapshot.getMax())
        .histogramSnapshotMean(histogramSnapshot.getMean())
        .histogramSnapshotMedian(histogramSnapshot.getMedian())
        .histogramSnapshotMin(histogramSnapshot.getMin())
        .histogramSnapshotStdDev(histogramSnapshot.getStdDev())
        .histogramSnapshotValues(histogramSnapshot.getValues());
  }

  private HistogrammSnapshot emptyHistogrammSnapshot(final String histogrammName) {
    return new HistogrammSnapshot().name(histogrammName);
  }

  @GET()
  @Path(LIST_ALL_HISTOGRAMM_NAMES)
  @Produces(MediaType.APPLICATION_JSON)
  public String listAllNames() {
    final SortedMap<String, Histogram> histogramMap = RapidPMMetricsRegistry.getInstance().getMetrics().getHistograms();
    return new Gson().toJson(histogramMap.keySet(), Set.class);
  }

  @GET()
  @Path(LIST_ONE_HISTOGRAMMS)
  @Produces(MediaType.APPLICATION_JSON)
  public String listOneHistogramm(@QueryParam(QUERY_PARAM_HISTOGRAMM_NAME) final String histogrammName) {
    final SortedMap<String, Histogram> histograms = RapidPMMetricsRegistry.getInstance().getMetrics().getHistograms();
    final HistogrammSnapshot histogrammSnapshot;
    if (histograms.containsKey(histogrammName)) {
      histogrammSnapshot = mapData(histogrammName, histograms.get(histogrammName));
    } else {
      histogrammSnapshot = emptyHistogrammSnapshot(histogrammName);
    }
    return new Gson().toJson(histogrammSnapshot, HistogrammSnapshot.class);
  }

  @GET()
  @Path(REMOVE_ONE_HISTOGRAMMS)
  @Produces(MediaType.APPLICATION_JSON)
  public String removeOneHistogramm(@QueryParam(QUERY_PARAM_HISTOGRAMM_NAME) final String histogrammName) {
    final MetricRegistry metricRegistry = RapidPMMetricsRegistry.getInstance().getMetrics();

    final SortedMap<String, Histogram> histograms = metricRegistry.getHistograms();

    final HistogrammSnapshot histogrammSnapshot;

    if (histograms.containsKey(histogrammName)) {
      histogrammSnapshot = mapData(histogrammName, histograms.get(histogrammName));
    } else {
      histogrammSnapshot = emptyHistogrammSnapshot(histogrammName);
    }

    metricRegistry.remove(histogrammName);
    return new Gson().toJson(histogrammSnapshot, HistogrammSnapshot.class);
  }

  @GET()
  @Path(LIST_ALL_ACTIVATED_METRICS)
  @Produces(MediaType.APPLICATION_JSON)
  public String listAllActivatedMetrics() {
    return new Gson().toJson(DI.listAllActivatedMetrics(), STRING_SET_TYPE);
  }

  //activate Metrics
  @GET()
  @Path(ACTIVATE_METRICS_FOR_CLASS)
  public String activateMetricsForClass(@QueryParam(QUERY_PARAM_CLASS_FQ_NAME) final String classFQN) {
    if (classFQN != null && !classFQN.isEmpty()) {
      try {
        final Class<?> aClass = Class.forName(classFQN);
        DI.activateMetrics(aClass);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return e.getMessage();
      }
    }
    return OK;
  }

  @GET()
  @Path(ACTIVATE_METRICS_FOR_PKG)
  @Produces(MediaType.TEXT_PLAIN)
  public String activateMetricsForPKG(@QueryParam(QUERY_PARAM_PKG_NAME) final String pkgName) {
    if (pkgName != null && !pkgName.isEmpty()) {
      DI.activateMetrics(pkgName);
      return OK;
    }
    return NOT_OK;
  }

  //deactivate Metrics
  @GET()
  @Path(DE_ACTIVATE_METRICS_FOR_CLASS)
  public String deActivateMetricsForClass(@QueryParam(QUERY_PARAM_CLASS_FQ_NAME) final String classFQN) {
    if (classFQN != null && !classFQN.isEmpty()) {
      try {
        final Class<?> aClass = Class.forName(classFQN);
        DI.deActivateMetrics(aClass);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
        return e.getMessage();
      }
      return OK;
    }
    return NOT_OK;
  }

  @GET()
  @Path(DE_ACTIVATE_METRICS_FOR_PKG)
  public String deActivateMetricsForPKG(@QueryParam(QUERY_PARAM_PKG_NAME) final String pkgName) {
    if (pkgName != null && !pkgName.isEmpty()) {
      DI.deActivateMetrics(pkgName);
      return OK;
    }
    return NOT_OK;
  }

}


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.kb;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.tcas.Annotation;

/** A superclass for EntityMention and RelationMention.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class ConceptMention extends Annotation {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(ConceptMention.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected ConceptMention() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public ConceptMention(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public ConceptMention(JCas jcas) {
    super(jcas);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   * @param begin offset to the begin spot in the SofA
   * @param end offset to the end spot in the SofA
  */
  public ConceptMention(JCas jcas, int begin, int end) {
    super(jcas);
    setBegin(begin);
    setEnd(end);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: concept

  /** getter for concept - gets The abstract concept that the text span conveys.
   * @generated
   * @return value of the feature
   */
  public Concept getConcept() {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    return (Concept)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_concept)));}

  /** setter for concept - sets The abstract concept that the text span conveys.
   * @generated
   * @param v value to set into the feature
   */
  public void setConcept(Concept v) {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    jcasType.ll_cas.ll_setRefValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_concept, jcasType.ll_cas.ll_getFSRef(v));}

  //*--------------*
  //* Feature: matchedName

  /** getter for matchedName - gets A synonym of the concept that best matches the concept mention (similar to conceptMatched in metamap).
   * @generated
   * @return value of the feature
   */
  public String getMatchedName() {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_matchedName == null)
      jcasType.jcas.throwFeatMissing("matchedName", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    return jcasType.ll_cas.ll_getStringValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_matchedName);}

  /** setter for matchedName - sets A synonym of the concept that best matches the concept mention (similar to conceptMatched in metamap).
   * @generated
   * @param v value to set into the feature
   */
  public void setMatchedName(String v) {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_matchedName == null)
      jcasType.jcas.throwFeatMissing("matchedName", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    jcasType.ll_cas.ll_setStringValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_matchedName, v);}

  //*--------------*
  //* Feature: score

  /** getter for score - gets The confidence score that the concept mention matches the concept.
   * @generated
   * @return value of the feature
   */
  public double getScore() {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    return jcasType.ll_cas.ll_getDoubleValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_score);}

  /** setter for score - sets The confidence score that the concept mention matches the concept.
   * @generated
   * @param v value to set into the feature
   */
  public void setScore(double v) {
    if (ConceptMention_Type.featOkTst && ((ConceptMention_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.kb.ConceptMention");
    jcasType.ll_cas.ll_setDoubleValue(addr, ((ConceptMention_Type)jcasType).casFeatCode_score, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.answer;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.tcas.Annotation;

/** Annotates a span of text identified as a candidate answer.
 * Updated by JCasGen Sun Apr 19 19:46:49 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class CandidateAnswerOccurrence extends Annotation {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(CandidateAnswerOccurrence.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected CandidateAnswerOccurrence() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public CandidateAnswerOccurrence(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public CandidateAnswerOccurrence(JCas jcas) {
    super(jcas);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   * @param begin offset to the begin spot in the SofA
   * @param end offset to the end spot in the SofA
  */
  public CandidateAnswerOccurrence(JCas jcas, int begin, int end) {
    super(jcas);
    setBegin(begin);
    setEnd(end);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: text

  /** getter for text - gets The candidate answer string.
   * @generated
   * @return value of the feature
   */
  public String getText() {
    if (CandidateAnswerOccurrence_Type.featOkTst && ((CandidateAnswerOccurrence_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerOccurrence");
    return jcasType.ll_cas.ll_getStringValue(addr, ((CandidateAnswerOccurrence_Type)jcasType).casFeatCode_text);}

  /** setter for text - sets The candidate answer string.
   * @generated
   * @param v value to set into the feature
   */
  public void setText(String v) {
    if (CandidateAnswerOccurrence_Type.featOkTst && ((CandidateAnswerOccurrence_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerOccurrence");
    jcasType.ll_cas.ll_setStringValue(addr, ((CandidateAnswerOccurrence_Type)jcasType).casFeatCode_text, v);}

  //*--------------*
  //* Feature: mentionType

  /** getter for mentionType - gets The manner in which covered text refers to some entity, e.g. NAME, NOMINAL, PRONOUN
   * @generated
   * @return value of the feature
   */
  public String getMentionType() {
    if (CandidateAnswerOccurrence_Type.featOkTst && ((CandidateAnswerOccurrence_Type)jcasType).casFeat_mentionType == null)
      jcasType.jcas.throwFeatMissing("mentionType", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerOccurrence");
    return jcasType.ll_cas.ll_getStringValue(addr, ((CandidateAnswerOccurrence_Type)jcasType).casFeatCode_mentionType);}

  /** setter for mentionType - sets The manner in which covered text refers to some entity, e.g. NAME, NOMINAL, PRONOUN
   * @generated
   * @param v value to set into the feature
   */
  public void setMentionType(String v) {
    if (CandidateAnswerOccurrence_Type.featOkTst && ((CandidateAnswerOccurrence_Type)jcasType).casFeat_mentionType == null)
      jcasType.jcas.throwFeatMissing("mentionType", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerOccurrence");
    jcasType.ll_cas.ll_setStringValue(addr, ((CandidateAnswerOccurrence_Type)jcasType).casFeatCode_mentionType, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.kb;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.TOP;

/** The type/category the concept belongs to.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class ConceptType extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(ConceptType.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected ConceptType() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public ConceptType(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public ConceptType(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: id

  /** getter for id - gets The id of the concept type.
   * @generated
   * @return value of the feature
   */
  public String getId() {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_id == null)
      jcasType.jcas.throwFeatMissing("id", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    return jcasType.ll_cas.ll_getStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_id);}

  /** setter for id - sets The id of the concept type.
   * @generated
   * @param v value to set into the feature
   */
  public void setId(String v) {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_id == null)
      jcasType.jcas.throwFeatMissing("id", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    jcasType.ll_cas.ll_setStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_id, v);}

  //*--------------*
  //* Feature: name

  /** getter for name - gets A human readable concept label.
   * @generated
   * @return value of the feature
   */
  public String getName() {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_name == null)
      jcasType.jcas.throwFeatMissing("name", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    return jcasType.ll_cas.ll_getStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_name);}

  /** setter for name - sets A human readable concept label.
   * @generated
   * @param v value to set into the feature
   */
  public void setName(String v) {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_name == null)
      jcasType.jcas.throwFeatMissing("name", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    jcasType.ll_cas.ll_setStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_name, v);}

  //*--------------*
  //* Feature: abbreviation

  /** getter for abbreviation - gets The abbreviation of the name label.
   * @generated
   * @return value of the feature
   */
  public String getAbbreviation() {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_abbreviation == null)
      jcasType.jcas.throwFeatMissing("abbreviation", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    return jcasType.ll_cas.ll_getStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_abbreviation);}

  /** setter for abbreviation - sets The abbreviation of the name label.
   * @generated
   * @param v value to set into the feature
   */
  public void setAbbreviation(String v) {
    if (ConceptType_Type.featOkTst && ((ConceptType_Type)jcasType).casFeat_abbreviation == null)
      jcasType.jcas.throwFeatMissing("abbreviation", "edu.cmu.lti.oaqa.type.kb.ConceptType");
    jcasType.ll_cas.ll_setStringValue(addr, ((ConceptType_Type)jcasType).casFeatCode_abbreviation, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import edu.cmu.lti.oaqa.type.kb.Concept;

/** A search result from an ontology.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class ConceptSearchResult extends AnswerSearchResult {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(ConceptSearchResult.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected ConceptSearchResult() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public ConceptSearchResult(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public ConceptSearchResult(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: concept

  /** getter for concept - gets The relevant concept searched in the ontology.
   * @generated
   * @return value of the feature
   */
  public Concept getConcept() {
    if (ConceptSearchResult_Type.featOkTst && ((ConceptSearchResult_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.retrieval.ConceptSearchResult");
    return (Concept)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((ConceptSearchResult_Type)jcasType).casFeatCode_concept)));}

  /** setter for concept - sets The relevant concept searched in the ontology.
   * @generated
   * @param v value to set into the feature
   */
  public void setConcept(Concept v) {
    if (ConceptSearchResult_Type.featOkTst && ((ConceptSearchResult_Type)jcasType).casFeat_concept == null)
      jcasType.jcas.throwFeatMissing("concept", "edu.cmu.lti.oaqa.type.retrieval.ConceptSearchResult");
    jcasType.ll_cas.ll_setRefValue(addr, ((ConceptSearchResult_Type)jcasType).casFeatCode_concept, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.answer;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.FSList;
import org.apache.uima.jcas.cas.TOP;

/** An exact answer text generated by the QA system.
 * Updated by JCasGen Sun Apr 19 19:46:49 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class Answer extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(Answer.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected Answer() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public Answer(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public Answer(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: text

  /** getter for text - gets The actual answer string.
   * @generated
   * @return value of the feature
   */
  public String getText() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Answer");
    return jcasType.ll_cas.ll_getStringValue(addr, ((Answer_Type)jcasType).casFeatCode_text);}

  /** setter for text - sets The actual answer string.
   * @generated
   * @param v value to set into the feature
   */
  public void setText(String v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setStringValue(addr, ((Answer_Type)jcasType).casFeatCode_text, v);}

  //*--------------*
  //* Feature: score

  /** getter for score - gets The score associated with the answer.
   * @generated
   * @return value of the feature
   */
  public double getScore() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Answer");
    return jcasType.ll_cas.ll_getDoubleValue(addr, ((Answer_Type)jcasType).casFeatCode_score);}

  /** setter for score - sets The score associated with the answer.
   * @generated
   * @param v value to set into the feature
   */
  public void setScore(double v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_score == null)
      jcasType.jcas.throwFeatMissing("score", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setDoubleValue(addr, ((Answer_Type)jcasType).casFeatCode_score, v);}

  //*--------------*
  //* Feature: variants

  /** getter for variants - gets List of candidate answer variants that were merged into this final answer.
   * @generated
   * @return value of the feature
   */
  public FSList getVariants() {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Answer");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((Answer_Type)jcasType).casFeatCode_variants)));}

  /** setter for variants - sets List of candidate answer variants that were merged into this final answer.
   * @generated
   * @param v value to set into the feature
   */
  public void setVariants(FSList v) {
    if (Answer_Type.featOkTst && ((Answer_Type)jcasType).casFeat_variants == null)
      jcasType.jcas.throwFeatMissing("variants", "edu.cmu.lti.oaqa.type.answer.Answer");
    jcasType.ll_cas.ll_setRefValue(addr, ((Answer_Type)jcasType).casFeatCode_variants, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.jcas.cas.StringList;

/** A query concept in the abstract search query model.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class QueryConcept extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(QueryConcept.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected QueryConcept() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public QueryConcept(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public QueryConcept(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: namedEntityTypes

  /** getter for namedEntityTypes - gets List of Named Entity types associated with this concept.
   * @generated
   * @return value of the feature
   */
  public StringList getNamedEntityTypes() {
    if (QueryConcept_Type.featOkTst && ((QueryConcept_Type)jcasType).casFeat_namedEntityTypes == null)
      jcasType.jcas.throwFeatMissing("namedEntityTypes", "edu.cmu.lti.oaqa.type.retrieval.QueryConcept");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((QueryConcept_Type)jcasType).casFeatCode_namedEntityTypes)));}

  /** setter for namedEntityTypes - sets List of Named Entity types associated with this concept.
   * @generated
   * @param v value to set into the feature
   */
  public void setNamedEntityTypes(StringList v) {
    if (QueryConcept_Type.featOkTst && ((QueryConcept_Type)jcasType).casFeat_namedEntityTypes == null)
      jcasType.jcas.throwFeatMissing("namedEntityTypes", "edu.cmu.lti.oaqa.type.retrieval.QueryConcept");
    jcasType.ll_cas.ll_setRefValue(addr, ((QueryConcept_Type)jcasType).casFeatCode_namedEntityTypes, jcasType.ll_cas.ll_getFSRef(v));}

  //*--------------*
  //* Feature: conceptType

  /** getter for conceptType - gets The type of this concept.
   * @generated
   * @return value of the feature
   */
  public String getConceptType() {
    if (QueryConcept_Type.featOkTst && ((QueryConcept_Type)jcasType).casFeat_conceptType == null)
      jcasType.jcas.throwFeatMissing("conceptType", "edu.cmu.lti.oaqa.type.retrieval.QueryConcept");
    return jcasType.ll_cas.ll_getStringValue(addr, ((QueryConcept_Type)jcasType).casFeatCode_conceptType);}

  /** setter for conceptType - sets The type of this concept.
   * @generated
   * @param v value to set into the feature
   */
  public void setConceptType(String v) {
    if (QueryConcept_Type.featOkTst && ((QueryConcept_Type)jcasType).casFeat_conceptType == null)
      jcasType.jcas.throwFeatMissing("conceptType", "edu.cmu.lti.oaqa.type.retrieval.QueryConcept");
    jcasType.ll_cas.ll_setStringValue(addr, ((QueryConcept_Type)jcasType).casFeatCode_conceptType, v);}
  }


/**
 * Copyright © 2013 Sven Ruppert (sven.ruppert@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.rapidpm.microservice;

import static io.undertow.servlet.Servlets.defaultContainer;
import static io.undertow.servlet.Servlets.deployment;
import static io.undertow.servlet.Servlets.servlet;
import static org.rapidpm.microservice.ServletContainerFunctions.addShiroFilter;
import static org.rapidpm.microservice.ServletContainerFunctions.addStagemonitor;

import java.util.EventListener;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;

import org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer;
import org.jboss.resteasy.spi.ResourceFactory;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.rapidpm.ddi.DI;
import org.rapidpm.ddi.reflections.ReflectionUtils;
import org.rapidpm.dependencies.core.logger.Logger;
import org.rapidpm.dependencies.core.logger.LoggingService;
import org.rapidpm.microservice.optionals.ActiveUrlsDetector;
import org.rapidpm.microservice.optionals.header.ActiveUrlPrinter;
import org.rapidpm.microservice.optionals.header.HeaderScreenPrinter;
import org.rapidpm.microservice.rest.JaxRsActivator;
import org.rapidpm.microservice.rest.ddi.DdiInjectorFactory;
import org.rapidpm.microservice.rest.ddi.PoJoDDIRessourceFactory;
import org.rapidpm.microservice.servlet.ServletInstanceFactory;
import io.undertow.Handlers;
import io.undertow.Undertow;
import io.undertow.Undertow.Builder;
import io.undertow.UndertowOptions;
import io.undertow.server.HttpHandler;
import io.undertow.server.handlers.PathHandler;
import io.undertow.servlet.api.DeploymentInfo;
import io.undertow.servlet.api.DeploymentManager;
import io.undertow.servlet.api.ListenerInfo;
import io.undertow.servlet.api.ServletContainer;
import io.undertow.servlet.api.ServletInfo;
import io.undertow.websockets.jsr.WebSocketDeploymentInfo;

/**
 * Copyright (C) 2010 RapidPM
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * <p>
 * Created by RapidPM - Team on 08.08.16.
 */
public class MainUndertow {

  private MainUndertow() {
  }

  private static final LoggingService LOGGER = Logger.getLogger(MainUndertow.class);

  public static final String DEFAULT_FILTER_MAPPING       = "/*";
  public static final String DEFAULT_SHIRO_FILTER_NAME    = "ShiroFilter";
  public static final String MYAPP                        = "/microservice";
  public static final String MYAPP_VAADIN                 = "/vaadin";
  public static final String CONTEXT_PATH_REST            = "/rest";
  public static final int    DEFAULT_REST_PORT            = 7081;
  public static final int    DEFAULT_SERVLET_PORT         = 7080;
  public static final String REST_PORT_PROPERTY           = "org.rapidpm.microservice.rest.port";
  public static final String REST_HOST_PROPERTY           = "org.rapidpm.microservice.rest.host";
  public static final String SERVLET_PORT_PROPERTY        = "org.rapidpm.microservice.servlet.port";
  public static final String SERVLET_HOST_PROPERTY        = "org.rapidpm.microservice.servlet.host";
  public static final String SHIRO_ACTIVE_PROPERTY        = "org.rapidpm.microservice.security.shiro.active";
  public static final String STAGEMONITOR_ACTIVE_PROPERTY = "org.rapidpm.microservice.security.stagemonitor.active";

  private static final String RESTEASY_PORT_PROPERTY = "org.jboss.resteasy.port";
  private static final String RESTEASY_HOST_PROPERTY = "org.jboss.resteasy.host";

  private static UndertowJaxrsServer jaxrsServer;
  private static Undertow            undertowServer;

  private static Optional<String[]> cliArguments; //TODO switch to Result

  public static void deploy() {
    deploy(Optional.empty());
  }

  public static void deploy(Optional<String[]> args) {
    cliArguments = args;
    //executeStartupActions(args);
    //DI.bootstrap(); // per config steuern

    final Builder builder = Undertow.builder() //TODO
                                    .setDirectBuffers(true)
                                    .setServerOption(UndertowOptions.ENABLE_HTTP2 , true);

    // deploy servlets
    DeploymentInfo deploymentInfo = createServletDeploymentInfos();
    final boolean anyServlets = ! deploymentInfo.getServlets().isEmpty();
    if (anyServlets) {
      try {
        deployServlets(builder , deploymentInfo);
      } catch (ServletException e) {
        e.printStackTrace();
        LOGGER.warning("deploy Servlets " , e);
      }
    }

    final JaxRsActivator jaxRsActivator = new JaxRsActivator();
    if (jaxRsActivator.somethingToDeploy()) {
      deployRestResources(builder , jaxRsActivator);
    } else {
      undertowServer = builder.build();
      undertowServer.start();
    }

    new HeaderScreenPrinter().printOnScreen();
    new ActiveUrlPrinter().printActiveURLs(new ActiveUrlsDetector().detectUrls());
  }

  //TODO extend for a Vaadin App Version
  private static DeploymentInfo createServletDeploymentInfos() {

    final Set<Class<?>> typesAnnotatedWith = DI.getTypesAnnotatedWith(WebServlet.class , true);

    final List<ServletInfo> servletInfos = typesAnnotatedWith
        .stream()
        .filter(s -> new ReflectionUtils().checkInterface(s , HttpServlet.class))
        .map(c -> {
          Class<HttpServlet> servletClass = (Class<HttpServlet>) c;
          final ServletInfo servletInfo = servlet(c.getSimpleName() , servletClass , new ServletInstanceFactory<>(servletClass));
          if (c.isAnnotationPresent(WebInitParam.class)) {
            final WebInitParam[] annotationsByType = c.getAnnotationsByType(WebInitParam.class);
            for (WebInitParam webInitParam : annotationsByType) {
              final String value = webInitParam.value();
              final String name = webInitParam.name();
              servletInfo.addInitParam(name , value);
            }
          }
          final WebServlet annotation = c.getAnnotation(WebServlet.class);
          final String[] urlPatterns = annotation.urlPatterns();
          for (String urlPattern : urlPatterns) {
            servletInfo.addMapping(urlPattern);
          }
          servletInfo.setAsyncSupported(annotation.asyncSupported());
          return servletInfo;
        })
        .filter(servletInfo -> ! servletInfo.getMappings().isEmpty())
        .collect(Collectors.toList());

    final Set<Class<?>> weblisteners = DI.getTypesAnnotatedWith(WebListener.class);
    final List<ListenerInfo> listenerInfos = weblisteners.stream()
                                                         .map(c -> new ListenerInfo((Class<? extends EventListener>) c))
                                                         .collect(Collectors.toList());

    final DeploymentInfo deploymentInfo = deployment()
        .setClassLoader(Main.class.getClassLoader())
        .setContextPath(MYAPP)
        .setDeploymentName("ROOT" + ".war")
        .setDefaultEncoding("UTF-8");

    final Boolean shiroActive = Boolean.valueOf(System.getProperty(SHIRO_ACTIVE_PROPERTY , "false"));
    final Boolean stagemonitorActive = Boolean.valueOf(System.getProperty(STAGEMONITOR_ACTIVE_PROPERTY , "false"));
    if (shiroActive) addShiroFilter().apply(deploymentInfo , DEFAULT_SHIRO_FILTER_NAME , DEFAULT_FILTER_MAPPING);
    if (stagemonitorActive) addStagemonitor().apply(deploymentInfo);

    return deploymentInfo
        .addListeners(listenerInfos)
        .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME , new WebSocketDeploymentInfo())
        .addServlets(servletInfos);
  }

  static void deployServlets(final Builder builder , final DeploymentInfo deploymentInfo) throws ServletException {
    final ServletContainer servletContainer = defaultContainer();
    final DeploymentManager manager = servletContainer.addDeployment(deploymentInfo);
    manager.deploy();
    final HttpHandler servletHandler = manager.start();
    final PathHandler pathServlet = Handlers
        .path(Handlers.redirect(MYAPP))
        .addPrefixPath(MYAPP , servletHandler);
    final String realServletPort = System.getProperty(SERVLET_PORT_PROPERTY , DEFAULT_SERVLET_PORT + "");
    final String realServletHost = System.getProperty(SERVLET_HOST_PROPERTY , Main.DEFAULT_HOST);

    builder.addHttpListener(Integer.parseInt(realServletPort) , realServletHost , pathServlet);
  }

  static void deployRestResources(final Builder builder , final JaxRsActivator jaxRsActivator) {
    final String realRestPort = System.getProperty(REST_PORT_PROPERTY , DEFAULT_REST_PORT + "");
    final String realRestHost = System.getProperty(REST_HOST_PROPERTY , Main.DEFAULT_HOST);

    System.setProperty(RESTEASY_PORT_PROPERTY , realRestPort);
    System.setProperty(RESTEASY_HOST_PROPERTY , realRestHost);

    builder.addHttpListener(Integer.parseInt(realRestPort) , realRestHost);
    jaxrsServer = new UndertowJaxrsServer().start(builder);
    final ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplication(jaxRsActivator);
//      deployment.setAsyncJobServiceEnabled(false);
    deployment.setInjectorFactoryClass(DdiInjectorFactory.class.getCanonicalName());

    // add resourceFactories for dedicated classes

    final List<ResourceFactory> collect = jaxRsActivator
        .getInterfacesWithPathAnnotation()
        .stream()
        .map(PoJoDDIRessourceFactory::new)
        .collect(Collectors.toList());

    deployment.setResourceFactories(collect);

    jaxrsServer.deploy(jaxrsServer.undertowDeployment(deployment)
                                  .setDeploymentName("Rest")
                                  .setContextPath(CONTEXT_PATH_REST)
                                  .setClassLoader(Main.class.getClassLoader()));
  }

  public static void stop() {
    if (jaxrsServer != null) {
      if (new JaxRsActivator().somethingToDeploy())
        try {
          jaxrsServer.stop();
        } catch (Exception e) {
          LOGGER.warning("jaxrsServer.stop()" , e);
        }
    } else if (undertowServer != null) {
      try {
        undertowServer.stop();
      } catch (Exception e) {
        LOGGER.warning("undertowServer.stop()" , e);
      }
    }
  }
}


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.answer;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.FSList;
import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.jcas.cas.StringList;

/** A variant of a candidate answer. A variant may have multiple occurrences, all of which are collected in a variant object.
 * Updated by JCasGen Sun Apr 19 19:46:49 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class CandidateAnswerVariant extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(CandidateAnswerVariant.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected CandidateAnswerVariant() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public CandidateAnswerVariant(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public CandidateAnswerVariant(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: occurrences

  /** getter for occurrences - gets The occurrences of this variant.
   * @generated
   * @return value of the feature
   */
  public FSList getOccurrences() {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_occurrences == null)
      jcasType.jcas.throwFeatMissing("occurrences", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_occurrences)));}

  /** setter for occurrences - sets The occurrences of this variant.
   * @generated
   * @param v value to set into the feature
   */
  public void setOccurrences(FSList v) {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_occurrences == null)
      jcasType.jcas.throwFeatMissing("occurrences", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    jcasType.ll_cas.ll_setRefValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_occurrences, jcasType.ll_cas.ll_getFSRef(v));}

  //*--------------*
  //* Feature: names

  /** getter for names - gets Names for a given candidate answer variant, e.g. Tandy, Tandy Inc. for candidate answer Variant Tandy Incorporated.
   * @generated
   * @return value of the feature
   */
  public StringList getNames() {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_names == null)
      jcasType.jcas.throwFeatMissing("names", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_names)));}

  /** setter for names - sets Names for a given candidate answer variant, e.g. Tandy, Tandy Inc. for candidate answer Variant Tandy Incorporated.
   * @generated
   * @param v value to set into the feature
   */
  public void setNames(StringList v) {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_names == null)
      jcasType.jcas.throwFeatMissing("names", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    jcasType.ll_cas.ll_setRefValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_names, jcasType.ll_cas.ll_getFSRef(v));}

  //*--------------*
  //* Feature: docId

  /** getter for docId - gets The unique id of the document (if any) from which this candidate answer was generated.
   * @generated
   * @return value of the feature
   */
  public String getDocId() {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    return jcasType.ll_cas.ll_getStringValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_docId);}

  /** setter for docId - sets The unique id of the document (if any) from which this candidate answer was generated.
   * @generated
   * @param v value to set into the feature
   */
  public void setDocId(String v) {
    if (CandidateAnswerVariant_Type.featOkTst && ((CandidateAnswerVariant_Type)jcasType).casFeat_docId == null)
      jcasType.jcas.throwFeatMissing("docId", "edu.cmu.lti.oaqa.type.answer.CandidateAnswerVariant");
    jcasType.ll_cas.ll_setStringValue(addr, ((CandidateAnswerVariant_Type)jcasType).casFeatCode_docId, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.FSList;
import org.apache.uima.jcas.cas.TOP;

/** An abstract search query for the question that represents query concepts and query operators over those concepts.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class AbstractQuery extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(AbstractQuery.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected AbstractQuery() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public AbstractQuery(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public AbstractQuery(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: concepts

  /** getter for concepts - gets The list of query concepts that make up this abstract query. The list is ordered.
   * @generated
   * @return value of the feature
   */
  public FSList getConcepts() {
    if (AbstractQuery_Type.featOkTst && ((AbstractQuery_Type)jcasType).casFeat_concepts == null)
      jcasType.jcas.throwFeatMissing("concepts", "edu.cmu.lti.oaqa.type.retrieval.AbstractQuery");
    return (FSList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((AbstractQuery_Type)jcasType).casFeatCode_concepts)));}

  /** setter for concepts - sets The list of query concepts that make up this abstract query. The list is ordered.
   * @generated
   * @param v value to set into the feature
   */
  public void setConcepts(FSList v) {
    if (AbstractQuery_Type.featOkTst && ((AbstractQuery_Type)jcasType).casFeat_concepts == null)
      jcasType.jcas.throwFeatMissing("concepts", "edu.cmu.lti.oaqa.type.retrieval.AbstractQuery");
    jcasType.ll_cas.ll_setRefValue(addr, ((AbstractQuery_Type)jcasType).casFeatCode_concepts, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

/** A primitive query concept represented by a single text string
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class AtomicQueryConcept extends QueryConcept {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(AtomicQueryConcept.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected AtomicQueryConcept() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public AtomicQueryConcept(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public AtomicQueryConcept(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: text

  /** getter for text - gets The keyword text.
   * @generated
   * @return value of the feature
   */
  public String getText() {
    if (AtomicQueryConcept_Type.featOkTst && ((AtomicQueryConcept_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.retrieval.AtomicQueryConcept");
    return jcasType.ll_cas.ll_getStringValue(addr, ((AtomicQueryConcept_Type)jcasType).casFeatCode_text);}

  /** setter for text - sets The keyword text.
   * @generated
   * @param v value to set into the feature
   */
  public void setText(String v) {
    if (AtomicQueryConcept_Type.featOkTst && ((AtomicQueryConcept_Type)jcasType).casFeat_text == null)
      jcasType.jcas.throwFeatMissing("text", "edu.cmu.lti.oaqa.type.retrieval.AtomicQueryConcept");
    jcasType.ll_cas.ll_setStringValue(addr, ((AtomicQueryConcept_Type)jcasType).casFeatCode_text, v);}

  //*--------------*
  //* Feature: originalText

  /** getter for originalText - gets The lexical string in the question.
   * @generated
   * @return value of the feature
   */
  public String getOriginalText() {
    if (AtomicQueryConcept_Type.featOkTst && ((AtomicQueryConcept_Type)jcasType).casFeat_originalText == null)
      jcasType.jcas.throwFeatMissing("originalText", "edu.cmu.lti.oaqa.type.retrieval.AtomicQueryConcept");
    return jcasType.ll_cas.ll_getStringValue(addr, ((AtomicQueryConcept_Type)jcasType).casFeatCode_originalText);}

  /** setter for originalText - sets The lexical string in the question.
   * @generated
   * @param v value to set into the feature
   */
  public void setOriginalText(String v) {
    if (AtomicQueryConcept_Type.featOkTst && ((AtomicQueryConcept_Type)jcasType).casFeat_originalText == null)
      jcasType.jcas.throwFeatMissing("originalText", "edu.cmu.lti.oaqa.type.retrieval.AtomicQueryConcept");
    jcasType.ll_cas.ll_setStringValue(addr, ((AtomicQueryConcept_Type)jcasType).casFeatCode_originalText, v);}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.retrieval;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.cas.TOP;
import org.apache.uima.jcas.cas.StringList;

/** A query operator in the abstract search query model.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class QueryOperator extends TOP {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(QueryOperator.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected QueryOperator() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public QueryOperator(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public QueryOperator(JCas jcas) {
    super(jcas);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: name

  /** getter for name - gets The name (kind) of the operator.
   * @generated
   * @return value of the feature
   */
  public String getName() {
    if (QueryOperator_Type.featOkTst && ((QueryOperator_Type)jcasType).casFeat_name == null)
      jcasType.jcas.throwFeatMissing("name", "edu.cmu.lti.oaqa.type.retrieval.QueryOperator");
    return jcasType.ll_cas.ll_getStringValue(addr, ((QueryOperator_Type)jcasType).casFeatCode_name);}

  /** setter for name - sets The name (kind) of the operator.
   * @generated
   * @param v value to set into the feature
   */
  public void setName(String v) {
    if (QueryOperator_Type.featOkTst && ((QueryOperator_Type)jcasType).casFeat_name == null)
      jcasType.jcas.throwFeatMissing("name", "edu.cmu.lti.oaqa.type.retrieval.QueryOperator");
    jcasType.ll_cas.ll_setStringValue(addr, ((QueryOperator_Type)jcasType).casFeatCode_name, v);}

  //*--------------*
  //* Feature: args

  /** getter for args - gets The arguments for the operator.
   * @generated
   * @return value of the feature
   */
  public StringList getArgs() {
    if (QueryOperator_Type.featOkTst && ((QueryOperator_Type)jcasType).casFeat_args == null)
      jcasType.jcas.throwFeatMissing("args", "edu.cmu.lti.oaqa.type.retrieval.QueryOperator");
    return (StringList)(jcasType.ll_cas.ll_getFSForRef(jcasType.ll_cas.ll_getRefValue(addr, ((QueryOperator_Type)jcasType).casFeatCode_args)));}

  /** setter for args - sets The arguments for the operator.
   * @generated
   * @param v value to set into the feature
   */
  public void setArgs(StringList v) {
    if (QueryOperator_Type.featOkTst && ((QueryOperator_Type)jcasType).casFeat_args == null)
      jcasType.jcas.throwFeatMissing("args", "edu.cmu.lti.oaqa.type.retrieval.QueryOperator");
    jcasType.ll_cas.ll_setRefValue(addr, ((QueryOperator_Type)jcasType).casFeatCode_args, jcasType.ll_cas.ll_getFSRef(v));}
  }


/* First created by JCasGen Sat Apr 11 19:49:33 EDT 2015 */
package edu.cmu.lti.oaqa.type.nlp;

import org.apache.uima.jcas.JCas;
import org.apache.uima.jcas.JCasRegistry;
import org.apache.uima.jcas.cas.TOP_Type;

import org.apache.uima.jcas.tcas.Annotation;

/** A semantic role label.
 * Updated by JCasGen Sun Apr 19 19:46:50 EDT 2015
 * XML source: /home/yangzi/QA/baseqa/src/main/resources/baseqa/type/OAQATypes.xml
 * @generated */
public class SemanticRole extends Annotation {
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int typeIndexID = JCasRegistry.register(SemanticRole.class);
  /** @generated
   * @ordered
   */
  @SuppressWarnings ("hiding")
  public final static int type = typeIndexID;
  /** @generated
   * @return index of the type
   */
  @Override
  public              int getTypeIndexID() {return typeIndexID;}

  /** Never called.  Disable default constructor
   * @generated */
  protected SemanticRole() {/* intentionally empty block */}

  /** Internal - constructor used by generator
   * @generated
   * @param addr low level Feature Structure reference
   * @param type the type of this Feature Structure
   */
  public SemanticRole(int addr, TOP_Type type) {
    super(addr, type);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   */
  public SemanticRole(JCas jcas) {
    super(jcas);
    readObject();
  }

  /** @generated
   * @param jcas JCas to which this Feature Structure belongs
   * @param begin offset to the begin spot in the SofA
   * @param end offset to the end spot in the SofA
  */
  public SemanticRole(JCas jcas, int begin, int end) {
    super(jcas);
    setBegin(begin);
    setEnd(end);
    readObject();
  }

  /**
   * <!-- begin-user-doc -->
   * Write your own initialization here
   * <!-- end-user-doc -->
   *
   * @generated modifiable
   */
  private void readObject() {/*default - does nothing empty block */}

  //*--------------*
  //* Feature: label

  /** getter for label - gets The semantic role label.
   * @generated
   * @return value of the feature
   */
  public String getLabel() {
    if (SemanticRole_Type.featOkTst && ((SemanticRole_Type)jcasType).casFeat_label == null)
      jcasType.jcas.throwFeatMissing("label", "edu.cmu.lti.oaqa.type.nlp.SemanticRole");
    return jcasType.ll_cas.ll_getStringValue(addr, ((SemanticRole_Type)jcasType).casFeatCode_label);}

  /** setter for label - sets The semantic role label.
   * @generated
   * @param v value to set into the feature
   */
  public void setLabel(String v) {
    if (SemanticRole_Type.featOkTst && ((SemanticRole_Type)jcasType).casFeat_label == null)
      jcasType.jcas.throwFeatMissing("label", "edu.cmu.lti.oaqa.type.nlp.SemanticRole");
    jcasType.ll_cas.ll_setStringValue(addr, ((SemanticRole_Type)jcasType).casFeatCode_label, v);}
  }


package com.bah.lucene.blockcache;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import java.util.concurrent.atomic.AtomicLongArray;

import org.apache.lucene.util.OpenBitSet;

public class BlockLocks {

  private AtomicLongArray bits;
  private int wlen;

  public BlockLocks(long numBits) {
    int length = OpenBitSet.bits2words(numBits);
    bits = new AtomicLongArray(length);
    wlen = length;
  }

  /**
   * Find the next clear bit in the bit set.
   *
   * @param index
   * @return
   */
  public int nextClearBit(int index) {
    int i = index >> 6;
    if (i >= wlen)
      return -1;
    int subIndex = index & 0x3f; // index within the word
    long word = ~bits.get(i) >> subIndex; // skip all the bits to the right of
                                          // index
    if (word != 0) {
      return (i << 6) + subIndex + Long.numberOfTrailingZeros(word);
    }
    while (++i < wlen) {
      word = ~bits.get(i);
      if (word != 0) {
        return (i << 6) + Long.numberOfTrailingZeros(word);
      }
    }
    return -1;
  }

  /**
   * Thread safe set operation that will set the bit if and only if the bit was
   * not previously set.
   *
   * @param index
   *          the index position to set.
   * @return returns true if the bit was set and false if it was already set.
   */
  public boolean set(int index) {
    int wordNum = index >> 6; // div 64
    int bit = index & 0x3f; // mod 64
    long bitmask = 1L << bit;
    long word, oword;
    do {
      word = bits.get(wordNum);
      // if set another thread stole the lock
      if ((word & bitmask) != 0) {
        return false;
      }
      oword = word;
      word |= bitmask;
    } while (!bits.compareAndSet(wordNum, oword, word));
    return true;
  }

  public void clear(int index) {
    int wordNum = index >> 6;
    int bit = index & 0x03f;
    long bitmask = 1L << bit;
    long word, oword;
    do {
      word = bits.get(wordNum);
      oword = word;
      word &= ~bitmask;
    } while (!bits.compareAndSet(wordNum, oword, word));
  }
}


package me.zzp.ar.sql;

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import me.zzp.util.Seq;

/**
 * 实现生成insert、update、delete和select的语句的方法。
 * 由子类自行实现如何填充数据。
 *
 * @since 1.0
 * @author redraiment
 */
public abstract class AbstractSqlBuilder implements SqlBuilder {
  protected static enum Mode {
    Select,
    Insert,
    Update,
    Delete
  }

  protected Mode mode;
  protected Deque<String> fields;
  protected Deque<String> tables;
  protected Deque<String> conditions;
  protected Deque<String> groups;
  protected Deque<String> having;
  protected Deque<String> orders;
  protected int limit;
  protected int offset;

  protected SqlBuilder start(Mode mode) {
    this.mode = mode;
    fields = new LinkedList<>();
    tables = new LinkedList<>();
    conditions = new LinkedList<>();
    groups = new LinkedList<>();
    having = new LinkedList<>();
    orders = new LinkedList<>();
    limit = offset = -1;
    return this;
  }

  public SqlBuilder addField(String field) {
    fields.addLast(field);
    return this;
  }

  public SqlBuilder addTable(String table) {
    tables.addLast(table);
    return this;
  }

  public SqlBuilder addCondition(String condition) {
    conditions.addLast(condition);
    return this;
  }

  public SqlBuilder addGroup(String group) {
    groups.addLast(group);
    return this;
  }

  public SqlBuilder addHaving(String having) {
    this.having.addLast(having);
    return this;
  }

  public SqlBuilder addOrder(String order) {
    orders.addLast(order);
    return this;
  }

  public SqlBuilder setFields(String... fields) {
    this.fields.clear();
    this.fields.addAll(Arrays.asList(fields));
    return this;
  }

  public SqlBuilder setTables(String... tables) {
    this.tables.clear();
    this.tables.addAll(Arrays.asList(tables));
    return this;
  }

  public SqlBuilder setConditions(String... conditions) {
    this.conditions.clear();
    this.conditions.addAll(Arrays.asList(conditions));
    return this;
  }

  public SqlBuilder setGroups(String... groups) {
    this.groups.clear();
    this.groups.addAll(Arrays.asList(groups));
    return this;
  }

  public SqlBuilder setHaving(String... having) {
    this.having.clear();
    this.having.addAll(Arrays.asList(having));
    return this;
  }

  public SqlBuilder setOrders(String... orders) {
    this.orders.clear();
    this.orders.addAll(Arrays.asList(orders));
    return this;
  }

  public SqlBuilder setLimit(int limit) {
    this.limit = limit;
    return this;
  }

  public SqlBuilder setOffset(int offset) {
    this.offset = offset;
    return this;
  }

  // toString

  private String selectToString() {
    StringBuilder sql = new StringBuilder("select ");
    sql.append(Seq.join(fields, ", "))
       .append(" from ")
       .append(Seq.join(tables, " join "));
    if (!conditions.isEmpty()) {
      sql.append(" where ").append(Seq.join(conditions, " and "));
    }
    if (!groups.isEmpty()) {
      sql.append(" group by ").append(Seq.join(groups, ", "));
      if (!having.isEmpty()) {
        sql.append(" having ").append(Seq.join(having, " and "));
      }
    }
    if (!orders.isEmpty()) {
      sql.append(" order by ").append(Seq.join(orders, ", "));
    }
    if (limit > 0) {
      sql.append(" limit ").append(Integer.toString(limit));
    }
    if (offset > -1) {
      sql.append(" offset ").append(Integer.toString(offset));
    }

    return sql.toString();
  }

  private String insertToString() {
    StringBuilder sql = new StringBuilder("insert into ");
    sql.append(tables.getFirst())
       .append(" (")
       .append(Seq.join(fields, ", "))
       .append(") values (")
       .append(Seq.join(Seq.map(fields, "?"), ", "))
       .append(")");
    return sql.toString();
  }

  private String updateToString() {
    StringBuilder sql = new StringBuilder("update ");
    sql.append(tables.getFirst())
       .append(" set ")
       .append(Seq.join(Seq.map(fields, "%s = ?"), ", "));

    if (!conditions.isEmpty()) {
      sql.append(" where ").append(Seq.join(conditions, " and "));
    }
    return sql.toString();
  }

  private String deleteToString() {
    StringBuilder sql = new StringBuilder("delete from ");
    sql.append(tables.getFirst());
    if (!conditions.isEmpty()) {
      sql.append(" where ").append(Seq.join(conditions, " and "));
    }
    return sql.toString();
  }

  @Override
  public String toString() {
    switch (mode) {
      case Select: return selectToString();
      case Insert: return insertToString();
      case Update: return updateToString();
      case Delete: return deleteToString();
      default: return "";
    }
  }
}