MtasTerms.java

  1. package mtas.codec;

  2. import java.io.IOException;
  3. import java.util.HashMap;
  4. import java.util.Map.Entry;

  5. import org.apache.lucene.index.Terms;
  6. import org.apache.lucene.index.TermsEnum;
  7. import org.apache.lucene.store.IndexInput;

  8. /**
  9.  * The Class MtasTerms.
  10.  */
  11. public class MtasTerms extends Terms {

  12.   /** The index input list. */
  13.   HashMap<String, IndexInput> indexInputList;

  14.   /** The index input offset list. */
  15.   HashMap<String, Long> indexInputOffsetList;

  16.   /** The version. */
  17.   int version;

  18.   /** The delegate terms. */
  19.   Terms delegateTerms;

  20.   /**
  21.    * Instantiates a new mtas terms.
  22.    *
  23.    * @param terms the terms
  24.    * @param indexInputList the index input list
  25.    * @param indexInputOffsetList the index input offset list
  26.    * @param version the version
  27.    */
  28.   public MtasTerms(Terms terms, HashMap<String, IndexInput> indexInputList,
  29.       HashMap<String, Long> indexInputOffsetList, int version) {
  30.     delegateTerms = terms;
  31.     this.indexInputList = indexInputList;
  32.     this.indexInputOffsetList = indexInputOffsetList;
  33.     this.version = version;
  34.   }

  35.   /*
  36.    * (non-Javadoc)
  37.    *
  38.    * @see org.apache.lucene.index.Terms#iterator()
  39.    */
  40.   @Override
  41.   public TermsEnum iterator() throws IOException {
  42.     if (delegateTerms != null) {
  43.       return delegateTerms.iterator();
  44.     } else {
  45.       return TermsEnum.EMPTY;
  46.     }
  47.   }

  48.   /*
  49.    * (non-Javadoc)
  50.    *
  51.    * @see org.apache.lucene.index.Terms#size()
  52.    */
  53.   @Override
  54.   public long size() throws IOException {
  55.     if (delegateTerms != null) {
  56.       return delegateTerms.size();
  57.     } else {
  58.       return -1;
  59.     }
  60.   }

  61.   /*
  62.    * (non-Javadoc)
  63.    *
  64.    * @see org.apache.lucene.index.Terms#getSumTotalTermFreq()
  65.    */
  66.   @Override
  67.   public long getSumTotalTermFreq() throws IOException {
  68.     if (delegateTerms != null) {
  69.       return delegateTerms.getSumTotalTermFreq();
  70.     } else {
  71.       return -1;
  72.     }
  73.   }

  74.   /*
  75.    * (non-Javadoc)
  76.    *
  77.    * @see org.apache.lucene.index.Terms#getSumDocFreq()
  78.    */
  79.   @Override
  80.   public long getSumDocFreq() throws IOException {
  81.     if (delegateTerms != null) {
  82.       return delegateTerms.getSumDocFreq();
  83.     } else {
  84.       return -1;
  85.     }
  86.   }

  87.   /*
  88.    * (non-Javadoc)
  89.    *
  90.    * @see org.apache.lucene.index.Terms#getDocCount()
  91.    */
  92.   @Override
  93.   public int getDocCount() throws IOException {
  94.     if (delegateTerms != null) {
  95.       return delegateTerms.getDocCount();
  96.     } else {
  97.       return -1;
  98.     }
  99.   }

  100.   /*
  101.    * (non-Javadoc)
  102.    *
  103.    * @see org.apache.lucene.index.Terms#hasFreqs()
  104.    */
  105.   @Override
  106.   public boolean hasFreqs() {
  107.     if (delegateTerms != null) {
  108.       return delegateTerms.hasFreqs();
  109.     } else {
  110.       return false;
  111.     }
  112.   }

  113.   /*
  114.    * (non-Javadoc)
  115.    *
  116.    * @see org.apache.lucene.index.Terms#hasOffsets()
  117.    */
  118.   @Override
  119.   public boolean hasOffsets() {
  120.     if (delegateTerms != null) {
  121.       return delegateTerms.hasOffsets();
  122.     } else {
  123.       return false;
  124.     }
  125.   }

  126.   /*
  127.    * (non-Javadoc)
  128.    *
  129.    * @see org.apache.lucene.index.Terms#hasPositions()
  130.    */
  131.   @Override
  132.   public boolean hasPositions() {
  133.     if (delegateTerms != null) {
  134.       return delegateTerms.hasPositions();
  135.     } else {
  136.       return false;
  137.     }
  138.   }

  139.   /*
  140.    * (non-Javadoc)
  141.    *
  142.    * @see org.apache.lucene.index.Terms#hasPayloads()
  143.    */
  144.   @Override
  145.   public boolean hasPayloads() {
  146.     if (delegateTerms != null) {
  147.       return delegateTerms.hasPayloads();
  148.     } else {
  149.       return false;
  150.     }
  151.   }

  152.   /**
  153.    * Gets the version.
  154.    *
  155.    * @return the version
  156.    */
  157.   public int getVersion() {
  158.     return version;
  159.   }

  160.   /**
  161.    * Gets the index input list.
  162.    *
  163.    * @return the index input list
  164.    */
  165.   public HashMap<String, IndexInput> getIndexInputList() {
  166.     HashMap<String, IndexInput> clonedIndexInputList = new HashMap<String, IndexInput>();
  167.     for (Entry<String, IndexInput> entry : indexInputList.entrySet()) {
  168.       clonedIndexInputList.put(entry.getKey(), entry.getValue().clone());
  169.     }
  170.     return clonedIndexInputList;
  171.   }

  172.   /**
  173.    * Gets the index input offset list.
  174.    *
  175.    * @return the index input offset list
  176.    */
  177.   public HashMap<String, Long> getIndexInputOffsetList() {
  178.     return indexInputOffsetList;
  179.   }

  180. }