1 15 package org.apache.hivemind.impl; 16 17 import java.util.HashMap ; 18 import java.util.Map ; 19 20 27 public class JavaTypeUtils 28 { 29 33 private static Map PRIMITIVE_TYPE_CODES = new HashMap (); 34 35 static 36 { 37 PRIMITIVE_TYPE_CODES.put("boolean", "Z"); 38 PRIMITIVE_TYPE_CODES.put("short", "S"); 39 PRIMITIVE_TYPE_CODES.put("int", "I"); 40 PRIMITIVE_TYPE_CODES.put("long", "J"); 41 PRIMITIVE_TYPE_CODES.put("float", "F"); 42 PRIMITIVE_TYPE_CODES.put("double", "D"); 43 PRIMITIVE_TYPE_CODES.put("char", "C"); 44 PRIMITIVE_TYPE_CODES.put("byte", "B"); 45 } 46 47 50 private static final Map PRIMITIVE_CLASSES = new HashMap (); 51 52 static 53 { 54 PRIMITIVE_CLASSES.put("boolean", boolean.class); 55 PRIMITIVE_CLASSES.put("short", short.class); 56 PRIMITIVE_CLASSES.put("char", char.class); 57 PRIMITIVE_CLASSES.put("byte", byte.class); 58 PRIMITIVE_CLASSES.put("int", int.class); 59 PRIMITIVE_CLASSES.put("long", long.class); 60 PRIMITIVE_CLASSES.put("float", float.class); 61 PRIMITIVE_CLASSES.put("double", double.class); 62 } 63 64 private JavaTypeUtils() 65 { 66 } 68 69 74 public static String getJVMClassName(String type) 75 { 76 if (!type.endsWith("[]")) 78 return type; 79 80 StringBuffer buffer = new StringBuffer (); 82 83 while (type.endsWith("[]")) 84 { 85 buffer.append("["); 86 type = type.substring(0, type.length() - 2); 87 } 88 89 String primitiveIdentifier = (String ) PRIMITIVE_TYPE_CODES.get(type); 90 if (primitiveIdentifier != null) 91 buffer.append(primitiveIdentifier); 92 else 93 { 94 buffer.append("L"); 95 buffer.append(type); 96 buffer.append(";"); 97 } 98 99 return buffer.toString(); 100 } 101 102 109 110 public static Class getPrimtiveClass(String type) 111 { 112 return (Class ) PRIMITIVE_CLASSES.get(type); 113 } 114 } | Popular Tags |