001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections4.bloomfilter;
018
019import java.util.function.IntPredicate;
020import java.util.function.LongPredicate;
021
022/**
023 * An abstract class to assist in implementing Bloom filter decorators.
024 *
025 * @since 4.5
026 */
027public abstract class WrappedBloomFilter implements BloomFilter {
028    private final BloomFilter wrapped;
029
030    /**
031     * Wraps a Bloom filter.  The wrapped filter is maintained as a reference
032     * not a copy.  Changes in one will be reflected in the other.
033     * @param bf The Bloom filter.
034     */
035    public WrappedBloomFilter(final BloomFilter bf) {
036        this.wrapped = bf;
037    }
038
039    @Override
040    public long[] asBitMapArray() {
041        return wrapped.asBitMapArray();
042    }
043
044    @Override
045    public int[] asIndexArray() {
046        return wrapped.asIndexArray();
047    }
048
049    @Override
050    public int cardinality() {
051        return wrapped.cardinality();
052    }
053
054    @Override
055    public int characteristics() {
056        return wrapped.characteristics();
057    }
058
059    @Override
060    public void clear() {
061        wrapped.clear();
062    }
063
064    @Override
065    public boolean contains(final BitMapExtractor bitMapExtractor) {
066        return wrapped.contains(bitMapExtractor);
067    }
068
069    @Override
070    public boolean contains(final BloomFilter other) {
071        return wrapped.contains(other);
072    }
073
074    @Override
075    public boolean contains(final Hasher hasher) {
076        return wrapped.contains(hasher);
077    }
078
079    @Override
080    public boolean contains(final IndexExtractor indexExtractor) {
081        return wrapped.contains(indexExtractor);
082    }
083
084    @Override
085    public int estimateIntersection(final BloomFilter other) {
086        return wrapped.estimateIntersection(other);
087    }
088
089    @Override
090    public int estimateN() {
091        return wrapped.estimateN();
092    }
093
094    @Override
095    public int estimateUnion(final BloomFilter other) {
096        return wrapped.estimateUnion(other);
097    }
098
099    @Override
100    public boolean processBitMaps(final LongPredicate predicate) {
101        return wrapped.processBitMaps(predicate);
102    }
103
104    @Override
105    public boolean processBitMapPairs(final BitMapExtractor other, final LongBiPredicate func) {
106        return wrapped.processBitMapPairs(other, func);
107    }
108
109    @Override
110    public boolean processIndices(final IntPredicate predicate) {
111        return wrapped.processIndices(predicate);
112    }
113
114    @Override
115    public Shape getShape() {
116        return wrapped.getShape();
117    }
118
119    protected BloomFilter getWrapped() {
120        return wrapped;
121    }
122
123    @Override
124    public boolean isFull() {
125        return wrapped.isFull();
126    }
127
128    @Override
129    public boolean merge(final BitMapExtractor bitMapExtractor) {
130        return wrapped.merge(bitMapExtractor);
131    }
132
133    @Override
134    public boolean merge(final BloomFilter other) {
135        return wrapped.merge(other);
136    }
137
138    @Override
139    public boolean merge(final Hasher hasher) {
140        return wrapped.merge(hasher);
141    }
142
143    @Override
144    public boolean merge(final IndexExtractor indexExtractor) {
145        return wrapped.merge(indexExtractor);
146    }
147}