-
Notifications
You must be signed in to change notification settings - Fork 0
Properties
Properties stores states of events and provides a way to access and define (if property is mutable) the value without the need of knowing the type of event.
Example:
val event = ...
val amount = event.getIntGetterProperty("amount")
// if mutable:
val gsAmount = event.getIntGSProperty("amount")
gsAmount.setAsInt(9)
println(amount.getAsInt()) // Prints 9
For every property, event generator creates a backing field, a getter, and if property is mutable, a setter. All properties instance are registered in a Map<String, Property<?>>
that is later wrapped into an unmodifiable map that is expoded by getProperties
.
The same applies to additional properties.
Concrete event implementations must correctly implement getProperties
(this means that the implementation must return an unmodifiable view of all properties of event).
There are four types of properties:
-
Property<T>
¹- Only representation, values cannot be neither accessed nor defined.
-
GetterProperty<T>
- Read-only property, value can only be accessed.
-
SetterProperty<T>
¹- Write-only property, value can only be defined.
-
GSProperty<T>
- Read and write property, value can be accessed and defined.
¹ - By default, event generator does not construct a property with this type.
With variants specialized for:
- Boolean
- Double
- Int
- Long
Properties are the core of event destruction, also they allow variants of events to be created without creating a new interface for every variant, example: UserBuyEvent
, BusinessBuyEvent
, UserCancelPurchaseEvent
, BusinessCancelPurchaseEvent
. See Extensions for more information.