1 17 18 package org.objectweb.jac.util; 19 20 import java.lang.reflect.Array ; 21 22 public class Classes 23 { 24 25 33 public static Class getPrimitiveTypeWrapper(Class type) { 34 if (!type.isPrimitive()) 35 return type; 36 if (type == int.class) 37 return Integer .class; 38 else if (type == long.class) 39 return Long .class; 40 else if (type == short.class) 41 return Short .class; 42 else if (type == float.class) 43 return Float .class; 44 else if (type == double.class) 45 return Double .class; 46 else if (type == boolean.class) 47 return Boolean .class; 48 else if (type == byte.class) 49 return Byte .class; 50 else if (type == void.class) 51 return Void .class; 52 else 53 return type; 54 } 55 56 64 public static String getPrimitiveTypeWrapper(String type) { 65 if (type == null) 66 return "java.lang.Void"; 67 if (type.equals("int")) 68 return "java.lang.Integer"; 69 else if (type.equals("long")) 70 return "java.lang.Long"; 71 else if (type.equals("short")) 72 return "java.lang.Short"; 73 else if (type.equals("float")) 74 return "java.lang.Float"; 75 else if (type.equals("double")) 76 return "java.lang.Double"; 77 else if (type.equals("boolean")) 78 return "java.lang.Boolean"; 79 else if (type.equals("byte")) 80 return "java.lang.Byte"; 81 else if (type.equals("void")) 82 return "java.lang.Void"; 83 else 84 return type; 85 } 86 87 88 96 public static boolean isPrimitiveType(String type) { 97 return 98 type.equals("void") || 99 type.equals("int") || 100 type.equals("long") || 101 type.equals("short") || 102 type.equals("float") || 103 type.equals("double") || 104 type.equals("boolean") || 105 type.equals("byte"); 106 } 107 108 111 public static Object [] convertPrimitiveArray(Object primitiveArray) { 112 Class type = primitiveArray.getClass().getComponentType(); 113 int length = Array.getLength(primitiveArray); 114 Object [] result = (Object [])Array.newInstance(getPrimitiveTypeWrapper(type), 115 length); 116 for (int i=0; i<length; i++) { 117 Array.set(result,i,Array.get(primitiveArray,i)); 118 } 119 return result; 120 } 121 } 122 | Popular Tags |