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.type; 020 021import java.util.Iterator; 022 023import lucee.runtime.PageContext; 024import lucee.runtime.dump.DumpData; 025import lucee.runtime.dump.DumpProperties; 026import lucee.runtime.dump.DumpTable; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.op.Caster; 029import lucee.runtime.op.Operator; 030import lucee.runtime.type.dt.DateTime; 031 032public final class DoubleStruct extends StructImpl { 033 034 @Override 035 public Boolean castToBoolean(Boolean defaultValue) { 036 try { 037 return Caster.toBoolean(castToBooleanValue()); 038 } catch (PageException e) { 039 return defaultValue; 040 } 041 } 042 043 @Override 044 public DateTime castToDateTime(DateTime defaultValue) { 045 try { 046 return castToDateTime(); 047 } catch (PageException e) { 048 return defaultValue; 049 } 050 } 051 052 @Override 053 public double castToDoubleValue(double defaultValue) { 054 try { 055 return castToDoubleValue(); 056 } catch (PageException e) { 057 return defaultValue; 058 } 059 } 060 061 @Override 062 public String castToString(String defaultValue) { 063 try { 064 return castToString(); 065 } catch (PageException e) { 066 return defaultValue; 067 } 068 } 069 070 @Override 071 public boolean castToBooleanValue() throws PageException { 072 return Caster.toBooleanValue(castToDoubleValue()); 073 074 } 075 076 @Override 077 public DateTime castToDateTime() throws PageException { 078 return Caster.toDate(castToDateTime(),null); 079 } 080 081 @Override 082 public double castToDoubleValue() throws PageException { 083 Iterator it = valueIterator(); 084 double value=0; 085 while(it.hasNext()){ 086 value+=Caster.toDoubleValue(it.next()); 087 } 088 return value; 089 } 090 091 @Override 092 public String castToString() throws PageException { 093 return Caster.toString(castToDoubleValue()); 094 } 095 096 @Override 097 public int compareTo(boolean b) throws PageException { 098 return Operator.compare(castToDoubleValue(), b); 099 } 100 101 @Override 102 public int compareTo(DateTime dt) throws PageException { 103 return Operator.compare(castToDoubleValue(), dt); 104 } 105 106 @Override 107 public int compareTo(double d) throws PageException { 108 return Operator.compare(castToDoubleValue(),d); 109 } 110 111 @Override 112 public int compareTo(String str) throws PageException { 113 return Operator.compare(castToDoubleValue(), str); 114 } 115 116 @Override 117 public Collection duplicate(boolean deepCopy) { 118 Struct sct=new DoubleStruct(); 119 copy(this,sct,deepCopy); 120 return sct; 121 } 122 123 @Override 124 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 125 DumpTable table = (DumpTable) super.toDumpData(pageContext, maxlevel, dp); 126 try{ 127 table.setTitle("Double Struct ("+castToString()+")"); 128 } 129 catch(PageException pe){} 130 return table; 131 } 132}