ProductDetailQuery.java

  1. package gov.usgs.earthquake.indexer;

  2. import java.util.Iterator;
  3. import java.util.List;

  4. import gov.usgs.earthquake.product.Product;

  5. /**
  6.  * Search for one product.
  7.  */
  8. public class ProductDetailQuery extends SearchQuery {

  9.     private List<Product> result;

  10.     /**
  11.      * Constructor making a SearchQuery object with PRODUCT_DETAIL as the method
  12.      * @param query a ProductIndexQuery
  13.      */
  14.     public ProductDetailQuery(final ProductIndexQuery query) {
  15.         super(SearchMethod.PRODUCT_DETAIL, query);
  16.     }

  17.     @Override
  18.     public List<Product> getResult() {
  19.         return result;
  20.     }

  21.     /** @param product list to set */
  22.     public void setResult(final List<Product> product) {
  23.         this.result = product;
  24.     }

  25.     @Override
  26.     public int compareTo(SearchQuery that) {
  27.         int r;

  28.         if ((r = super.compareTo(that)) != 0) {
  29.             return r;
  30.         }

  31.         if (this.result != null) {
  32.             List<Product> thatResult = ((ProductDetailQuery) that).result;
  33.             if ((r = (thatResult.size() - this.result.size())) != 0) {
  34.                 return r;
  35.             }

  36.             Iterator<Product> thisIter = this.result.iterator();
  37.             Iterator<Product> thatIter = thatResult.iterator();
  38.             while (thisIter.hasNext() && thatIter.hasNext()) {
  39.                 // just compare product ids for now
  40.                 r = thisIter.next().getId().compareTo(thatIter.next().getId());
  41.                 if (r != 0) {
  42.                     return r;
  43.                 }
  44.             }
  45.         }

  46.         return 0;
  47.     }

  48. }