Class LayerManager

java.lang.Object
org.apache.commons.collections4.bloomfilter.LayerManager
All Implemented Interfaces:
BloomFilterProducer

public class LayerManager extends Object implements BloomFilterProducer
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 LinkedList of BloomFilter that removes any expired or out dated filters from the list.

When extendCheck returns true the following steps are taken:

  1. Cleanup is called
  2. FilterSuplier is executed and the new filter added to the list as the target filter.
Since:
4.5
  • Method Details

    • builder

      public static LayerManager.Builder builder()
      Creates a new Builder with defaults of ExtendCheck.neverAdvance() and Cleanup.noCleanup().
      Returns:
      A builder.
      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

      public LayerManager copy()
      Creates a deep copy of this LayerManager.

      Filters in the copy are deep copies, not references, so changes in the copy are NOT reflected in the original.

      The filterSupplier, extendCheck, and the filterCleanup are shared between the copy and this instance.

      Returns:
      a copy of this layer Manager.
    • forEachBloomFilter

      public boolean forEachBloomFilter(Predicate<BloomFilter> bloomFilterPredicate)
      Executes a Bloom filter Predicate on each Bloom filter in the manager in depth order. Oldest filter first.
      Specified by:
      forEachBloomFilter in interface BloomFilterProducer
      Parameters:
      bloomFilterPredicate - the predicate to evaluate each Bloom filter with.
      Returns:
      false when the a filter fails the predicate test. Returns true if all filters pass the test.
    • get

      public final BloomFilter get(int depth)
      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()
      Returns the number of filters in the LayerManager. In the default LayerManager implementation there is alwasy at least one layer.
      Returns:
      the current depth.
    • getTarget

      public final BloomFilter getTarget()
      Returns the current target filter. If a new filter should be created based on extendCheck it will be created before this method returns.
      Returns:
      the current target filter after any extension.