1 23 24 29 30 package com.sun.jdo.spi.persistence.utility; 31 32 import java.util.Map ; 33 import java.util.HashMap ; 34 35 42 public class JavaTypeHelper 43 { 44 45 private final static Map _primitiveToWrappers; 46 47 48 private final static Map _primitiveNamesToPrimitives; 49 50 51 private final static Map _primitiveNamesToWrapperNames; 52 53 54 private final static Map _wrapperToPrimitiveNames; 55 56 static 57 { 58 _primitiveToWrappers = new HashMap (9); 59 _primitiveToWrappers.put(Boolean.TYPE, Boolean .class); 60 _primitiveToWrappers.put(Byte.TYPE, Byte .class); 61 _primitiveToWrappers.put(Character.TYPE, Character .class); 62 _primitiveToWrappers.put(Double.TYPE, Double .class); 63 _primitiveToWrappers.put(Float.TYPE, Float .class); 64 _primitiveToWrappers.put(Integer.TYPE, Integer .class); 65 _primitiveToWrappers.put(Long.TYPE, Long .class); 66 _primitiveToWrappers.put(Short.TYPE, Short .class); 67 _primitiveToWrappers.put(Void.TYPE, Void .class); 68 69 _primitiveNamesToPrimitives = new HashMap (9); 70 _primitiveNamesToPrimitives.put("boolean", Boolean.TYPE); _primitiveNamesToPrimitives.put("byte", Byte.TYPE); _primitiveNamesToPrimitives.put("char", Character.TYPE); _primitiveNamesToPrimitives.put("double", Double.TYPE); _primitiveNamesToPrimitives.put("float", Float.TYPE); _primitiveNamesToPrimitives.put("int", Integer.TYPE); _primitiveNamesToPrimitives.put("long", Long.TYPE); _primitiveNamesToPrimitives.put("short", Short.TYPE); _primitiveNamesToPrimitives.put("void", Void.TYPE); 80 _primitiveNamesToWrapperNames = new HashMap (9); 81 _primitiveNamesToWrapperNames.put("boolean", "Boolean"); _primitiveNamesToWrapperNames.put("byte", "Byte"); _primitiveNamesToWrapperNames.put("char", "Character"); _primitiveNamesToWrapperNames.put("double", "Double"); _primitiveNamesToWrapperNames.put("float", "Float"); _primitiveNamesToWrapperNames.put("int", "Integer"); _primitiveNamesToWrapperNames.put("long", "Long"); _primitiveNamesToWrapperNames.put("short", "Short"); _primitiveNamesToWrapperNames.put("void", "Void"); 91 _wrapperToPrimitiveNames = new HashMap (9); 92 _wrapperToPrimitiveNames.put(Boolean .class, "boolean"); _wrapperToPrimitiveNames.put(Byte .class, "byte"); _wrapperToPrimitiveNames.put(Character .class, "char"); _wrapperToPrimitiveNames.put(Double .class, "double"); _wrapperToPrimitiveNames.put(Float .class, "float"); _wrapperToPrimitiveNames.put(Integer .class, "int"); _wrapperToPrimitiveNames.put(Long .class, "long"); _wrapperToPrimitiveNames.put(Short .class, "short"); _wrapperToPrimitiveNames.put(Void .class, "void"); } 102 103 109 public static String getPackageName (final String className) 110 { 111 if (className != null) 112 { 113 final int index = className.lastIndexOf('.'); 114 115 return ((index != -1) ? 116 className.substring(0, index) : ""); } 118 119 return null; 120 } 121 122 127 public static String getShortClassName (final String className) 128 { 129 if (className != null) 130 { 131 final int index = className.lastIndexOf('.'); 132 133 return className.substring(index + 1); 134 } 135 return null; 136 } 137 138 140 144 public static Class getWrapperClass (Class primitive) 145 { 146 return (Class )_primitiveToWrappers.get(primitive); 147 } 148 149 154 public static Class getPrimitiveClass (String primitiveName) 155 { 156 return (Class )_primitiveNamesToPrimitives.get(primitiveName); 157 } 158 159 164 public static String getWrapperName (String primitiveName) 165 { 166 return (String )_primitiveNamesToWrapperNames.get(primitiveName); 167 } 168 169 174 public static String getPrimitiveName (Class wrapper) 175 { 176 return (String )_wrapperToPrimitiveNames.get(wrapper); 177 } 178 179 189 public static Boolean valueOf (boolean flag) 190 { 191 return (flag ? Boolean.TRUE : Boolean.FALSE); 192 } 193 } 194 | Popular Tags |