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