| 1 | |
package org.webslinger.collections; |
| 2 | |
|
| 3 | |
import java.util.List; |
| 4 | |
|
| 5 | 0 | public class ArrayUtil { |
| 6 | |
public static List<Boolean> asList(boolean[] array) { |
| 7 | 0 | return new booleanArrayWrapper(array); |
| 8 | |
} |
| 9 | |
|
| 10 | |
public static List<Byte> asList(byte[] array) { |
| 11 | 0 | return new byteArrayWrapper(array); |
| 12 | |
} |
| 13 | |
|
| 14 | |
public static List<Character> asList(char[] array) { |
| 15 | 0 | return new charArrayWrapper(array); |
| 16 | |
} |
| 17 | |
|
| 18 | |
public static List<Double> asList(double[] array) { |
| 19 | 0 | return new doubleArrayWrapper(array); |
| 20 | |
} |
| 21 | |
|
| 22 | |
public static List<Float> asList(float[] array) { |
| 23 | 0 | return new floatArrayWrapper(array); |
| 24 | |
} |
| 25 | |
|
| 26 | |
public static List<Integer> asList(int[] array) { |
| 27 | 0 | return new intArrayWrapper(array); |
| 28 | |
} |
| 29 | |
|
| 30 | |
public static List<Long> asList(long[] array) { |
| 31 | 0 | return new longArrayWrapper(array); |
| 32 | |
} |
| 33 | |
|
| 34 | |
public static List<Short> asList(short[] array) { |
| 35 | 0 | return new shortArrayWrapper(array); |
| 36 | |
} |
| 37 | |
|
| 38 | |
public static List<Object> asList(Object[] array) { |
| 39 | 2 | return new objectArrayWrapper(array); |
| 40 | |
} |
| 41 | |
|
| 42 | |
public static List<?> asList(Object object) { |
| 43 | 2 | if (object instanceof boolean[]) return asList((boolean[]) object); |
| 44 | 2 | if (object instanceof byte[]) return asList((byte[]) object); |
| 45 | 2 | if (object instanceof char[]) return asList((char[]) object); |
| 46 | 2 | if (object instanceof double[]) return asList((double[]) object); |
| 47 | 2 | if (object instanceof float[]) return asList((float[]) object); |
| 48 | 2 | if (object instanceof int[]) return asList((int[]) object); |
| 49 | 2 | if (object instanceof long[]) return asList((long[]) object); |
| 50 | 2 | if (object instanceof short[]) return asList((short[]) object); |
| 51 | 2 | if (object instanceof Object[]) return asList((Object[]) object); |
| 52 | 0 | return new ArrayWrapper(object); |
| 53 | |
} |
| 54 | |
|
| 55 | |
public static <T> int hashCodeHelper(T[] array) { |
| 56 | 0 | int hashCode = 0; |
| 57 | 0 | for (T t: array) hashCode ^= t.hashCode(); |
| 58 | 0 | return hashCode; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public static <T> boolean equalsHelper(T[] left, T[] right) { |
| 62 | 0 | if (left == null) return right == null; |
| 63 | 0 | if (right == null) return false; |
| 64 | 0 | if (left.length != right.length) return false; |
| 65 | 0 | for (int i = 0; i < left.length; i++) { |
| 66 | 0 | if (!left[i].equals(right[i])) return false; |
| 67 | |
} |
| 68 | 0 | return true; |
| 69 | |
} |
| 70 | |
} |