nfsantos commented on code in PR #1690:
URL: https://github.com/apache/jackrabbit-oak/pull/1690#discussion_r1750084935
##########
oak-commons/src/main/java/org/apache/jackrabbit/oak/commons/collections/CollectionUtils.java:
##########
@@ -75,10 +86,91 @@ public static <T> Set<T> toSet(final Iterable<T> iterable) {
* @return the set
* @param <T> the type of the elements
*/
- public static <T> Set<T> toSet(final Iterator<T> iterator) {
+ @NotNull
+ public static <T> Set<T> toSet(@NotNull final Iterator<T> iterator) {
+ Objects.requireNonNull(iterator);
final Set<T> result = new HashSet<>();
iterator.forEachRemaining(result::add);
return result;
}
-}
+ /**
+ * Convert a vararg list of items to a set. The returning set is mutable
and supports all optional operations.
+ * @param elements elements to convert
+ * @return the set
+ * @param <T> the type of the elements
+ */
+ @SafeVarargs
+ @NotNull
+ public static <T> Set<T> toSet(@NotNull final T... elements) {
+ Objects.requireNonNull(elements);
+ // make sure the set does not need to be resized given the initial
content
+ float loadFactor = (float) 0.75; // HashSet default
+ int initialCapacity = 1 + (int) (elements.length / loadFactor);
+ final Set<T> result = new HashSet<>(initialCapacity, loadFactor);
+ for (T element : elements) {
+ result.add(element);
+ }
+ return result;
+ }
+
+ /**
+ * Convert an {@code Iterator} to an {@code Iterable}.
+ * <p>
+ * This method is not thread-safe
Review Comment:
This is not accurate. The method is thread-safe, it can be called
concurrently without any problems. But the Iterable returned is not thread
safe. It's a really minor issue.
--
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]