laurentgo commented on a change in pull request #11063:
URL: https://github.com/apache/arrow/pull/11063#discussion_r700668677
##########
File path:
java/memory/memory-core/src/main/java/org/apache/arrow/util/Collections2.java
##########
@@ -46,23 +45,55 @@ private Collections2() {}
* Converts the iterable into a new {@link List}.
*/
public static <T> List<T> toList(Iterable<T> iterable) {
- return StreamSupport.stream(iterable.spliterator(),
false).collect(Collectors.toList());
+ if (iterable instanceof Collection<?>) {
+ // If iterable is a collection, take advantage of it for a more
efficient copy
+ return new ArrayList<T>((Collection<T>) iterable);
+ }
+ return toList(iterable.iterator());
}
+ /**
+ * Converts the iterable into a new immutable {@link List}.
+ */
+ public static <T> List<T> toImmutableList(Iterable<T> iterable) {
+ return Collections.unmodifiableList(toList(iterable));
+ }
+
+
/** Copies the elements of <code>map</code> to a new unmodifiable map. */
public static <K, V> Map<K, V> immutableMapCopy(Map<K, V> map) {
- Map<K, V> newMap = new HashMap<>();
- newMap.putAll(map);
- return java.util.Collections.unmodifiableMap(newMap);
+ return Collections.unmodifiableMap(new HashMap<>(map));
}
/** Copies the elements of list to a new unmodifiable list. */
public static <V> List<V> immutableListCopy(List<V> list) {
- return
Collections.unmodifiableList(list.stream().collect(Collectors.toList()));
+ return Collections.unmodifiableList(new ArrayList<>(list));
}
/** Copies the values to a new unmodifiable list. */
public static <V> List<V> asImmutableList(V...values) {
return Collections.unmodifiableList(Arrays.asList(values));
}
+
+ /**
+ * Creates a human readable string from the remaining elements in iterator.
+ *
+ * The output should be similar to {@code Arrays#toString(Object[])}
+ */
+ public static String toString(Iterator<?> iterator) {
+ if (!iterator.hasNext()) {
Review comment:
Added a commit to change it
--
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]