1 2 5 14 package org.jacorb.trading.constraint; 15 16 17 public class ValueType 18 { 19 private int m_id; 20 private boolean m_sequence; 21 private static String [] s_typeNames = { 22 "BOOLEAN", 23 "SHORT", 24 "USHORT", 25 "LONG", 26 "ULONG", 27 "FLOAT", 28 "DOUBLE", 29 "CHAR", 30 "STRING", 31 "OTHER" 32 }; 33 34 private static String [] s_longTypeNames = { 36 "boolean", 37 "short", 38 "unsigned short", 39 "long", 40 "unsigned long", 41 "float", 42 "double", 43 "char", 44 "string", 45 "other" 46 }; 47 48 public static final int BOOLEAN = 0; 49 public static final int SHORT = 1; 50 public static final int USHORT = 2; 51 public static final int LONG = 3; 52 public static final int ULONG = 4; 53 public static final int FLOAT = 5; 54 public static final int DOUBLE = 6; 55 public static final int CHAR = 7; 56 public static final int STRING = 8; 57 public static final int OTHER = 9; 58 public static final int NUMTYPES = OTHER + 1; 59 60 61 public ValueType() 62 { 63 this(OTHER, false); 64 } 65 66 67 public ValueType(int id) 68 { 69 this(id, false); 70 } 71 72 73 public ValueType(int id, boolean sequence) 74 { 75 m_id = id; 76 m_sequence = sequence; 77 } 78 79 80 public ValueType(ValueType type) 81 { 82 m_id = type.m_id; 83 m_sequence = type.m_sequence; 84 } 85 86 87 public boolean equals(ValueType type) 88 { 89 return (m_id == type.m_id && m_sequence == type.m_sequence); 90 } 91 92 93 public int getId() 94 { 95 return m_id; 96 } 97 98 99 public boolean isSequence() 100 { 101 return m_sequence; 102 } 103 104 105 public boolean isNumber() 106 { 107 return checkNumeric(m_id); 108 } 109 110 111 public String getTypeName() 112 { 113 return s_typeNames[m_id]; 114 } 115 116 117 public static String getTypeName(int id) 118 { 119 return s_typeNames[id]; 120 } 121 122 123 public String getLongTypeName() 124 { 125 return s_longTypeNames[m_id]; 126 } 127 128 129 public static String getLongTypeName(int id) 130 { 131 return s_longTypeNames[id]; 132 } 133 134 135 public String toString() 136 { 137 String result; 138 if (m_sequence) 139 result = "sequence<" + getLongTypeName() + ">"; 140 else 141 result = getLongTypeName(); 142 return result; 143 } 144 145 146 public static boolean isCompatible(int id1, int id2) 147 { 148 return (s_promoteTable[id1][id2] != -1); 149 } 150 151 152 public static int promote(int id1, int id2) 153 { 154 int result = s_promoteTable[id1][id2]; 155 156 return result; 157 } 158 159 160 protected boolean checkNumeric(int id) 161 { 162 boolean result = (id != STRING && id != OTHER && id != BOOLEAN); 163 return result; 164 } 165 166 167 172 private static int s_promoteTable[][] = { 173 174 { 176 BOOLEAN, -1, -1, -1, -1, -1, -1, -1, -1, -1 }, 187 188 189 { 191 -1, LONG, LONG, LONG, ULONG, FLOAT, DOUBLE, -1, -1, -1 }, 202 203 204 { 206 -1, LONG, LONG, LONG, ULONG, FLOAT, DOUBLE, -1, -1, -1 }, 217 218 { 220 -1, LONG, LONG, LONG, ULONG, FLOAT, DOUBLE, -1, -1, -1 }, 231 232 { 234 -1, ULONG, ULONG, ULONG, ULONG, FLOAT, DOUBLE, -1, -1, -1 }, 245 246 { 248 -1, FLOAT, FLOAT, FLOAT, FLOAT, FLOAT, DOUBLE, -1, -1, -1 }, 259 260 { 262 -1, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, DOUBLE, -1, -1, -1 }, 273 274 { 276 -1, -1, -1, -1, -1, -1, -1, CHAR, STRING, -1 }, 287 288 { 290 -1, -1, -1, -1, -1, -1, -1, STRING, STRING, -1 }, 301 302 { 304 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } 315 316 }; 317 318 319 349 } 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | Popular Tags |