busbey commented on a change in pull request #2985:
URL: https://github.com/apache/hadoop/pull/2985#discussion_r631284867



##########
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Sets.java
##########
@@ -0,0 +1,311 @@
+/*
+ * 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.hadoop.util;
+
+import org.apache.hadoop.classification.InterfaceAudience;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Static utility methods pertaining to {@link Set} instances.
+ * This class is Hadoop's internal use alternative to Guava's Sets
+ * utility class.
+ */
+@InterfaceAudience.Private
+public class Sets {
+
+  /**
+   * Creates a <i>mutable</i>, initially empty {@code HashSet} instance.
+   *
+   * <p><b>Note:</b> if mutability is not required, use ImmutableSet#of() 
instead. If {@code
+   * E} is an {@link Enum} type, use {@link EnumSet#noneOf} instead. 
Otherwise, strongly consider
+   * using a {@code LinkedHashSet} instead, at the cost of increased memory 
footprint, to get
+   * deterministic iteration behavior.
+   */
+  public static <E> HashSet<E> newHashSet() {
+    return new HashSet<E>();
+  }
+
+  /**
+   * Creates a <i>mutable</i>, empty {@code TreeSet} instance sorted by the 
natural sort ordering of
+   * its elements.
+   *
+   * <p><b>Note:</b> if mutability is not required, use 
ImmutableSortedSet#of() instead.
+   *
+   * @return a new, empty {@code TreeSet}
+   */
+  public static <E extends Comparable> TreeSet<E> newTreeSet() {
+    return new TreeSet<E>();
+  }
+
+  /**
+   * Creates a <i>mutable</i> {@code HashSet} instance initially containing 
the given elements.
+   *
+   * <p><b>Note:</b> if elements are non-null and won't be added or removed 
after this point, use
+   * ImmutableSet#of() or ImmutableSet#copyOf(Object[]) instead. If {@code E} 
is an
+   * {@link Enum} type, use {@link EnumSet#of(Enum, Enum[])} instead. 
Otherwise, strongly consider
+   * using a {@code LinkedHashSet} instead, at the cost of increased memory 
footprint, to get
+   * deterministic iteration behavior.
+   *
+   * <p>This method is just a small convenience, either for {@code 
newHashSet(}{@link Arrays#asList
+   * asList}{@code (...))}, or for creating an empty set then calling {@link 
Collections#addAll}.
+   * This method is not actually very useful and will likely be deprecated in 
the future.
+   */
+  public static <E> HashSet<E> newHashSet(E... elements) {
+    HashSet<E> set = newHashSetWithExpectedSize(elements.length);
+    Collections.addAll(set, elements);
+    return set;
+  }

Review comment:
       I believe you can annotate this `@SafeVarargs` since we don't directly 
make use of the type of the elements array and `Collections.addAll` is already 
annotated as the same.
   
   That should clear up these javac complaints.




-- 
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:
us...@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to