1 package prefuse.data.expression; 2 3 import prefuse.data.Schema; 4 import prefuse.data.Tuple; 5 import prefuse.util.TypeLib; 6 7 12 public class NumericLiteral extends Literal { 13 14 private final Number m_number; 15 private final Class m_type; 16 17 20 24 public NumericLiteral(int x) { 25 m_number = new Integer (x); 26 m_type = int.class; 27 } 28 29 33 public NumericLiteral(long x) { 34 m_number = new Long (x); 35 m_type = long.class; 36 } 37 38 42 public NumericLiteral(float x) { 43 m_number = new Float (x); 44 m_type = float.class; 45 } 46 47 51 public NumericLiteral(double x) { 52 m_number = new Double (x); 53 m_type = double.class; 54 } 55 56 61 public NumericLiteral(Object x) { 62 if ( x instanceof Number ) { 63 m_number = (Number )x; 64 m_type = TypeLib.getPrimitiveType(m_number.getClass()); 65 } else { 66 throw new IllegalArgumentException ("Invalid type!"); 67 } 68 } 69 70 73 76 public Class getType(Schema s) { 77 return m_type; 78 } 79 80 83 public Object get(Tuple t) { 84 return m_number; 85 } 86 87 90 public int getInt(Tuple t) { 91 return m_number.intValue(); 92 } 93 94 97 public long getLong(Tuple t) { 98 return m_number.longValue(); 99 } 100 101 104 public float getFloat(Tuple t) { 105 return m_number.floatValue(); 106 } 107 108 111 public double getDouble(Tuple t) { 112 return m_number.doubleValue(); 113 } 114 115 118 public String toString() { 119 return m_number.toString(); 120 } 121 122 } | Popular Tags |