MCPcopy Create free account
hub / github.com/MTrop/DoomTools / ArrayUtils

Class ArrayUtils

src/main/java/net/mtrop/doom/tools/struct/util/ArrayUtils.java:19–817  ·  view source on GitHub ↗

Simple utility functions around Arrays. @author Matthew Tropiano

Source from the content-addressed store, hash-verified

17 * @author Matthew Tropiano
18 */
19public final class ArrayUtils
20{
21 private ArrayUtils() {}
22
23 /**
24 * Tests if a class is actually an array type.
25 * @param clazz the class to test.
26 * @return true if so, false if not.
27 */
28 public static boolean isArray(Class<?> clazz)
29 {
30 return clazz.isArray();
31 }
32
33 /**
34 * Tests if an object is actually an array type.
35 * @param object the object to test.
36 * @return true if so, false if not.
37 */
38 public static boolean isArray(Object object)
39 {
40 return isArray(object.getClass());
41 }
42
43 /**
44 * Gets the class type of this array type, if this is an array type.
45 * @param arrayType the type to inspect.
46 * @return this array's type, or null if the provided type is not an array,
47 * or if the found class is not on the classpath.
48 */
49 public static Class<?> getArrayType(Class<?> arrayType)
50 {
51 String cname = arrayType.getName();
52
53 int typeIndex = getArrayDimensions(arrayType);
54 if (typeIndex == 0)
55 return null;
56
57 char t = cname.charAt(typeIndex);
58 if (t == 'L') // is object.
59 {
60 String classtypename = cname.substring(typeIndex + 1, cname.length() - 1);
61 try {
62 return Class.forName(classtypename);
63 } catch (ClassNotFoundException e){
64 return null;
65 }
66 }
67 else switch (t)
68 {
69 case 'Z': return Boolean.TYPE;
70 case 'B': return Byte.TYPE;
71 case 'S': return Short.TYPE;
72 case 'I': return Integer.TYPE;
73 case 'J': return Long.TYPE;
74 case 'F': return Float.TYPE;
75 case 'D': return Double.TYPE;
76 case 'C': return Character.TYPE;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected