nastra commented on code in PR #11322:
URL: https://github.com/apache/iceberg/pull/11322#discussion_r2607890485


##########
api/src/main/java/org/apache/iceberg/util/CharSequenceSet.java:
##########
@@ -18,183 +18,53 @@
  */
 package org.apache.iceberg.util;
 
-import java.io.Serializable;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Set;
-import java.util.stream.Collectors;
-import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
 import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
-import org.apache.iceberg.relocated.com.google.common.collect.Iterators;
-import org.apache.iceberg.relocated.com.google.common.collect.Sets;
-import org.apache.iceberg.relocated.com.google.common.collect.Streams;
 
-public class CharSequenceSet implements Set<CharSequence>, Serializable {
+public class CharSequenceSet extends WrapperSet<CharSequence> {
   private static final ThreadLocal<CharSequenceWrapper> WRAPPERS =
       ThreadLocal.withInitial(() -> CharSequenceWrapper.wrap(null));
 
-  public static CharSequenceSet of(Iterable<CharSequence> charSequences) {
-    return new CharSequenceSet(charSequences);
-  }
-
-  public static CharSequenceSet empty() {
-    return new CharSequenceSet(ImmutableList.of());
-  }
-
-  private final Set<CharSequenceWrapper> wrapperSet;
-
-  private CharSequenceSet(Iterable<CharSequence> charSequences) {
-    this.wrapperSet =
-        Sets.newHashSet(Iterables.transform(charSequences, 
CharSequenceWrapper::wrap));
+  private CharSequenceSet() {
+    // needed for serialization
   }
 
-  @Override
-  public int size() {
-    return wrapperSet.size();
+  private CharSequenceSet(Iterable<? extends CharSequence> charSequences) {
+    super(
+        Iterables.transform(
+            charSequences,
+            obj -> {
+              Preconditions.checkNotNull(obj, "Invalid object: null");
+              return CharSequenceWrapper.wrap(obj);
+            }));
   }
 
-  @Override
-  public boolean isEmpty() {
-    return wrapperSet.isEmpty();
+  public static CharSequenceSet of(Iterable<? extends CharSequence> 
charSequences) {
+    return new CharSequenceSet(charSequences);
   }
 
-  @Override
-  public boolean contains(Object obj) {
-    if (obj instanceof CharSequence) {
-      CharSequenceWrapper wrapper = WRAPPERS.get();
-      boolean result = wrapperSet.contains(wrapper.set((CharSequence) obj));
-      wrapper.set(null); // don't hold a reference to the value
-      return result;
-    }
-    return false;
+  public static CharSequenceSet empty() {
+    return new CharSequenceSet();

Review Comment:
   we can't do that because `empty()` is expected to be a modifiable set and 
making this static will lead to reusing the same Set instance across different 
places. The equivalent in `DataFileSet` is `create()`, but here we historically 
have `empty()`. We could however deprecate that method and introduce 
`create()`, but this would cause a non-minor diff so I'd leave that to a 
separate PR



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to