001    package railo.runtime.type;
002    
003    import java.util.Iterator;
004    
005    import railo.runtime.PageContext;
006    import railo.runtime.dump.DumpData;
007    import railo.runtime.dump.DumpProperties;
008    import railo.runtime.dump.DumpTable;
009    import railo.runtime.exp.PageException;
010    import railo.runtime.op.Caster;
011    import railo.runtime.op.Operator;
012    import railo.runtime.type.dt.DateTime;
013    
014    public final class DoubleStruct extends StructImpl  {
015            
016            /**
017             * @see railo.runtime.type.util.StructSupport#castToBoolean(java.lang.Boolean)
018             */
019            public Boolean castToBoolean(Boolean defaultValue) {
020                    try {
021                            return Caster.toBoolean(castToBooleanValue());
022                    } catch (PageException e) {
023                            return defaultValue;
024                    }
025            }
026    
027            /**
028             * @see railo.runtime.type.util.StructSupport#castToDateTime(railo.runtime.type.dt.DateTime)
029             */
030            public DateTime castToDateTime(DateTime defaultValue) {
031                    try {
032                            return castToDateTime();
033                    } catch (PageException e) {
034                            return defaultValue;
035                    }
036            }
037    
038            /**
039             * @see railo.runtime.type.util.StructSupport#castToDoubleValue(double)
040             */
041            public double castToDoubleValue(double defaultValue) {
042                    try {
043                            return castToDoubleValue();
044                    } catch (PageException e) {
045                            return defaultValue;
046                    }
047            }
048    
049            /**
050             * @see railo.runtime.type.util.StructSupport#castToString(java.lang.String)
051             */
052            public String castToString(String defaultValue) {
053                    try {
054                            return castToString();
055                    } catch (PageException e) {
056                            return defaultValue;
057                    }
058            }
059    
060            /**
061             *
062             * @throws PageException 
063             * @see railo.runtime.type.StructImpl#castToBooleanValue()
064             */
065            public boolean castToBooleanValue() throws PageException {
066                    return Caster.toBooleanValue(castToDoubleValue());
067                    
068            }
069    
070            /**
071             *
072             * @throws PageException 
073             * @see railo.runtime.type.StructImpl#castToDateTime()
074             */
075            public DateTime castToDateTime() throws PageException {
076                    return Caster.toDate(castToDateTime(),null);
077            }
078    
079            /**
080             *
081             * @throws PageException 
082             * @see railo.runtime.type.StructImpl#castToDoubleValue()
083             */
084            public double castToDoubleValue() throws PageException {
085                    Iterator it = valueIterator();
086                    double value=0;
087                    while(it.hasNext()){
088                            value+=Caster.toDoubleValue(it.next());
089                    }
090                    return value;
091            }
092    
093            /**
094             *
095             * @throws PageException 
096             * @see railo.runtime.type.StructImpl#castToString()
097             */
098            public String castToString() throws PageException {
099                    return Caster.toString(castToDoubleValue());
100            }
101    
102            /**
103             *
104             * @throws PageException 
105             * @see railo.runtime.type.StructImpl#compareTo(boolean)
106             */
107            public int compareTo(boolean b) throws PageException {
108                    return Operator.compare(castToDoubleValue(), b);
109            }
110    
111            /**
112             *
113             * @see railo.runtime.type.StructImpl#compareTo(railo.runtime.type.dt.DateTime)
114             */
115            public int compareTo(DateTime dt) throws PageException {
116                    return Operator.compare(castToDoubleValue(), dt);
117            }
118    
119            /**
120             *
121             * @see railo.runtime.type.StructImpl#compareTo(double)
122             */
123            public int compareTo(double d) throws PageException {
124                    return Operator.compare(castToDoubleValue(),d);
125            }
126    
127            /**
128             *
129             * @see railo.runtime.type.StructImpl#compareTo(java.lang.String)
130             */
131            public int compareTo(String str) throws PageException {
132                    return Operator.compare(castToDoubleValue(), str);
133            }
134    
135            /**
136             *
137             * @see railo.runtime.type.StructImpl#duplicate(boolean)
138             */
139            public Collection duplicate(boolean deepCopy) {
140                    Struct sct=new DoubleStruct();
141                    copy(this,sct,deepCopy);
142                    return sct;
143            }
144    
145            /**
146             *
147             * @see railo.runtime.type.StructImpl#toDumpData(railo.runtime.PageContext, int)
148             */
149            public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
150                    DumpTable table = (DumpTable) super.toDumpData(pageContext, maxlevel, dp);
151                    try{
152                            table.setTitle("Double Struct ("+castToString()+")");
153                    }
154                    catch(PageException pe){}
155                    return table;
156            }
157    }