mirror of
https://github.com/bitfireAT/davx5-ose.git
synced 2026-09-12 22:29:39 -04:00
* update to Lombok 1.16.4 and dnsjava 2.1.7 * optimize imports and copyrights * delete Note data class (will be implemented later)
34 lines
1009 B
Java
34 lines
1009 B
Java
/*
|
||
* Copyright © 2013 – 2015 Ricki Hirner (bitfire web engineering).
|
||
* All rights reserved. This program and the accompanying materials
|
||
* are made available under the terms of the GNU Public License v3.0
|
||
* which accompanies this distribution, and is available at
|
||
* http://www.gnu.org/licenses/gpl.html
|
||
*/
|
||
package at.bitfire.davdroid;
|
||
|
||
import java.lang.reflect.Array;
|
||
|
||
public class ArrayUtils {
|
||
|
||
@SuppressWarnings("unchecked")
|
||
public static <T> T[][] partition(T[] bigArray, int max) {
|
||
int nItems = bigArray.length;
|
||
int nPartArrays = (nItems + max-1)/max;
|
||
|
||
T[][] partArrays = (T[][])Array.newInstance(bigArray.getClass().getComponentType(), nPartArrays, 0);
|
||
|
||
// nItems is now the number of remaining items
|
||
for (int i = 0; nItems > 0; i++) {
|
||
int n = (nItems < max) ? nItems : max;
|
||
partArrays[i] = (T[])Array.newInstance(bigArray.getClass().getComponentType(), n);
|
||
System.arraycopy(bigArray, i*max, partArrays[i], 0, n);
|
||
|
||
nItems -= n;
|
||
}
|
||
|
||
return partArrays;
|
||
}
|
||
|
||
}
|