    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 * @param <T> The WrappedBloomFilter type.
    026 * @param <W> The <em>wrapped</em> BloomFilter type.
    027 * @since 4.5.0-M1
    028 */
    029public abstract class WrappedBloomFilter<T extends WrappedBloomFilter<T, W>, W extends BloomFilter<W>> implements BloomFilter<T> {
    030
    031    private final W wrapped;
    032
    033    /**
    034     * Wraps a Bloom filter.  The wrapped filter is maintained as a reference
    035     * not a copy.  Changes in one will be reflected in the other.
    036     *
    037     * @param wrapped The Bloom filter.
    038     */
    039    public WrappedBloomFilter(final W wrapped) {
    040        this.wrapped = wrapped;
    041    }
    042
    043    @Override
    044    public long[] asBitMapArray() {
    045        return wrapped.asBitMapArray();
    046    }
    047
    048    @Override
    049    public int[] asIndexArray() {
    050        return wrapped.asIndexArray();
    051    }
    052
    053    @Override
    054    public int cardinality() {
    055        return wrapped.cardinality();
    056    }
    057
    058    @Override
    059    public int characteristics() {
    060        return wrapped.characteristics();
    061    }
    062
    063    @Override
    064    public void clear() {
    065        wrapped.clear();
    066    }
    067
    068    @Override
    069    public boolean contains(final BitMapExtractor bitMapExtractor) {
    070        return wrapped.contains(bitMapExtractor);
    071    }
    072
    073    @Override
    074    public boolean contains(final BloomFilter<?> other) {
    075        return wrapped.contains(other);
    076    }
    077
    078    @Override
    079    public boolean contains(final Hasher hasher) {
    080        return wrapped.contains(hasher);
    081    }
    082
    083    @Override
    084    public boolean contains(final IndexExtractor indexExtractor) {
    085        return wrapped.contains(indexExtractor);
    086    }
    087
    088    @Override
    089    public int estimateIntersection(final BloomFilter<?> other) {
    090        return wrapped.estimateIntersection(other);
    091    }
    092
    093    @Override
    094    public int estimateN() {
    095        return wrapped.estimateN();
    096    }
    097
    098    @Override
    099    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}