Sequence Attributes
Sequences are special attributes allowing do provide sequence of items of type String
or named data entities (objects of data class implementing NamedEntity
interface). This is useful if you want give user any kind of questions or tasks and prevent to repeat them (or pass too often) by remembering them. Implementation is based on MemoryMutableSet<String>
storing each value (data entity name) into value
property together with count
and time
properties. Developer specifies how next item will be selected implementing lambda nextBlock
function called by sequence in scope of SequenceAttribute object, providing properties
next
returns next value generated from sequence. If no more suitable value is available in sequence at the moment, it will benull
.last
returns last generated value. If there is no access tonext
property yet, it throws error.
and two methods
nextRandom
nextInLine
(if end of list is reached andmaxCount
value described below is > 1, it will start from the beginning of list again afterminDuration
)
both with following optional parameters
minDuration
- minimum duration before repeating same item again (default is 1.day)maxCount
- maximum count (default valueInt.MAX_VALUE
means unlimited)resetDuration
- ifcount
has reachedmaxCount
andtime < now - resetDuration
thencount
will be reset to0
and therefore value can be returned again (default valuenull
means no reset time). e.g.1.week
Please remember that *Duration
parameters work always only within attribute scope - therefore using hour
, day
or week
units make sense to use only in user, not session context scope (which usually takes only minutes)
Sequence attributes should be always declared as val
because their value is object of type SequenceAttribute
Examples
Init Code
Functional code
Last updated