Package gov.usgs.earthquake.indexer
Class Event
- java.lang.Object
-
- gov.usgs.earthquake.indexer.Event
-
- All Implemented Interfaces:
java.lang.Comparable<Event>
public class Event extends java.lang.Object implements java.lang.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 Summary
Fields Modifier and Type Field Description static java.lang.String
ASSOCIATE_PRODUCT_TYPE
Associate product typestatic java.lang.String
DISASSOCIATE_PRODUCT_TYPE
Disassociate product typestatic java.lang.String
ORIGIN_PRODUCT_TYPE
Origin product typestatic java.lang.String
OTHEREVENTSOURCE_PROPERTY
Property for othereventsourcestatic java.lang.String
OTHEREVENTSOURCECODE_PROPERTY
Property for othereventsourcecode
-
Constructor Summary
Constructors Constructor Description Event()
Default constructor.Event(Event copy)
Copy constructor for event.Event(java.lang.Long indexId)
Construct an event with only an indexId.Event(java.lang.Long indexId, java.util.Map<java.lang.String,java.util.List<ProductSummary>> products)
Construct and event with an indexId and a list of products.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addProduct(ProductSummary summary)
A convenience method for adding a product summary to an event object.int
compareTo(Event that)
java.util.Map<java.lang.String,java.util.List<java.lang.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).java.util.List<ProductSummary>
getAllProductList()
Get all event products (including those that are deleted or superseded).java.util.Map<java.lang.String,java.util.List<ProductSummary>>
getAllProducts()
Get all products associated with event, even if they are deleted.java.math.BigDecimal
getDepth()
Get the preferred depth for this event.java.util.Map<java.lang.String,java.lang.String>
getEventCodes()
Deprecated.usegetAllEventCodes(boolean)
instead.static java.util.Map<java.lang.String,java.lang.String>
getEventCodes(java.util.List<ProductSummary> summaries)
Deprecated.usegetAllEventCodes(boolean)
instead.java.lang.String
getEventId()
Get the event id.protected ProductSummary
getEventIdProduct()
Get the product used for eventsource and eventsourcecode.EventSummary
getEventSummary()
Summarize this event into preferred values.java.lang.Long
getIndexId()
Get the index id.java.math.BigDecimal
getLatitude()
Get the preferred latitude for this event.java.math.BigDecimal
getLongitude()
Get the preferred longitude for this event.java.math.BigDecimal
getMagnitude()
Get the preferred magntitude for this event.static ProductSummary
getMostPreferred(java.util.List<ProductSummary> products, java.lang.String preferredType, java.lang.String preferredNotNullProperty)
Find the most preferred product.ProductSummary
getPreferredMagnitudeProduct()
Get the most preferred magnitude product for event.ProductSummary
getPreferredOriginProduct()
Get the most preferred origin-like product for this event.ProductSummary
getPreferredProduct(java.lang.String type)
Get the preferred product of a specific type.static ProductSummary
getPreferredProduct(java.util.List<ProductSummary> all)
Get the most preferred product from a list of products.java.util.Map<java.lang.String,ProductSummary>
getPreferredProducts()
Get preferred products of all types.java.util.List<ProductSummary>
getPreferredProductsSorted()
Get a list of all the preferred products sorted based on their authoritative weightsjava.util.List<ProductSummary>
getProductList()
Get all event products that have not been deleted or superseded as a list.java.util.Map<java.lang.String,java.util.List<ProductSummary>>
getProducts()
Get the event products.java.util.List<ProductSummary>
getProducts(java.lang.String type)
Convenience method to get products of a given type.ProductSummary
getProductWithOriginProperties()
Get the most recent product with origin properties (id, lat, lon, time).static java.util.List<ProductSummary>
getSortedMostPreferredFirst(java.util.List<ProductSummary> products)
Sort a list of products, most preferred first.java.lang.String
getSource()
Get the preferred source for this event.java.lang.String
getSourceCode()
Get the preferred source code for this event.java.util.Map<java.lang.String,Event>
getSubEvents()
Return a list of sub-events that make up this event.java.util.Date
getTime()
Get the preferred time for this event.java.util.Date
getUpdateTime()
Event update time is most recent product update time.static java.util.List<ProductSummary>
getWithEventId(java.util.List<ProductSummary> products)
Remove deleted products from the list.static java.util.List<ProductSummary>
getWithoutDeleted(java.util.List<ProductSummary> products)
Remove deleted products from the list.static java.util.List<ProductSummary>
getWithoutSuperseded(java.util.List<ProductSummary> products)
Remove old versions of products from the list.boolean
hasAssociateProduct(Event otherEvent)
Check if this event has an associate product for another given Event.boolean
hasDisassociateProduct(Event otherEvent)
Check if this event has an disassociate product for another given Event.boolean
isAssociated(Event that)
Same as isAssociated(that, new DefaultAssociator());boolean
isAssociated(Event that, Associator associator)
Check if an event is associated to this event.boolean
isDeleted()
void
log(java.util.logging.Logger logger)
Depending on logger level, takes in summary data and appends to bufferstatic boolean
productHasOriginProperties(ProductSummary product)
Check if a product can define an event (id, lat, lon, time).void
removeProduct(ProductSummary summary)
A convenience method for removing a product summary from an event object.void
setIndexId(java.lang.Long indexId)
Set the index id.void
setProducts(java.util.Map<java.lang.String,java.util.List<ProductSummary>> newProducts)
Set products.
-
-
-
Field Detail
-
ORIGIN_PRODUCT_TYPE
public static final java.lang.String ORIGIN_PRODUCT_TYPE
Origin product type- See Also:
- Constant Field Values
-
ASSOCIATE_PRODUCT_TYPE
public static final java.lang.String ASSOCIATE_PRODUCT_TYPE
Associate product type- See Also:
- Constant Field Values
-
DISASSOCIATE_PRODUCT_TYPE
public static final java.lang.String DISASSOCIATE_PRODUCT_TYPE
Disassociate product type- See Also:
- Constant Field Values
-
OTHEREVENTSOURCE_PROPERTY
public static final java.lang.String OTHEREVENTSOURCE_PROPERTY
Property for othereventsource- See Also:
- Constant Field Values
-
OTHEREVENTSOURCECODE_PROPERTY
public static final java.lang.String OTHEREVENTSOURCECODE_PROPERTY
Property for othereventsourcecode- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Event
public Event()
Default constructor. All fields are set to null, and the list of products is empty.
-
Event
public Event(java.lang.Long indexId)
Construct an event with only an indexId. The products map will be empty.- Parameters:
indexId
- the indexId to set.
-
Event
public Event(java.lang.Long indexId, java.util.Map<java.lang.String,java.util.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 Detail
-
getIndexId
public java.lang.Long getIndexId()
Get the index id.- Returns:
- the indexId or null if one hasn't been assigned.
-
setIndexId
public void setIndexId(java.lang.Long indexId)
Set the index id.- Parameters:
indexId
- the indexId to set.
-
getAllProducts
public java.util.Map<java.lang.String,java.util.List<ProductSummary>> getAllProducts()
Get all products associated with event, even if they are deleted.- Returns:
- all products associated with event.
-
getProducts
public java.util.Map<java.lang.String,java.util.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:
getAllProducts()
-
setProducts
public void setProducts(java.util.Map<java.lang.String,java.util.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 java.util.List<ProductSummary> getProducts(java.lang.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 java.util.List<ProductSummary> getAllProductList()
Get all event products (including those that are deleted or superseded).- Returns:
- a list of event products.
-
getProductList
public java.util.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 java.util.Map<java.lang.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(java.lang.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
public java.util.Map<java.lang.String,java.lang.String> getEventCodes()
Deprecated.usegetAllEventCodes(boolean)
instead.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
public static java.util.Map<java.lang.String,java.lang.String> getEventCodes(java.util.List<ProductSummary> summaries)
Deprecated.usegetAllEventCodes(boolean)
instead.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 java.util.Map<java.lang.String,java.util.List<java.lang.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 java.util.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 java.lang.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()
,getSourceCode()
-
getSource
public java.lang.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 java.lang.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:
getPreferredOriginProduct()
-
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 withgetPreferredOriginProduct()
. Products are checked in the following order, sorted most preferred first within each group. The first matching product is returned:- "origin" products not superseded or deleted, that have origin properties
- "origin" products superseded by a delete, that have origin properties
- products not superseded or deleted, that have origin properties
- products superseded by a delete, that have origin properties
- Returns:
- the most recent product with origin properties.
- See Also:
productHasOriginProperties(ProductSummary)
-
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 usinggetProductWithOriginProperties()
. 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:
- "origin" products not superseded or deleted, that have origin properties.
- "origin" products not superseded, that have an event id.
- If no "origin" products exist:
- products not superseded or deleted, that have origin properties.
- products not superseded, that have an event id.
- Returns:
- the most recent product with origin properties.
- See Also:
productHasOriginProperties(ProductSummary)
- If any "origin" products exist:
-
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 callsgetPreferredOriginProduct()
.- Returns:
- the most preferred magnitude product for event.
-
getTime
public java.util.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 java.math.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 java.math.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 java.util.Date getUpdateTime()
Event update time is most recent product update time.- Returns:
- the most recent product update time.
-
getDepth
public java.math.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 java.math.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(java.util.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 interfacejava.lang.Comparable<Event>
-
getMostPreferred
public static ProductSummary getMostPreferred(java.util.List<ProductSummary> products, java.lang.String preferredType, java.lang.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 java.util.List<ProductSummary> getWithoutDeleted(java.util.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 java.util.List<ProductSummary> getWithEventId(java.util.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 java.util.List<ProductSummary> getWithoutSuperseded(java.util.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 java.util.List<ProductSummary> getSortedMostPreferredFirst(java.util.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 java.util.Map<java.lang.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:- Share a common EVENTSOURCE with different EVENTSOURCECODE.
- Either has a disassociate product for the other.
- Preferred location in space and time is NOT nearby, and no other reason to associate.
- Share a common EVENTID
- Either has an associate product for the other.
- 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(java.util.logging.Logger logger)
Depending on logger level, takes in summary data and appends to buffer- Parameters:
logger
- logger object
-
-