T
- the List type representing the stacks to be leveledE
- the type of the elements of each Listpublic final class LevelingDownsampler<T extends java.util.List<E>,E> extends Downsampler<T>
Constructor and Description |
---|
LevelingDownsampler(long targetSize)
Construct a LevelingDownsampler
Uses the default minElementsPerStack of 1
|
LevelingDownsampler(long targetSize,
int minElementsPerStack)
Construct a LevelingDownsampler
|
Modifier and Type | Method and Description |
---|---|
void |
clearItems()
Empty the downsampler of all finalized/pending items
|
java.util.List<T> |
consumeFinalizedItems()
Return (and *remove*) all items that have survived downsampling and are waiting to be retrieved.
|
boolean |
hasFinalizedItems()
Are there items that have survived the downsampling process waiting to be retrieved?
|
boolean |
hasPendingItems()
Are there items stored in this downsampler that it doesn't yet know whether they will
ultimately survive the downsampling process?
|
T |
peekFinalized()
Peek at the first finalized item stored in this downsampler (or null if there are no finalized items)
|
T |
peekPending()
Peek at the first pending item stored in this downsampler (or null if there are no pending items)
|
void |
signalEndOfInput()
Used to tell the downsampler that no more items will be submitted to it, and that it should
finalize any pending items.
|
int |
size()
Get the current number of items in this downsampler
This should be the best estimate of the total number of elements that will come out of the downsampler
were consumeFinalizedItems() to be called immediately after this call.
|
void |
submit(java.util.Collection<T> items)
Submit a collection of items to the downsampler for consideration.
|
void |
submit(T item)
Submit one item to the downsampler for consideration.
|
getNumberOfDiscardedItems, incrementNumberOfDiscardedItems, resetStats
public LevelingDownsampler(long targetSize)
targetSize
- the sum of the sizes of all individual Lists this downsampler is fed may not exceed
this value -- if it does, items are removed from Lists evenly until the total size
is <= this valuepublic LevelingDownsampler(long targetSize, int minElementsPerStack)
targetSize
- the sum of the sizes of all individual Lists this downsampler is fed may not exceed
this value -- if it does, items are removed from Lists evenly until the total size
is <= this valueminElementsPerStack
- no stack will be reduced below this size during downsampling. That is,
if a stack has only 3 elements and minElementsPerStack is 3, no matter what
we'll not reduce this stack below 3.public void submit(T item)
Downsampler
submit
in interface PushPullTransformer<T extends java.util.List<E>>
submit
in class Downsampler<T extends java.util.List<E>>
item
- the individual item to submit to the downsampler for considerationpublic void submit(java.util.Collection<T> items)
Downsampler
submit
in interface PushPullTransformer<T extends java.util.List<E>>
submit
in class Downsampler<T extends java.util.List<E>>
items
- the collection of items to submit to the downsampler for considerationpublic boolean hasFinalizedItems()
Downsampler
hasFinalizedItems
in interface PushPullTransformer<T extends java.util.List<E>>
hasFinalizedItems
in class Downsampler<T extends java.util.List<E>>
public java.util.List<T> consumeFinalizedItems()
Downsampler
consumeFinalizedItems
in interface PushPullTransformer<T extends java.util.List<E>>
consumeFinalizedItems
in class Downsampler<T extends java.util.List<E>>
public boolean hasPendingItems()
Downsampler
hasPendingItems
in class Downsampler<T extends java.util.List<E>>
public T peekFinalized()
Downsampler
peekFinalized
in class Downsampler<T extends java.util.List<E>>
public T peekPending()
Downsampler
peekPending
in class Downsampler<T extends java.util.List<E>>
public int size()
Downsampler
size
in class Downsampler<T extends java.util.List<E>>
public void signalEndOfInput()
Downsampler
signalEndOfInput
in interface PushPullTransformer<T extends java.util.List<E>>
signalEndOfInput
in class Downsampler<T extends java.util.List<E>>
public void clearItems()
Downsampler
clearItems
in class Downsampler<T extends java.util.List<E>>