1 13 14 15 package org.aspectj.runtime.internal; 16 17 public final class Conversions { 18 private Conversions() {} 20 21 public static Object intObject(int i) { 23 return new Integer (i); 24 } 25 public static Object shortObject(short i) { 26 return new Short (i); 27 } 28 public static Object byteObject(byte i) { 29 return new Byte (i); 30 } 31 public static Object charObject(char i) { 32 return new Character (i); 33 } 34 public static Object longObject(long i) { 35 return new Long (i); 36 } 37 public static Object floatObject(float i) { 38 return new Float (i); 39 } 40 public static Object doubleObject(double i) { 41 return new Double (i); 42 } 43 public static Object booleanObject(boolean i) { 44 return new Boolean (i); 45 } 46 public static Object voidObject() { 47 return null; 48 } 49 50 51 public static int intValue(Object o) { 52 if (o == null) { 53 return 0; 54 } else if (o instanceof Number ) { 55 return ((Number )o).intValue(); 56 } else { 57 throw new ClassCastException (o.getClass().getName() + 58 " can not be converted to int"); 59 } 60 } 61 public static long longValue(Object o) { 62 if (o == null) { 63 return 0; 64 } else if (o instanceof Number ) { 65 return ((Number )o).longValue(); 66 } else { 67 throw new ClassCastException (o.getClass().getName() + 68 " can not be converted to long"); 69 } 70 } 71 public static float floatValue(Object o) { 72 if (o == null) { 73 return 0; 74 } else if (o instanceof Number ) { 75 return ((Number )o).floatValue(); 76 } else { 77 throw new ClassCastException (o.getClass().getName() + 78 " can not be converted to float"); 79 } 80 } 81 public static double doubleValue(Object o) { 82 if (o == null) { 83 return 0; 84 } else if (o instanceof Number ) { 85 return ((Number )o).doubleValue(); 86 } else { 87 throw new ClassCastException (o.getClass().getName() + 88 " can not be converted to double"); 89 } 90 } 91 public static byte byteValue(Object o) { 92 if (o == null) { 93 return 0; 94 } else if (o instanceof Number ) { 95 return ((Number )o).byteValue(); 96 } else { 97 throw new ClassCastException (o.getClass().getName() + 98 " can not be converted to byte"); 99 } 100 } 101 public static short shortValue(Object o) { 102 if (o == null) { 103 return 0; 104 } else if (o instanceof Number ) { 105 return ((Number )o).shortValue(); 106 } else { 107 throw new ClassCastException (o.getClass().getName() + 108 " can not be converted to short"); 109 } 110 } 111 public static char charValue(Object o) { 112 if (o == null) { 113 return 0; 114 } else if (o instanceof Character ) { 115 return ((Character )o).charValue(); 116 } else { 117 throw new ClassCastException (o.getClass().getName() + 118 " can not be converted to char"); 119 } 120 } 121 public static boolean booleanValue(Object o) { 122 if (o == null) { 123 return false; 124 } else if (o instanceof Boolean ) { 125 return ((Boolean )o).booleanValue(); 126 } else { 127 throw new ClassCastException (o.getClass().getName() + 128 " can not be converted to boolean"); 129 } 130 } 131 132 137 public static Object voidValue(Object o) { 138 if (o == null) { 139 return o; 140 } else { 141 return o; 143 } 144 } 145 } 146 | Popular Tags |