1 28 29 package com.caucho.xpath.expr; 30 31 import com.caucho.util.CharBuffer; 32 33 36 public class NumberVar extends Var { 37 private static NumberVar []intVar = new NumberVar[256]; 38 39 private double value; 40 private Double objValue; 41 private String strValue; 42 43 46 private NumberVar(double value) 47 { 48 this.value = value; 49 } 50 51 54 public static NumberVar create(double value) 55 { 56 NumberVar var; 57 58 int index = (int) value; 59 60 if (index == value && index > -128 && index < 128) { 61 var = intVar[index + 128]; 62 if (var == null) { 63 var = new NumberVar(value); 64 intVar[index + 128] = var; 65 } 66 67 return var; 68 } 69 else 70 return new NumberVar(value); 71 } 72 73 76 double getDouble() 77 { 78 return value; 79 } 80 81 84 Object getObject() 85 { 86 if (objValue == null) 87 objValue = new Double (value); 88 89 return objValue; 90 } 91 92 95 String getString() 96 { 97 if (strValue == null) { 98 if ((int) value == value) { 99 CharBuffer cb = CharBuffer.allocate(); 100 cb.append((int) value); 101 strValue = cb.close(); 102 } 103 else 104 strValue = String.valueOf(value); 105 } 106 107 return strValue; 108 } 109 110 113 void getString(CharBuffer cb) 114 { 115 if ((int) value == value) 116 cb.append((int) value); 117 else 118 cb.append(value); 119 } 120 121 124 public Object clone() 125 { 126 NumberVar var = (NumberVar) NumberVar.create(value); 127 var.objValue = objValue; 128 var.strValue = strValue; 129 130 return var; 131 } 132 133 public String toString() 134 { 135 return "[NumberVar " + value + "]"; 136 } 137 } 138 | Popular Tags |