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.tag;
020
021import java.io.Serializable;
022import java.util.Date;
023import java.util.TimeZone;
024
025import lucee.runtime.PageContext;
026import lucee.runtime.exp.PageException;
027import lucee.runtime.op.Caster;
028
029public class ChartDataBean implements Serializable,Comparable {
030
031        private Object item;
032        private String strItem;
033        private double value;
034        /**
035         * @return the item
036         */
037        public Object getItem() {
038                return item;
039        }
040        public String getItemAsString() {
041                return strItem;
042        }
043        /**
044         * @param item the item to set
045         * @throws PageException 
046         */
047        public void setItem(PageContext pc,Object obj) throws PageException {
048                this.strItem = itemToString(pc, obj);
049                this.item=obj;
050        }
051        public void setItem(String str)  {
052                this.strItem = str;
053                this.item=str;
054        }
055        /**
056         * @return the value
057         */
058        public double getValue() {
059                return value;
060        }
061        /**
062         * @param value the value to set
063         */
064        public void setValue(double value) {
065                this.value = value;
066        }
067        
068        @Override
069        public String toString() {
070                return "item:"+item+";"+"value;"+value+";";
071        }
072        public int compareTo(Object o) {
073                if(!(o instanceof ChartDataBean)) return 0;
074                ChartDataBean other=(ChartDataBean) o;
075                return getItemAsString().compareTo(other.getItemAsString());
076        }
077        
078
079        private String itemToString(PageContext pc,Object obj) throws PageException {
080                if(obj instanceof Date) {
081                        TimeZone tz = pc.getTimeZone();
082                        return new lucee.runtime.format.DateFormat(pc.getLocale()).format(Caster.toDate(obj, tz),"short",tz)+" "+
083                        new lucee.runtime.format.TimeFormat(pc.getLocale()).format(Caster.toDate(obj, tz),"short",tz);
084                }
085                return Caster.toString(obj);
086        }
087}