EventsSummaryQuery.java

  1. package gov.usgs.earthquake.indexer;

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

  4. /**
  5.  * Search for multiple Events.
  6.  */
  7. public class EventsSummaryQuery extends SearchQuery {

  8.     private List<EventSummary> result;

  9.     /**
  10.      * Construct an EventsSummaryQuery.
  11.      *
  12.      * @param query ProductIndexQuery
  13.      */
  14.     public EventsSummaryQuery(final ProductIndexQuery query) {
  15.         super(SearchMethod.EVENTS_SUMMARY, query);
  16.     }

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

  21.     /** @param events list of EventSummarys to set as result */
  22.     public void setResult(List<EventSummary> events) {
  23.         this.result = events;
  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<EventSummary> thatResult = ((EventsSummaryQuery) that).result;
  33.             if ((r = (thatResult.size() - this.result.size())) != 0) {
  34.                 return r;
  35.             }

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

  46.         return 0;
  47.     }

  48. }