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 lucee.runtime.PageContext; 022import lucee.runtime.exp.PageException; 023import lucee.runtime.interpreter.ref.Ref; 024import lucee.runtime.interpreter.ref.RefSupport; 025import lucee.runtime.interpreter.ref.util.RefUtil; 026import lucee.runtime.op.Caster; 027 028/** 029 * constructor of the class 030 */ 031public final class LBoolean extends RefSupport implements Literal { 032 033 /** 034 * Field <code>TRUE</code> 035 */ 036 public static final Ref TRUE = new LBoolean(Boolean.TRUE); 037 /** 038 * Field <code>FALSE</code> 039 */ 040 public static final Ref FALSE = new LBoolean(Boolean.FALSE); 041 042 private Boolean literal; 043 044 /** 045 * constructor with Boolean 046 * @param literal 047 */ 048 public LBoolean(Boolean literal) { 049 this.literal=literal; 050 } 051 052 /** 053 * constructor with boolean 054 * @param b 055 */ 056 public LBoolean(boolean b) { 057 this.literal=b?Boolean.TRUE:Boolean.FALSE; 058 } 059 060 /** 061 * constructor with boolean 062 * @param str 063 * @throws PageException 064 */ 065 public LBoolean(String str) throws PageException { 066 this.literal=Caster.toBoolean(str); 067 } 068 069 070 @Override 071 public Object getValue(PageContext pc) { 072 return literal; 073 } 074 075 @Override 076 public String getTypeName() { 077 return "literal"; 078 } 079 080 @Override 081 public String getString(PageContext pc) { 082 return toString(); 083 } 084 085 @Override 086 public String toString() { 087 return Caster.toString(literal.booleanValue()); 088 } 089 090 @Override 091 public boolean eeq(PageContext pc,Ref other) throws PageException { 092 if(other instanceof LNumber){ 093 return literal.booleanValue()==((LBoolean)other).literal.booleanValue(); 094 } 095 return RefUtil.eeq(pc,this,other); 096 } 097 098}