blob: 2047d3fc0be50d9ce78b6ae2bf629e2dba7c4565 [file] [log] [blame]
Alex Klyubin5927c9f2015-04-10 13:28:03 -07001package android.security;
2
3import libcore.util.EmptyArray;
4
5/**
6 * @hide
7 */
8abstract class ArrayUtils {
9 private ArrayUtils() {}
10
11 public static String[] nullToEmpty(String[] array) {
12 return (array != null) ? array : EmptyArray.STRING;
13 }
14
15 public static String[] cloneIfNotEmpty(String[] array) {
16 return ((array != null) && (array.length > 0)) ? array.clone() : array;
17 }
18
19 public static byte[] concat(byte[] arr1, byte[] arr2) {
20 return concat(arr1, 0, (arr1 != null) ? arr1.length : 0,
21 arr2, 0, (arr2 != null) ? arr2.length : 0);
22 }
23
24 public static byte[] concat(byte[] arr1, int offset1, int len1, byte[] arr2, int offset2,
25 int len2) {
26 if (len1 == 0) {
27 return subarray(arr2, offset2, len2);
28 } else if (len2 == 0) {
29 return subarray(arr1, offset1, len1);
30 } else {
31 byte[] result = new byte[len1 + len2];
32 System.arraycopy(arr1, offset1, result, 0, len1);
33 System.arraycopy(arr2, offset2, result, len1, len2);
34 return result;
35 }
36 }
37
38 public static byte[] subarray(byte[] arr, int offset, int len) {
39 if (len == 0) {
40 return EmptyArray.BYTE;
41 }
42 if ((offset == 0) && (len == arr.length)) {
43 return arr;
44 }
45 byte[] result = new byte[len];
46 System.arraycopy(arr, offset, result, 0, len);
47 return result;
48 }
49
50 public static int[] concat(int[] arr1, int[] arr2) {
51 if ((arr1 == null) || (arr1.length == 0)) {
52 return arr2;
53 } else if ((arr2 == null) || (arr2.length == 0)) {
54 return arr1;
55 } else {
56 int[] result = new int[arr1.length + arr2.length];
57 System.arraycopy(arr1, 0, result, 0, arr1.length);
58 System.arraycopy(arr2, 0, result, arr1.length, arr2.length);
59 return result;
60 }
61 }
62}