DefaultNotification.java

  1. /*
  2.  * DefaultNotification
  3.  */
  4. package gov.usgs.earthquake.distribution;

  5. import gov.usgs.earthquake.product.ProductId;

  6. import java.net.URL;
  7. import java.util.Date;

  8. /**
  9.  * A DefaultNotification is a implementation of the Notification interface. No
  10.  * location information is stored about products, and must be tracked
  11.  * separately.
  12.  */
  13. public class DefaultNotification implements Notification {

  14.     /** The product that is available. */
  15.     private final ProductId id;

  16.     /** How long the product is available. */
  17.     private final Date expirationDate;

  18.     /** Where to send tracking updates. */
  19.     private final URL trackerURL;

  20.     /**
  21.      * Construct a DefaultNotification.
  22.      *
  23.      * @param id
  24.      *            the product that is available.
  25.      * @param expirationDate
  26.      *            how long the product is available.
  27.      * @param trackerURL
  28.      *            where to send tracking updates.
  29.      */
  30.     public DefaultNotification(final ProductId id, final Date expirationDate,
  31.             final URL trackerURL) {
  32.         this.id = id;
  33.         this.expirationDate = expirationDate;
  34.         this.trackerURL = trackerURL;
  35.     }

  36.     /**
  37.      * @return how long the product is available.
  38.      */
  39.     public Date getExpirationDate() {
  40.         return expirationDate;
  41.     }

  42.     /**
  43.      * @return which product is available.
  44.      */
  45.     public ProductId getProductId() {
  46.         return id;
  47.     }

  48.     /**
  49.      * @return location to send tracking updates.
  50.      */
  51.     public URL getTrackerURL() {
  52.         return trackerURL;
  53.     }

  54.     /** A comparison method to see if two notifications are equal. */
  55.     public boolean equals(Notification that) {
  56.         return
  57.         (
  58.             that instanceof DefaultNotification &&
  59.             getExpirationDate().equals(that.getExpirationDate()) &&
  60.             getProductId().equals(that.getProductId()) &&
  61.             (
  62.                 (getTrackerURL() == null && that.getTrackerURL() == null)
  63.                 || getTrackerURL().equals(that.getTrackerURL()))
  64.         );
  65.     }

  66. }