1 2 12 package com.versant.core.ejb.query; 13 14 17 public class LiteralNode extends Node { 18 19 public static final int LONG = 1; 20 public static final int DOUBLE = 2; 21 public static final int BOOLEAN = 3; 22 public static final int STRING = 4; 23 24 private int type; 25 private long longValue; 26 private double doubleValue; 27 private String stringValue; 28 private boolean booleanValue; 29 30 public LiteralNode(int type, String s) { 31 this.type = type; 32 int len, c; 33 switch (type) { 34 case LONG: 35 len = s.length(); 36 c = s.charAt(len - 1); 37 if (c == 'l' || c == 'L') { 38 s = s.substring(0, len - 1); 39 } 40 if (s.startsWith("0x")) { 41 longValue = Long.parseLong(s.substring(2), 16); 42 } else { 43 longValue = Long.parseLong(s); 44 } 45 break; 46 case DOUBLE: 47 len = s.length(); 48 c = s.charAt(len - 1); 49 if (c == 'f' || c == 'F' || c == 'd' || c == 'D') { 50 s = s.substring(0, len - 1); 51 } 52 doubleValue = Double.parseDouble(s); 53 break; 54 case BOOLEAN: 55 s = s.toUpperCase(); 56 booleanValue = "TRUE".equals(s); 57 break; 58 case STRING: 59 stringValue = s.substring(1, s.length() - 1); 60 break; 61 default: 62 throw new IllegalArgumentException ("Invalid type " + type + 63 " for " + s); 64 } 65 } 66 67 public int getType() { 68 return type; 69 } 70 71 public long getLongValue() { 72 return longValue; 73 } 74 75 public double getDoubleValue() { 76 return doubleValue; 77 } 78 79 public String getStringValue() { 80 return stringValue; 81 } 82 83 public boolean getBooleanValue() { 84 return booleanValue; 85 } 86 87 public Object arrive(NodeVisitor v, Object msg) { 88 return v.arriveLiteralNode(this, msg); 89 } 90 91 public String toStringImp() { 92 switch (type) { 93 case LONG: return Long.toString(longValue) + "L"; 94 case DOUBLE: return Double.toString(doubleValue); 95 case BOOLEAN: return booleanValue ? "TRUE" : "FALSE"; 96 case STRING: return "'" + stringValue + "'"; 97 } 98 return "<? type " + type + "?>"; 99 } 100 101 } 102 103 | Popular Tags |