aherbert commented on a change in pull request #160:
URL: 
https://github.com/apache/commons-collections/pull/160#discussion_r425908912



##########
File path: 
src/main/java/org/apache/commons/collections4/bloomfilter/SimpleBloomFilter.java
##########
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.collections4.bloomfilter;
+
+import java.util.function.Function;
+
+import org.apache.commons.collections4.bloomfilter.hasher.DynamicHasher;
+import org.apache.commons.collections4.bloomfilter.hasher.Hasher;
+import org.apache.commons.collections4.bloomfilter.hasher.Shape;
+import 
org.apache.commons.collections4.bloomfilter.hasher.function.Murmur128x64Cyclic;
+
+/**
+ * A bloom filter that uses a BitSetBloomFilter to create a Bloom filter that
+ * can merge instances of a specific class.
+ *
+ * @param <T> The Class to merge.
+ * @since 4.5
+ */
+public class SimpleBloomFilter<T> extends BitSetBloomFilter implements 
BloomFilter {
+
+    /**
+     * The function that converts the instance of T to the SimpleBuilder.
+     * <p>
+     * If the object T is to be considered as a single item in the filter then
+     * function must create the {@code SimpleBuilder} and only call a single 
{@code with()}
+     * method.</p>
+     * <p>
+     * If the object T is to be considered as several items then the function 
must
+     * create the {@code SimpleBuilder} and call the {@code with()} method 
once for each item.</p>
+     */
+    private Function<T, SimpleBuilder> func;
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape and function.  This 
constructor
+     * creates an empty Bloom filter.
+     * @param hasher the Hasher to use.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @see #func
+     */
+    public SimpleBloomFilter(Hasher hasher, Shape shape, Function<T, 
SimpleBuilder> func) {
+        super(hasher, shape);
+        this.func = func;
+    }
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape and function.  This 
constructor
+     * creates an empty Bloom filter.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @see #func
+     */
+    public SimpleBloomFilter(Shape shape, Function<T, SimpleBuilder> func) {
+        super(shape);
+        this.func = func;
+    }
+
+    /**
+     * Constructs a SimpleBloomFilter from the shape, function and a data 
object.
+     * This constructor creates an Bloom filter populated with the data from 
the
+     * {@code data} parameter.
+     * @param shape the Shape of the Bloom filter.
+     * @param func a Function to convert T to a SimpleBuilder.
+     * @param data the data object to populate the filter with.
+     * @see #func
+     */
+    public SimpleBloomFilter(Shape shape, Function<T, SimpleBuilder> func, T 
data) {
+        this(shape, func);
+        this.merge( data );

Review comment:
       I am more asking to remove clutter from the API. It does not seem 
essential to me to have this constructor that saves 1 line of code.
   
   When using a Bloom filter it would be expected to add hundreds or thousands 
of items. This will be done in a loop or over time by a method. Adding a single 
item at the creation point is a drop in the ocean against the final result of 
the saturated filter.
   
   This is where my example of the ArrayList comes in (or any collection for 
that matter). There are no collections in the JDK that are created with an item 
except the singleton specialisations. Thus the language do not see this as a 
common case to satisfy. I'd suggest dropping the constructor that takes an item.
   
   I would not add a constructor that accepts a Bloom filter since that also 
only saves 1 line of code over just calling merge on the next line.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to