001/**
002 *
003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved.
004 *
005 * This library is free software; you can redistribute it and/or
006 * modify it under the terms of the GNU Lesser General Public
007 * License as published by the Free Software Foundation; either 
008 * version 2.1 of the License, or (at your option) any later version.
009 * 
010 * This library is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013 * Lesser General Public License for more details.
014 * 
015 * You should have received a copy of the GNU Lesser General Public 
016 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
017 * 
018 **/
019package lucee.runtime.interpreter.ref.literal;
020
021import java.math.BigDecimal;
022
023import lucee.runtime.PageContext;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.interpreter.ref.Ref;
026import lucee.runtime.interpreter.ref.util.RefUtil;
027
028/**
029 * Literal Number
030 */
031public final class LBigDecimal implements Ref {
032
033    public static final LBigDecimal ZERO = new LBigDecimal(BigDecimal.ZERO);
034    public static final LBigDecimal ONE = new LBigDecimal(BigDecimal.ONE);
035    
036    
037    
038        private BigDecimal literal;
039
040    /**
041     * constructor of the class
042     * @param literal
043     */
044    public LBigDecimal(BigDecimal literal) {
045        this.literal=literal;
046    }
047
048    /**
049     * constructor of the class
050     * @param literal
051     * @throws PageException 
052     */
053    public LBigDecimal(String literal) throws PageException {
054        this.literal=new BigDecimal(literal);
055    }
056    
057    public BigDecimal getBigDecimal() {
058        return literal;
059    }
060    
061    @Override
062        public Object getValue(PageContext pc) {
063        return literal;
064    }
065    
066    @Override
067    public Object getCollection(PageContext pc) {
068        return getValue(pc);
069    }
070
071    @Override
072    public String getTypeName() {
073        return "number";
074    }
075    
076    @Override
077    public Object touchValue(PageContext pc) {
078        return getValue(pc);
079    }
080
081    @Override
082    public String toString() {
083        return literal.toString();
084    }
085    
086    @Override
087        public boolean eeq(PageContext pc,Ref other) throws PageException {
088                return RefUtil.eeq(pc,this,other);
089        }
090}