Class PriceChangedEvent
java.lang.Object
com.university.bookstore.observer.PriceChangedEvent
- All Implemented Interfaces:
MaterialEvent
Event that occurs when a material's price changes.
- Since:
- 2024-09-15
- Version:
- 3.0
- Author:
- Navid Mohaghegh
-
Constructor Summary
ConstructorsConstructorDescriptionPriceChangedEvent(Material material, double oldPrice, double newPrice) Creates a new price changed event. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGets a description of this event.Gets the type of this event.Gets the material associated with this event.doubleGets the new price.doubleGets the old price.doubleGets the price change amount.doubleGets the price change percentage.longGets the timestamp when this event occurred.inthashCode()booleanChecks if the price decreased.booleanChecks if the price increased.toString()
-
Constructor Details
-
PriceChangedEvent
Creates a new price changed event.- Parameters:
material- the material whose price changedoldPrice- the previous pricenewPrice- the new price- Throws:
IllegalArgumentException- if material is null or prices are negative
-
-
Method Details
-
getMaterial
Description copied from interface:MaterialEventGets the material associated with this event.- Specified by:
getMaterialin interfaceMaterialEvent- Returns:
- the material
-
getTimestamp
public long getTimestamp()Description copied from interface:MaterialEventGets the timestamp when this event occurred.- Specified by:
getTimestampin interfaceMaterialEvent- Returns:
- the event timestamp in milliseconds
-
getEventType
Description copied from interface:MaterialEventGets the type of this event.- Specified by:
getEventTypein interfaceMaterialEvent- Returns:
- the event type
-
getDescription
Description copied from interface:MaterialEventGets a description of this event.- Specified by:
getDescriptionin interfaceMaterialEvent- Returns:
- the event description
-
getOldPrice
public double getOldPrice()Gets the old price.- Returns:
- the previous price
-
getNewPrice
public double getNewPrice()Gets the new price.- Returns:
- the new price
-
getPriceChange
public double getPriceChange()Gets the price change amount.- Returns:
- the price change (new - old)
-
getPriceChangePercentage
public double getPriceChangePercentage()Gets the price change percentage.- Returns:
- the price change percentage
-
isPriceIncrease
public boolean isPriceIncrease()Checks if the price increased.- Returns:
- true if the price increased
-
isPriceDecrease
public boolean isPriceDecrease()Checks if the price decreased.- Returns:
- true if the price decreased
-
equals
-
hashCode
-
toString
-