equal
deleted
inserted
replaced
30 import java.security.*; |
30 import java.security.*; |
31 import jdk.internal.util.Preconditions; |
31 import jdk.internal.util.Preconditions; |
32 |
32 |
33 |
33 |
34 /** |
34 /** |
35 * This class holds the various utility methods for array range checks. |
35 * This class holds the various utility methods for arrays. |
36 */ |
36 */ |
37 |
37 |
38 public final class ArrayUtil { |
38 public final class ArrayUtil { |
39 |
39 |
40 private static final BiFunction<String, List<Integer>, |
40 private static final BiFunction<String, List<Integer>, |
50 |
50 |
51 public static void nullAndBoundsCheck(byte[] array, int offset, int len) { |
51 public static void nullAndBoundsCheck(byte[] array, int offset, int len) { |
52 // NPE is thrown when array is null |
52 // NPE is thrown when array is null |
53 Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER); |
53 Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER); |
54 } |
54 } |
|
55 |
|
56 |
|
57 private static void swap(byte[] arr, int i, int j) { |
|
58 byte tmp = arr[i]; |
|
59 arr[i] = arr[j]; |
|
60 arr[j] = tmp; |
|
61 } |
|
62 |
|
63 public static void reverse(byte [] arr) { |
|
64 int i = 0; |
|
65 int j = arr.length - 1; |
|
66 |
|
67 while (i < j) { |
|
68 swap(arr, i, j); |
|
69 i++; |
|
70 j--; |
|
71 } |
|
72 } |
55 } |
73 } |