MCPcopy Index your code
hub / github.com/apache/groovy / concat

Method concat

src/main/java/org/apache/groovy/util/Arrays.java:38–60  ·  view source on GitHub ↗

Concatenate arrays and ignore null array @param arrays arrays to merge @param array component type @return the concatenated array

(T[]... arrays)

Source from the content-addressed store, hash-verified

36 * @return the concatenated array
37 */
38 @SuppressWarnings("unchecked")
39 public static <T> T[] concat(T[]... arrays) {
40 if (null == arrays || 0 == arrays.length) return null;
41
42 int resultLength =
43 java.util.Arrays.stream(arrays)
44 .filter(Objects::nonNull)
45 .map(e -> e.length)
46 .reduce(0, Integer::sum);
47 T[] resultArray = (T[]) Array.newInstance(arrays[0].getClass().getComponentType(), resultLength);
48
49 for (int i = 0, n = arrays.length, curr = 0; i < n; i++) {
50 T[] array = arrays[i];
51
52 if (null == array) continue;
53
54 int length = array.length;
55 System.arraycopy(array, 0, resultArray, curr, length);
56 curr += length;
57 }
58
59 return resultArray;
60 }
61
62 private Arrays() {}
63}

Callers 12

testConcat0Method · 0.95
testConcat1Method · 0.95
testConcat2Method · 0.95
testConcat3Method · 0.95
testConcat4Method · 0.95
testConcat5Method · 0.95
lsMethod · 0.45
unionAllMethod · 0.45
MetaClassImplMethod · 0.45
wbFunction · 0.45
UbFunction · 0.45

Calls 7

getClassMethod · 0.80
arraycopyMethod · 0.80
mapMethod · 0.65
filterMethod · 0.65
streamMethod · 0.65
newInstanceMethod · 0.65
getComponentTypeMethod · 0.45

Tested by 6

testConcat0Method · 0.76
testConcat1Method · 0.76
testConcat2Method · 0.76
testConcat3Method · 0.76
testConcat4Method · 0.76
testConcat5Method · 0.76