Class SlidingWindowToolkit


  • public class SlidingWindowToolkit
    extends Object
    Utility functions and interfaces for doing sliding window calculations.
    • Constructor Detail

      • SlidingWindowToolkit

        public SlidingWindowToolkit()
    • 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 window
        items - input items
        posAccessor - an accessor that should give a position value that is used with windowsSize and slideSize
        windowSize - size for the sliding window
        slideSize - how big the slide should be, if slideSize is null, 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 items
        windowSize - size for the sliding window
        slideSize - 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 items
        windowSize - size for the sliding window
        slideSize - how big the slide should be
        includeIntersecting - 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 evaluation
        windowSize - window size
        cancellationSupplier - if the evaluation should be cancelled
        valueFunction - provides the window value for items
        max - true to get the max value, false to get min value
        includeIntersecting - 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 evaluation
        windowSize - window size
        slideSize - window slide size
        cancellationSupplier - if the evaluation should be cancelled
        valueFunction - provides the window value for items
        max - true to get the max value, false to get min value
        includeIntersecting - 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 evaluation
        windowSize - window size
        cancellationSupplier - if the evaluation should be cancelled
        valueFunction - provides the window value for items
        valueComparator - compares values
        max - true to get the max value, false to get min value
        includeIntersecting - 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 evaluation
        windowSize - window size
        slideSize - window slide size
        cancellationSupplier - if the evaluation should be cancelled
        valueFunction - provides the window value for items
        valueComparator - compares values
        max - true to get the max value, false to get min value
        includeIntersecting - 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