virajjasani commented on a change in pull request #2985: URL: https://github.com/apache/hadoop/pull/2985#discussion_r633057797
########## File path: hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Sets.java ########## @@ -0,0 +1,329 @@ +/* + * 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 final class Sets { + + private Sets() { + // empty + } + + /** + * 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>(); + } Review comment: I think yes it makes sense but other than hadoop-common and hadoop-tools, many modules are dependent on these methods quite heavily. Perhaps making them use "new Hash/TreeSet<>()" directly can be taken up as follow-up task? As part of removal of Guava dependency, if we just update imports from guava to internal Sets class, that would be quite clean. WDYT? -- 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