Class Event

java.lang.Object
gov.usgs.earthquake.indexer.Event
All Implemented Interfaces:
Comparable<Event>

public class Event extends Object implements Comparable<Event>
An event is a group of products that are nearby in space and time. Which products appear in an event depend primarily on the ProductIndexQuery.ResultType that is used when retrieving an event from the index. Unless CURRENT is used, you may not get what you expect.
  • Field Details

    • ORIGIN_PRODUCT_TYPE

      public static final String ORIGIN_PRODUCT_TYPE
      Origin product type
      See Also:
    • ASSOCIATE_PRODUCT_TYPE

      public static final String ASSOCIATE_PRODUCT_TYPE
      Associate product type
      See Also:
    • DISASSOCIATE_PRODUCT_TYPE

      public static final String DISASSOCIATE_PRODUCT_TYPE
      Disassociate product type
      See Also:
    • OTHEREVENTSOURCE_PROPERTY

      public static final String OTHEREVENTSOURCE_PROPERTY
      Property for othereventsource
      See Also:
    • OTHEREVENTSOURCECODE_PROPERTY

      public static final String OTHEREVENTSOURCECODE_PROPERTY
      Property for othereventsourcecode
      See Also:
  • Constructor Details

    • Event

      public Event()
      Default constructor. All fields are set to null, and the list of products is empty.
    • Event

      public Event(Long indexId)
      Construct an event with only an indexId. The products map will be empty.
      Parameters:
      indexId - the indexId to set.
    • Event

      public Event(Long indexId, Map<String,List<ProductSummary>> products)
      Construct and event with an indexId and a list of products.
      Parameters:
      indexId - the product index id.
      products - the list of products.
    • Event

      public Event(Event copy)
      Copy constructor for event. The products associated with this event are not cloned, but the list of products is.
      Parameters:
      copy - the event to clone.
  • Method Details

    • getIndexId

      public Long getIndexId()
      Get the index id.
      Returns:
      the indexId or null if one hasn't been assigned.
    • setIndexId

      public void setIndexId(Long indexId)
      Set the index id.
      Parameters:
      indexId - the indexId to set.
    • getAllProducts

      public Map<String,List<ProductSummary>> getAllProducts()
      Get all products associated with event, even if they are deleted.
      Returns:
      all products associated with event.
    • getProducts

      public Map<String,List<ProductSummary>> getProducts()
      Get the event products. Only returns products that have not been deleted or superseded. This method returns a copy of the underlying product map that has been filtered to remove deleted products.
      Returns:
      a map of event products.
      See Also:
    • setProducts

      public void setProducts(Map<String,List<ProductSummary>> newProducts)
      Set products. ProductSummaries are not cloned, but lists are.
      Parameters:
      newProducts - the products to set.
    • addProduct

      public void addProduct(ProductSummary summary)
      A convenience method for adding a product summary to an event object. Note: this method does not update any associated product index.
      Parameters:
      summary - the summary to add to this event.
    • removeProduct

      public void removeProduct(ProductSummary summary)
      A convenience method for removing a product summary from an event object. Note: this method does not update any associated product index.
      Parameters:
      summary - the summary to remove from this event.
    • getProducts

      public List<ProductSummary> getProducts(String type)
      Convenience method to get products of a given type. This method always returns a copy of the internal list, and may be empty. Only returns products that have not been deleted or superseded.
      Parameters:
      type - the product type.
      Returns:
      a list of products of that type, which may be empty.
    • getAllProductList

      public List<ProductSummary> getAllProductList()
      Get all event products (including those that are deleted or superseded).
      Returns:
      a list of event products.
    • getProductList

      public List<ProductSummary> getProductList()
      Get all event products that have not been deleted or superseded as a list.
      Returns:
      a list of event products.
    • getPreferredProducts

      public Map<String,ProductSummary> getPreferredProducts()
      Get preferred products of all types. This map will contain one product of each type, chosen by preferred weight.
      Returns:
      a map from product type to the preferred product of that type.
    • getPreferredProduct

      public ProductSummary getPreferredProduct(String type)
      Get the preferred product of a specific type.
      Parameters:
      type - type of product to get.
      Returns:
      most preferred product of that type, or null if no product of that type is associated.
    • getEventCodes

      @Deprecated public Map<String,String> getEventCodes()
      Deprecated.
      Get a map of all event ids associated with this event. Same as Event.getEventCodes(this.getAllProductList());
      Returns:
      map of all event ids associated with this event.
    • getEventCodes

      @Deprecated public static Map<String,String> getEventCodes(List<ProductSummary> summaries)
      Deprecated.
      Get a map of all event ids associated with this event. Map key is eventSource, Map value is eventSourceCode.
      Parameters:
      summaries - the summaries list to extract event codes from.
      Returns:
      map of all event ids associated with this event.
    • getAllEventCodes

      public Map<String,List<String>> getAllEventCodes(boolean includeDeleted)
      Get a map of all event ids associated with this event, recognizing that one source may have multiple codes (they broke the rules, but it happens).
      Parameters:
      includeDeleted - whether to include ids for sub events whose products have all been deleted.
      Returns:
      Map from source to a list of codes from that source.
    • getPreferredProductsSorted

      public List<ProductSummary> getPreferredProductsSorted()
      Get a list of all the preferred products sorted based on their authoritative weights
      Returns:
      sorted list of ProductSummary objects
    • getEventId

      public String getEventId()
      Get the event id. The event id is the combination of event source and event source code.
      Returns:
      the event id, or null if either event source or event source code is null.
      See Also:
    • getSource

      public String getSource()
      Get the preferred source for this event. If an origin product exists, it's value is used.
      Returns:
      Source from preferred product or null
    • getSourceCode

      public String getSourceCode()
      Get the preferred source code for this event. If an origin product exists, it's value is used.
      Returns:
      Source code from preferred product or null
    • getEventIdProduct

      protected ProductSummary getEventIdProduct()
      Get the product used for eventsource and eventsourcecode. Event ID comes from the preferred origin product.
      Returns:
      The most preferred product summary. This summary is used to determine the eventsouce and eventsourcecode.
      See Also:
    • getProductWithOriginProperties

      public ProductSummary getProductWithOriginProperties()
      Get the most recent product with origin properties (id, lat, lon, time). NOTE: this product may have been superseded by a delete. When an event has not been deleted, this method should be consistent with getPreferredOriginProduct(). Products are checked in the following order, sorted most preferred first within each group. The first matching product is returned:
      1. "origin" products not superseded or deleted, that have origin properties
      2. "origin" products superseded by a delete, that have origin properties
      3. products not superseded or deleted, that have origin properties
      4. products superseded by a delete, that have origin properties
      Returns:
      the most recent product with origin properties.
      See Also:
    • getPreferredOriginProduct

      public ProductSummary getPreferredOriginProduct()
      Get the most preferred origin-like product for this event. The event is considered deleted if the returned product is null, deleted, or does not have origin properties. Information about the event may still be available using getProductWithOriginProperties(). Products are checked in the following order, sorted most preferred first within each group. The first matching product is returned:
      • If any "origin" products exist:
        1. "origin" products not superseded or deleted, that have origin properties.
        2. "origin" products not superseded, that have an event id.
      • If no "origin" products exist:
        1. products not superseded or deleted, that have origin properties.
        2. products not superseded, that have an event id.
      Returns:
      the most recent product with origin properties.
      See Also:
    • productHasOriginProperties

      public static boolean productHasOriginProperties(ProductSummary product)
      Check if a product can define an event (id, lat, lon, time).
      Parameters:
      product - product to check.
      Returns:
      true if product has id, lat, lon, and time properties.
    • getPreferredMagnitudeProduct

      public ProductSummary getPreferredMagnitudeProduct()
      Get the most preferred magnitude product for event. Currently calls getPreferredOriginProduct().
      Returns:
      the most preferred magnitude product for event.
    • getTime

      public Date getTime()
      Get the preferred time for this event. If an origin product exists, it's value is used.
      Returns:
      Time from preferred product or null
    • getLatitude

      public BigDecimal getLatitude()
      Get the preferred latitude for this event. If an origin product exists, it's value is used.
      Returns:
      Latitude from preferred product or null
    • getLongitude

      public BigDecimal getLongitude()
      Get the preferred longitude for this event. If an origin product exists, it's value is used.
      Returns:
      Longitude from preferred product or null
    • getUpdateTime

      public Date getUpdateTime()
      Event update time is most recent product update time.
      Returns:
      the most recent product update time.
    • getDepth

      public BigDecimal getDepth()
      Get the preferred depth for this event. If an origin product exists, it's value is used.
      Returns:
      Depth from preferred product or null
    • getMagnitude

      public BigDecimal getMagnitude()
      Get the preferred magntitude for this event. If an origin product exists, it's value is used.
      Returns:
      magnitude from preferred product or null
    • isDeleted

      public boolean isDeleted()
      Returns:
      boolean if the preferred event is deleted
    • getPreferredProduct

      public static ProductSummary getPreferredProduct(List<ProductSummary> all)
      Get the most preferred product from a list of products.
      Parameters:
      all - a list of products containing only one type of product.
      Returns:
      the product with the highest preferred weight, and if tied the most recent update time wins.
    • getEventSummary

      public EventSummary getEventSummary()
      Summarize this event into preferred values. NOTE: the event summary may include information from an origin product, even when the preferred origin for the event has been deleted. Use getPreferredOriginProduct() to check the preferred origin of the event.
      Returns:
      an event summary.
    • compareTo

      public int compareTo(Event that)
      Specified by:
      compareTo in interface Comparable<Event>
    • getMostPreferred

      public static ProductSummary getMostPreferred(List<ProductSummary> products, String preferredType, String preferredNotNullProperty)
      Find the most preferred product. If preferredType is not null, products of this type are favored over those not of this type. If preferredNotNullProperty is not null, products that have this property set are favored over those without this property set.
      Parameters:
      products - the list of products to search.
      preferredType - the preferred product type, if available.
      preferredNotNullProperty - the preferred property name, if available.
      Returns:
      The most preferred product summary of the given type.
    • getWithoutDeleted

      public static List<ProductSummary> getWithoutDeleted(List<ProductSummary> products)
      Remove deleted products from the list.
      Parameters:
      products - list of products to filter.
      Returns:
      copy of the products list with deleted products removed.
    • getWithEventId

      public static List<ProductSummary> getWithEventId(List<ProductSummary> products)
      Remove deleted products from the list.
      Parameters:
      products - list of products to filter.
      Returns:
      copy of the products list with deleted products removed.
    • getWithoutSuperseded

      public static List<ProductSummary> getWithoutSuperseded(List<ProductSummary> products)
      Remove old versions of products from the list.
      Parameters:
      products - list of products to filter.
      Returns:
      a copy of the products list with products of the same source+type+code but with older updateTimes (superseded) removed.
    • getSortedMostPreferredFirst

      public static List<ProductSummary> getSortedMostPreferredFirst(List<ProductSummary> products)
      Sort a list of products, most preferred first.
      Parameters:
      products - the list of products to sort.
      Returns:
      a copy of the list sorted with most preferred first.
    • getSubEvents

      public Map<String,Event> getSubEvents()
      Return a list of sub-events that make up this event. Event lines are drawn by eventid. Products that have no eventid are included with the sub event whose id is considered preferred.
      Returns:
      map from eventid to event object with products for that eventid.
    • hasAssociateProduct

      public boolean hasAssociateProduct(Event otherEvent)
      Check if this event has an associate product for another given Event.
      Parameters:
      otherEvent - the other event.
      Returns:
      true if there is an associate product, false otherwise.
    • hasDisassociateProduct

      public boolean hasDisassociateProduct(Event otherEvent)
      Check if this event has an disassociate product for another given Event.
      Parameters:
      otherEvent - the other event.
      Returns:
      true if there is an disassociate product, false otherwise.
    • isAssociated

      public boolean isAssociated(Event that)
      Same as isAssociated(that, new DefaultAssociator());
      Parameters:
      that - an event to test
      Returns:
      boolean true if associated, false otherwise
    • isAssociated

      public boolean isAssociated(Event that, Associator associator)
      Check if an event is associated to this event. Reasons events may be considered disassociated:
      1. Share a common EVENTSOURCE with different EVENTSOURCECODE.
      2. Either has a disassociate product for the other.
      3. Preferred location in space and time is NOT nearby, and no other reason to associate.
      Reasons events may be considered associated:
      1. Share a common EVENTID
      2. Either has an associate product for the other.
      3. Their preferred location in space and time is nearby.
      Parameters:
      that - candidate event to test.
      associator - An associator to compare two events
      Returns:
      true if associated, false otherwise.
    • log

      public void log(Logger logger)
      Depending on logger level, takes in summary data and appends to buffer
      Parameters:
      logger - logger object