Class LayerManager<T extends BloomFilter<T>>
java.lang.Object
org.apache.commons.collections4.bloomfilter.LayerManager<T>
- Type Parameters:
T- theBloomFiltertype.
- All Implemented Interfaces:
BloomFilterExtractor
Implementation of the methods to manage the layers in a layered Bloom filter.
The manager comprises a list of Bloom filters that are managed based on
various rules. The last filter in the list is known as the target and
is the filter into which merges are performed. The Layered manager utilizes
three methods to manage the list.
- ExtendCheck - A Predicate that if true causes a new Bloom filter to be created as the new target.
- FilterSupplier - A Supplier that produces empty Bloom filters to be used as a new target.
- Cleanup - A Consumer of a
LinkedListof BloomFilter that removes any expired or out dated filters from the list.
When extendCheck returns true the following steps are taken:
Cleanupis calledFilterSuplieris executed and the new filter added to the list as thetargetfilter.
- Since:
- 4.5.0-M1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classLayerManager.Builder<T extends BloomFilter<T>>Builds new instances ofLayerManager.static final classStatic methods to create a Consumer of a List of BloomFilter perform tests on whether to reduce the collection of Bloom filters.static final classA collection of common ExtendCheck implementations to test whether to extend the depth of a LayerManager. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Predicate<LayerManager<T>> private final LinkedList<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateLayerManager(Supplier<T> filterSupplier, Predicate<LayerManager<T>> extendCheck, Consumer<Deque<T>> filterCleanup, boolean initialize) Constructs a new instance. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidAdds a new Bloom filter to the list.static <T extends BloomFilter<T>>
LayerManager.Builder<T> builder()Creates a new Builder with defaults ofLayerManager.ExtendCheck.neverAdvance()andLayerManager.Cleanup.noCleanup().(package private) voidcleanup()Forces execution the configured cleanup without creating a new filter except in cases where the cleanup removes all the layers.final voidclear()Removes all the filters from the layer manager, and sets up a new one as the target.copy()Creates a deep copy of thisLayerManager.final Tfirst()Gets the Bloom filter from the first layer.final Tget(int depth) Gets the Bloom filter at the specified depth.final intgetDepth()Gets the number of filters in the LayerManager.final TGets the current target filter.final Tlast()Gets the Bloom filter from the last layer.(package private) voidnext()Forces an advance to the next depth.booleanprocessBloomFilters(Predicate<BloomFilter> bloomFilterPredicate) Executes a Bloom filter Predicate on each Bloom filter in the manager in depth order.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.collections4.bloomfilter.BloomFilterExtractor
asBloomFilterArray, flatten, processBloomFilterPair
-
Field Details
-
filters
-
filterCleanup
-
extendCheck
-
filterSupplier
-
-
Constructor Details
-
LayerManager
private LayerManager(Supplier<T> filterSupplier, Predicate<LayerManager<T>> extendCheck, Consumer<Deque<T>> filterCleanup, boolean initialize) Constructs a new instance.- Parameters:
filterSupplier- the non-null supplier of new Bloom filters to add the the list when necessary.extendCheck- The non-null predicate that checks if a new filter should be added to the list.filterCleanup- the non-null consumer that removes any old filters from the list.initialize- true if the filter list should be initialized.
-
-
Method Details
-
builder
Creates a new Builder with defaults ofLayerManager.ExtendCheck.neverAdvance()andLayerManager.Cleanup.noCleanup().- Type Parameters:
T- Type of BloomFilter.- Returns:
- A builder.
- See Also:
-
addFilter
private void addFilter()Adds a new Bloom filter to the list. -
cleanup
void cleanup()Forces execution the configured cleanup without creating a new filter except in cases where the cleanup removes all the layers.- See Also:
-
clear
public final void clear()Removes all the filters from the layer manager, and sets up a new one as the target. -
copy
Creates a deep copy of thisLayerManager.Filters in the copy are deep copies, not references, so changes in the copy are NOT reflected in the original.
The
filterSupplier,extendCheck, and thefilterCleanupare shared between the copy and this instance.- Returns:
- a copy of this
LayerManager.
-
first
Gets the Bloom filter from the first layer. No extension check is performed during this call.- Returns:
- The Bloom filter from the first layer.
- See Also:
-
get
Gets the Bloom filter at the specified depth. The filter at depth 0 is the oldest filter.- Parameters:
depth- the depth at which the desired filter is to be found.- Returns:
- the filter.
- Throws:
NoSuchElementException- if depth is not in the range [0,filters.size())
-
getDepth
public final int getDepth()Gets the number of filters in the LayerManager. In the default LayerManager implementation there is always at least one layer.- Returns:
- the current depth.
-
getTarget
Gets the current target filter. If a new filter should be created based onextendCheckit will be created before this method returns.- Returns:
- the current target filter after any extension.
-
last
Gets the Bloom filter from the last layer. No extension check is performed during this call.- Returns:
- The Bloom filter from the last layer.
- See Also:
-
next
void next()Forces an advance to the next depth. This method will clean-up the current layers and generate a new filter layer. In most cases is it unnecessary to call this method directly.Ths method is used within
getTarget()when the configuredExtendCheckreturnstrue.- See Also:
-
processBloomFilters
Executes a Bloom filter Predicate on each Bloom filter in the manager in depth order. Oldest filter first.- Specified by:
processBloomFiltersin interfaceBloomFilterExtractor- Parameters:
bloomFilterPredicate- the predicate to evaluate each Bloom filter with.- Returns:
falsewhen the a filter fails the predicate test. Returnstrueif all filters pass the test.
-