WrappedBloomFilter.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.collections4.bloomfilter;

  18. import java.util.function.IntPredicate;
  19. import java.util.function.LongPredicate;

  20. /**
  21.  * An abstract class to assist in implementing Bloom filter decorators.
  22.  *
  23.  * @param <T> The WrappedBloomFilter type.
  24.  * @param <W> The <em>wrapped</em> BloomFilter type.
  25.  * @since 4.5.0-M1
  26.  */
  27. public abstract class WrappedBloomFilter<T extends WrappedBloomFilter<T, W>, W extends BloomFilter<W>> implements BloomFilter<T> {

  28.     private final W wrapped;

  29.     /**
  30.      * Wraps a Bloom filter.  The wrapped filter is maintained as a reference
  31.      * not a copy.  Changes in one will be reflected in the other.
  32.      *
  33.      * @param wrapped The Bloom filter.
  34.      */
  35.     public WrappedBloomFilter(final W wrapped) {
  36.         this.wrapped = wrapped;
  37.     }

  38.     @Override
  39.     public long[] asBitMapArray() {
  40.         return wrapped.asBitMapArray();
  41.     }

  42.     @Override
  43.     public int[] asIndexArray() {
  44.         return wrapped.asIndexArray();
  45.     }

  46.     @Override
  47.     public int cardinality() {
  48.         return wrapped.cardinality();
  49.     }

  50.     @Override
  51.     public int characteristics() {
  52.         return wrapped.characteristics();
  53.     }

  54.     @Override
  55.     public void clear() {
  56.         wrapped.clear();
  57.     }

  58.     @Override
  59.     public boolean contains(final BitMapExtractor bitMapExtractor) {
  60.         return wrapped.contains(bitMapExtractor);
  61.     }

  62.     @Override
  63.     public boolean contains(final BloomFilter<?> other) {
  64.         return wrapped.contains(other);
  65.     }

  66.     @Override
  67.     public boolean contains(final Hasher hasher) {
  68.         return wrapped.contains(hasher);
  69.     }

  70.     @Override
  71.     public boolean contains(final IndexExtractor indexExtractor) {
  72.         return wrapped.contains(indexExtractor);
  73.     }

  74.     @Override
  75.     public int estimateIntersection(final BloomFilter<?> other) {
  76.         return wrapped.estimateIntersection(other);
  77.     }

  78.     @Override
  79.     public int estimateN() {
  80.         return wrapped.estimateN();
  81.     }

  82.     @Override
  83.     public int estimateUnion(final BloomFilter<?> other) {
  84.         return wrapped.estimateUnion(other);
  85.     }

  86.     @Override
  87.     public Shape getShape() {
  88.         return wrapped.getShape();
  89.     }

  90.     /**
  91.      * Gets the wrapped BloomFilter.
  92.      *
  93.      * @return the wrapped BloomFilter.
  94.      */
  95.     protected W getWrapped() {
  96.         return wrapped;
  97.     }

  98.     @Override
  99.     public boolean isFull() {
  100.         return wrapped.isFull();
  101.     }

  102.     @Override
  103.     public boolean merge(final BitMapExtractor bitMapExtractor) {
  104.         return wrapped.merge(bitMapExtractor);
  105.     }

  106.     @Override
  107.     public boolean merge(final BloomFilter<?> other) {
  108.         return wrapped.merge(other);
  109.     }

  110.     @Override
  111.     public boolean merge(final Hasher hasher) {
  112.         return wrapped.merge(hasher);
  113.     }

  114.     @Override
  115.     public boolean merge(final IndexExtractor indexExtractor) {
  116.         return wrapped.merge(indexExtractor);
  117.     }

  118.     @Override
  119.     public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
  120.         return wrapped.processBitMapPairs(other, func);
  121.     }

  122.     @Override
  123.     public boolean processBitMaps(final LongPredicate predicate) {
  124.         return wrapped.processBitMaps(predicate);
  125.     }

  126.     @Override
  127.     public boolean processIndices(final IntPredicate predicate) {
  128.         return wrapped.processIndices(predicate);
  129.     }
  130. }