Class SlidingWindowToolkit
- java.lang.Object
-
- org.openjdk.jmc.flightrecorder.rules.util.SlidingWindowToolkit
-
public class SlidingWindowToolkit extends Object
Utility functions and interfaces for doing sliding window calculations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
SlidingWindowToolkit.IOrderedWindowVisitor
static interface
SlidingWindowToolkit.IUnorderedWindowValueFunction<V>
static interface
SlidingWindowToolkit.IUnorderedWindowVisitor
-
Constructor Summary
Constructors Constructor Description SlidingWindowToolkit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
slidingWindowOrdered(SlidingWindowToolkit.IOrderedWindowVisitor callback, Iterator<IItem> items, IMemberAccessor<IQuantity,IItem> posAccessor, IQuantity windowSize, IQuantity slideSize)
Runs a sliding window through all items, looping through items once, removing from the start and adding and the end of a windowItem set to match the current time window.static void
slidingWindowUnordered(SlidingWindowToolkit.IUnorderedWindowVisitor callback, IItemCollection items, IQuantity windowSize, IQuantity slideSize)
Runs a sliding window through all items, by calculating the window start and end and filter through all the items.static void
slidingWindowUnordered(SlidingWindowToolkit.IUnorderedWindowVisitor callback, IItemCollection items, IQuantity windowSize, IQuantity slideSize, boolean includeIntersecting)
Runs a sliding window through all items, by calculating the window start and end and filter through all the items.static Pair<IQuantity,IRange<IQuantity>>
slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<IQuantity> valueFunction, boolean max, boolean includeIntersecting)
Calculates max/min window quantity value of items.static <V> Pair<V,IRange<IQuantity>>
slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<V> valueFunction, Comparator<V> valueComparator, boolean max, boolean includeIntersecting)
Calculates max/min window value of items.static Pair<IQuantity,IRange<IQuantity>>
slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, IQuantity slideSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<IQuantity> valueFunction, boolean max, boolean includeIntersecting)
Calculates max/min window quantity value of items.static <V> Pair<V,IRange<IQuantity>>
slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, IQuantity slideSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<V> valueFunction, Comparator<V> valueComparator, boolean max, boolean includeIntersecting)
Calculates max/min window value of items.
-
-
-
Method Detail
-
slidingWindowOrdered
public static void slidingWindowOrdered(SlidingWindowToolkit.IOrderedWindowVisitor callback, Iterator<IItem> items, IMemberAccessor<IQuantity,IItem> posAccessor, IQuantity windowSize, IQuantity slideSize)
Runs a sliding window through all items, looping through items once, removing from the start and adding and the end of a windowItem set to match the current time window. items.Suitable if the items are guaranteed to be ordered.
- Parameters:
callback
- method that can do calculations on the items in the windowitems
- input itemsposAccessor
- an accessor that should give a position value that is used with windowsSize and slideSizewindowSize
- size for the sliding windowslideSize
- how big the slide should be, if slideSize isnull
, it will slide one item at a time
-
slidingWindowUnordered
public static void slidingWindowUnordered(SlidingWindowToolkit.IUnorderedWindowVisitor callback, IItemCollection items, IQuantity windowSize, IQuantity slideSize)
Runs a sliding window through all items, by calculating the window start and end and filter through all the items. Suitable if the items are not guaranteed to be ordered, but is slower than the ordered version.- Parameters:
callback
- method that can do calculations on the items in the window.items
- input itemswindowSize
- size for the sliding windowslideSize
- how big the slide should be
-
slidingWindowUnordered
public static void slidingWindowUnordered(SlidingWindowToolkit.IUnorderedWindowVisitor callback, IItemCollection items, IQuantity windowSize, IQuantity slideSize, boolean includeIntersecting)
Runs a sliding window through all items, by calculating the window start and end and filter through all the items. Suitable if the items are not guaranteed to be ordered, but is slower than the ordered version.- Parameters:
callback
- method that can do calculations on the items in the window.items
- input itemswindowSize
- size for the sliding windowslideSize
- how big the slide should beincludeIntersecting
- if the window filter should include events intersecting the window, or just those with end time in the window. It's up to the caller to take this into account and for example cap event duration to the window timespan.
-
slidingWindowUnorderedMinMaxValue
public static Pair<IQuantity,IRange<IQuantity>> slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<IQuantity> valueFunction, boolean max, boolean includeIntersecting)
Calculates max/min window quantity value of items.- Parameters:
items
- items to use for evaluationwindowSize
- window sizecancellationSupplier
- if the evaluation should be cancelledvalueFunction
- provides the window value for itemsmax
- true to get the max value, false to get min valueincludeIntersecting
- true to include also intersecting items, false to only include contained items. If set to true, it's up to the valueFunction to only use the duration events that is actually included in the window.- Returns:
- min/max window value and range
-
slidingWindowUnorderedMinMaxValue
public static Pair<IQuantity,IRange<IQuantity>> slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, IQuantity slideSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<IQuantity> valueFunction, boolean max, boolean includeIntersecting)
Calculates max/min window quantity value of items.- Parameters:
items
- items to use for evaluationwindowSize
- window sizeslideSize
- window slide sizecancellationSupplier
- if the evaluation should be cancelledvalueFunction
- provides the window value for itemsmax
- true to get the max value, false to get min valueincludeIntersecting
- true to include also intersecting items, false to only include contained items. If set to true, it's up to the valueFunction to only use the duration events that is actually included in the window.- Returns:
- min/max window value and range
-
slidingWindowUnorderedMinMaxValue
public static <V> Pair<V,IRange<IQuantity>> slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<V> valueFunction, Comparator<V> valueComparator, boolean max, boolean includeIntersecting)
Calculates max/min window value of items.- Parameters:
items
- items to use for evaluationwindowSize
- window sizecancellationSupplier
- if the evaluation should be cancelledvalueFunction
- provides the window value for itemsvalueComparator
- compares valuesmax
- true to get the max value, false to get min valueincludeIntersecting
- true to include also intersecting items, false to only include contained items. If set to true, it's up to the valueFunction to only use the duration events that is actually included in the window.- Returns:
- min/max window value and range
-
slidingWindowUnorderedMinMaxValue
public static <V> Pair<V,IRange<IQuantity>> slidingWindowUnorderedMinMaxValue(IItemCollection items, IQuantity windowSize, IQuantity slideSize, FutureTask<IResult> cancellationSupplier, SlidingWindowToolkit.IUnorderedWindowValueFunction<V> valueFunction, Comparator<V> valueComparator, boolean max, boolean includeIntersecting)
Calculates max/min window value of items.- Parameters:
items
- items to use for evaluationwindowSize
- window sizeslideSize
- window slide sizecancellationSupplier
- if the evaluation should be cancelledvalueFunction
- provides the window value for itemsvalueComparator
- compares valuesmax
- true to get the max value, false to get min valueincludeIntersecting
- true to include also intersecting items, false to only include contained items. If set to true, it's up to the valueFunction to only use the duration events that is actually included in the window.- Returns:
- min/max window value and range
-
-