View Javadoc
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  
19  import java.util.function.IntPredicate;
20  import java.util.function.LongPredicate;
21  
22  /**
23   * An abstract class to assist in implementing Bloom filter decorators.
24   *
25   * @param <T> The WrappedBloomFilter type.
26   * @param <W> The <em>wrapped</em> BloomFilter type.
27   * @since 4.5.0-M1
28   */
29  public abstract class WrappedBloomFilter<T extends WrappedBloomFilter<T, W>, W extends BloomFilter<W>> implements BloomFilter<T> {
30  
31      private final W wrapped;
32  
33      /**
34       * Wraps a Bloom filter.  The wrapped filter is maintained as a reference
35       * not a copy.  Changes in one will be reflected in the other.
36       *
37       * @param wrapped The Bloom filter.
38       */
39      public WrappedBloomFilter(final W wrapped) {
40          this.wrapped = wrapped;
41      }
42  
43      @Override
44      public long[] asBitMapArray() {
45          return wrapped.asBitMapArray();
46      }
47  
48      @Override
49      public int[] asIndexArray() {
50          return wrapped.asIndexArray();
51      }
52  
53      @Override
54      public int cardinality() {
55          return wrapped.cardinality();
56      }
57  
58      @Override
59      public int characteristics() {
60          return wrapped.characteristics();
61      }
62  
63      @Override
64      public void clear() {
65          wrapped.clear();
66      }
67  
68      @Override
69      public boolean contains(final BitMapExtractor bitMapExtractor) {
70          return wrapped.contains(bitMapExtractor);
71      }
72  
73      @Override
74      public boolean contains(final BloomFilter<?> other) {
75          return wrapped.contains(other);
76      }
77  
78      @Override
79      public boolean contains(final Hasher hasher) {
80          return wrapped.contains(hasher);
81      }
82  
83      @Override
84      public boolean contains(final IndexExtractor indexExtractor) {
85          return wrapped.contains(indexExtractor);
86      }
87  
88      @Override
89      public int estimateIntersection(final BloomFilter<?> other) {
90          return wrapped.estimateIntersection(other);
91      }
92  
93      @Override
94      public int estimateN() {
95          return wrapped.estimateN();
96      }
97  
98      @Override
99      public int estimateUnion(final BloomFilter<?> other) {
100         return wrapped.estimateUnion(other);
101     }
102 
103     @Override
104     public Shape getShape() {
105         return wrapped.getShape();
106     }
107 
108     /**
109      * Gets the wrapped BloomFilter.
110      *
111      * @return the wrapped BloomFilter.
112      */
113     protected W getWrapped() {
114         return wrapped;
115     }
116 
117     @Override
118     public boolean isFull() {
119         return wrapped.isFull();
120     }
121 
122     @Override
123     public boolean merge(final BitMapExtractor bitMapExtractor) {
124         return wrapped.merge(bitMapExtractor);
125     }
126 
127     @Override
128     public boolean merge(final BloomFilter<?> other) {
129         return wrapped.merge(other);
130     }
131 
132     @Override
133     public boolean merge(final Hasher hasher) {
134         return wrapped.merge(hasher);
135     }
136 
137     @Override
138     public boolean merge(final IndexExtractor indexExtractor) {
139         return wrapped.merge(indexExtractor);
140     }
141 
142     @Override
143     public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
144         return wrapped.processBitMapPairs(other, func);
145     }
146 
147     @Override
148     public boolean processBitMaps(final LongPredicate predicate) {
149         return wrapped.processBitMaps(predicate);
150     }
151 
152     @Override
153     public boolean processIndices(final IntPredicate predicate) {
154         return wrapped.processIndices(predicate);
155     }
156 }