001 package railo.runtime.interpreter.ref.literal; 002 003 import railo.runtime.exp.PageException; 004 import railo.runtime.interpreter.ref.Ref; 005 import railo.runtime.interpreter.ref.util.RefUtil; 006 import railo.runtime.op.Caster; 007 008 /** 009 * Literal Number 010 */ 011 public final class LNumber implements Literal { 012 013 public static final LNumber ZERO = new LNumber(new Double(0)); 014 public static final LNumber ONE = new LNumber(new Double(1)); 015 016 017 018 private Double literal; 019 020 /** 021 * constructor of the class 022 * @param literal 023 */ 024 public LNumber(Double literal) { 025 this.literal=literal; 026 } 027 028 /** 029 * constructor of the class 030 * @param literal 031 * @throws PageException 032 */ 033 public LNumber(String literal) throws PageException { 034 this.literal=Caster.toDouble(literal); 035 } 036 037 /** 038 * @see railo.runtime.interpreter.ref.Ref#getValue() 039 */ 040 public Object getValue() { 041 return literal; 042 } 043 044 /** 045 * @see railo.runtime.interpreter.ref.Ref#getCollection() 046 */ 047 public Object getCollection() { 048 return getValue(); 049 } 050 051 /** 052 * @see railo.runtime.interpreter.ref.Ref#getTypeName() 053 */ 054 public String getTypeName() { 055 return "number"; 056 } 057 058 059 /** 060 * @see railo.runtime.interpreter.ref.Ref#touchValue() 061 */ 062 public Object touchValue() { 063 return getValue(); 064 } 065 066 /** 067 * @see railo.runtime.interpreter.ref.literal.Literal#getString() 068 */ 069 public String getString() { 070 return Caster.toString(literal.doubleValue()); 071 } 072 073 /** 074 * @see java.lang.Object#toString() 075 */ 076 public String toString() { 077 return getString(); 078 } 079 080 /** 081 * @see railo.runtime.interpreter.ref.Ref#eeq(railo.runtime.interpreter.ref.Ref) 082 */ 083 public boolean eeq(Ref other) throws PageException { 084 if(other instanceof LNumber){ 085 return literal.doubleValue()==((LNumber)other).literal.doubleValue(); 086 } 087 // TODO Auto-generated method stub 088 return RefUtil.eeq(this,other); 089 } 090 }