in src/main/java/net/hydromatic/linq4j/expressions/Primitive.java [323:377]
public Object toArray(Collection collection) {
int i = 0;
switch (this) {
case DOUBLE:
double[] doubles = new double[collection.size()];
for (double v : (Collection<Double>) collection) {
doubles[i++] = v;
}
return doubles;
case FLOAT:
float[] floats = new float[collection.size()];
for (float v : (Collection<Float>) collection) {
floats[i++] = v;
}
return floats;
case INT:
int[] ints = new int[collection.size()];
for (int v : (Collection<Integer>) collection) {
ints[i++] = v;
}
return ints;
case LONG:
long[] longs = new long[collection.size()];
for (long v : (Collection<Long>) collection) {
longs[i++] = v;
}
return longs;
case SHORT:
short[] shorts = new short[collection.size()];
for (short v : (Collection<Short>) collection) {
shorts[i++] = v;
}
return shorts;
case BOOLEAN:
boolean[] booleans = new boolean[collection.size()];
for (boolean v : (Collection<Boolean>) collection) {
booleans[i++] = v;
}
return booleans;
case BYTE:
byte[] bytes = new byte[collection.size()];
for (byte v : (Collection<Byte>) collection) {
bytes[i++] = v;
}
return bytes;
case CHAR:
char[] chars = new char[collection.size()];
for (char v : (Collection<Character>) collection) {
chars[i++] = v;
}
return chars;
default:
throw new RuntimeException("unexpected: " + this);
}
}