KT-729 Need to support arrays as varargs
This commit is contained in:
@@ -19,6 +19,8 @@ package jet.runtime;
|
||||
import jet.Function0;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
@@ -82,4 +84,36 @@ public class Intrinsics {
|
||||
return sanitizeStackTrace(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpreadBuilder extends ArrayList {
|
||||
public void addSpread(Object array) {
|
||||
if(array != null) {
|
||||
if(array instanceof Object[]) {
|
||||
Object[] arr = (Object[]) array;
|
||||
if(arr.length > 0) {
|
||||
ensureCapacity(size() + arr.length);
|
||||
for (int i = 0; i < arr.length; i++) {
|
||||
add(arr[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(array instanceof Collection) {
|
||||
addAll((Collection) array);
|
||||
}
|
||||
else if(array instanceof Iterable) {
|
||||
for(Iterator iterator = ((Iterable) array).iterator(); iterator.hasNext(); ) {
|
||||
add(iterator.next());
|
||||
}
|
||||
}
|
||||
else if(array instanceof Iterator) {
|
||||
for(Iterator iterator = ((Iterator) array); iterator.hasNext(); ) {
|
||||
add(iterator.next());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("Don't know how to spread " + array.getClass());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user