reduceIntoProfile
(DOC) Converts the payload objects into segments and combines them into a serial profile.
After the payload objects are converted into segments, any overlapping segments are resolved by combining them with a binary operation similar to a reduce operation (as in functional programming). It is recommended to create the binary operation using the NullBinaryOperation.reduce function.
Example
Say you have a timeline of activity instances, each with an integer argument called count
, and you want to extract a profile of the count
arguments - but in the event that the activities overlap, you want to add the counts together. Your code would look like this:
myInstances.reduceIntoProfile(Numbers::new, BinaryOperation.reduce(
(activity) -> activity.inner.count, // convert
(acc, activity) -> acc + activity.inner.count // combine
))
If the plan has three relevant activities overlapping (A, B, and C):
first the converter will be called on A, starting the accumulator (
acc
)then the combiner will be called for
acc
and B, updating the accumulatorthen the combiner will be called for
acc
and C, etc
If the plan also has other relevant activities the overlap sometime else, they will be combined independently of A, B, and C.
Parameters
the constructor of the result profile
a binary operation for converting and combining the input objects