Class BucketSequencer<T>

  • Type Parameters:
    T - The element which is to be scheduled.
    All Implemented Interfaces:
    ElementSequencer<T>

    public class BucketSequencer<T>
    extends java.lang.Object
    implements ElementSequencer<T>

    Introduction

    This class allows you to create a cyclic schedule that will maintain a mix of elements according to individual ratios. This particular sequencer simulates the effect of drawing from each bucket in round robin order until they are empty, putting each event into the planned sequence in turn. While this is not a good way to evenly interleave events over a large number, it is easy to reason about when looking at ratios like A:5,B:3,C:1. In this case, the order of events would be A B C A B A B A A. #

    Explanation and Example

    Given a set of three events A, B, and C, and a set of respective frequencies of these events 5, 5, and 1. In short form: A:5,B:5,C:1. This means that a total of 11 events will be scheduled. With this sequencing algorithm, source buckets of events of type A, B, and C are initialized with the respective number of instances. Then, each bucket in turn is drawn from in round robin fashion, with each bucket being removed from the rotation when it becomes empty.

    Further Examples

    These examples simply show in symbolic terms how the ordering is affected by different ratios.

    • X:1,Y:1,Z:1 - X Y Z
    • L:4,M:1 - L M L L L
    • A:4,B:3,C:2,D:1 - A B C D A B C A B A
    • A:1,B:2:C:3:D:4 - A B C D B C D C D D
    • D:4,C:3,B:2,A:1 - D C B A D C B D C D
    • Constructor Summary

      Constructors 
      Constructor Description
      BucketSequencer()  
    • Method Summary

      Modifier and Type Method Description
      int[] seqIndexByRatioFunc​(java.util.List<T> elems, java.util.function.ToLongFunction<T> ratioFunc)  
      int[] seqIndexesByRatios​(java.util.List<T> elems, java.util.List<java.lang.Long> ratios)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BucketSequencer

        public BucketSequencer()
    • Method Detail

      • seqIndexByRatioFunc

        public int[] seqIndexByRatioFunc​(java.util.List<T> elems,
                                         java.util.function.ToLongFunction<T> ratioFunc)
        Specified by:
        seqIndexByRatioFunc in interface ElementSequencer<T>
      • seqIndexesByRatios

        public int[] seqIndexesByRatios​(java.util.List<T> elems,
                                        java.util.List<java.lang.Long> ratios)
        Specified by:
        seqIndexesByRatios in interface ElementSequencer<T>