Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,15 @@ public final <T> JavaRDD<T> union(JavaRDD<T>... rdds) {
if (rdds.length == 0) {
throw new IllegalArgumentException("Union called on empty list");
}
List<JavaRDD<T>> rest = new ArrayList<>(rdds.length - 1);
for (int i = 1; i < rdds.length; i++) {
rest.add(rdds[i]);
}
rest = populateRDDList(rdds);
return union(rdds[0], rest);
}

public JavaDoubleRDD union(JavaDoubleRDD... rdds) {
if (rdds.length == 0) {
throw new IllegalArgumentException("Union called on empty list");
}
List<JavaDoubleRDD> rest = new ArrayList<>(rdds.length - 1);
for (int i = 1; i < rdds.length; i++) {
rest.add(rdds[i]);
}
rest = populateRDDList(rdds);
return union(rdds[0], rest);
}

Expand All @@ -58,6 +52,14 @@ public final <K, V> JavaPairRDD<K, V> union(JavaPairRDD<K, V>... rdds) {
}
return union(rdds[0], rest);
}

public final List<T> populateRDDList(T rdds) {
Copy link
Member

@srowen srowen Jul 29, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, pretty trivial but a win. You can use this in line 49 too right? and this can be static

List<T> rest = new ArrayList<>(rdds.length - 1);
for (int i = 1; i < rdds.length; i++) {
rest.add(rdds[i]);
}
return rdds;
}

// These methods take separate "first" and "rest" elements to avoid having the same type erasure
public abstract <T> JavaRDD<T> union(JavaRDD<T> first, List<JavaRDD<T>> rest);
Expand Down