ProductsSummaryQuery.java

  1. package gov.usgs.earthquake.indexer;

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

  4. /**
  5.  * Search for multiple products.
  6.  */
  7. public class ProductsSummaryQuery extends SearchQuery {

  8.     private List<ProductSummary> result;

  9.     /**
  10.      * Constructor
  11.      * makes a SearchQuery of type product summary
  12.      * @param query ProductIndexQuery
  13.      */
  14.     public ProductsSummaryQuery(final ProductIndexQuery query) {
  15.         super(SearchMethod.PRODUCTS_SUMMARY, query);
  16.     }

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

  21.     /** @param products List of ProductSummaries */
  22.     public void setResult(final List<ProductSummary> products) {
  23.         this.result = products;
  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<ProductSummary> thatResult = ((ProductsSummaryQuery) that).result;
  33.             if ((r = (thatResult.size() - this.result.size())) != 0) {
  34.                 return r;
  35.             }

  36.             Iterator<ProductSummary> thisIter = this.result.iterator();
  37.             Iterator<ProductSummary> 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. }