Skip to content

Commit

Permalink
Add previous operator for two entities (#38)
Browse files Browse the repository at this point in the history
* Add previous operator for two entities

* Unified KDoc.

---------

Co-authored-by: Dominik Mäckel <dominik.maeckel@tu-dortmund.de>
  • Loading branch information
tillschallau and dominikmaeckel authored Feb 13, 2024
1 parent 5d4f063 commit dd56637
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,47 @@ fun <E1 : E, E : EntityType<E, T, S>, T : TickDataType<E, T, S>, S : SegmentType
if (entity::class.isInstance(previousEntity)) phi(entity::class.cast(previousEntity))
else false
})

/**
* CMFTBL implementation of the previous operator for two entities.
*
* @param E1 [EntityType]
* 1.
* @param E2 [EntityType]
* 2.
* @param E [EntityType].
* @param T [TickDataType].
* @param S [SegmentType].
* @param entity1 Current [EntityType]
* 1.
* @param entity2 Current [EntityType]
* 2.
* @param interval Observation interval.
* @param phi Predicate.
*/
fun <
E1 : E,
E2 : E,
E : EntityType<E, T, S>,
T : TickDataType<E, T, S>,
S : SegmentType<E, T, S>> previous(
entity1: E1,
entity2: E2,
interval: Pair<Double, Double> = Pair(0.0, Double.MAX_VALUE),
phi: (E1, E2) -> Boolean
): Boolean {
require(entity1.tickData == entity2.tickData) {
"the two entities provided as argument are not from same tick"
}
return previous(
entity1.tickData,
interval,
phi = { td ->
val previousEntity1 = td.entity(entity1.id)
val previousEntity2 = td.entity(entity2.id)
if (entity1::class.isInstance(previousEntity1) &&
entity2::class.isInstance(previousEntity2))
phi(entity1::class.cast(previousEntity1), entity2::class.cast(previousEntity2))
else false
})
}

0 comments on commit dd56637

Please sign in to comment.