devutility.internal.util.ArraysUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of devutility.internal Show documentation
Show all versions of devutility.internal Show documentation
Some utilities for Java development
package devutility.internal.util;
import java.util.LinkedList;
import java.util.List;
public class ArraysUtils {
/**
* If the arrays is null or empty.
* @param arrays: String arrays.
* @return boolean
*/
public static boolean isNullOrEmpty(String[][] arrays) {
return arrays == null || arrays.length == 0;
}
/**
* Page array
* @param arrays: Arrays
* @param pageIndex: Page index, from 1
* @param pageSize: Page size
* @return String[][]
*/
public static String[][] pageArray(String[][] arrays, int pageIndex, int pageSize) {
if (isNullOrEmpty(arrays) || pageIndex < 1 || pageSize < 1) {
return new String[0][];
}
List list = new LinkedList<>();
int start = (pageIndex - 1) * pageSize;
int end = Math.min(start + pageSize, arrays.length);
for (int index = start; index < end; index++) {
list.add(arrays[index]);
}
return list.toArray(new String[0][]);
}
}