1 package com.calipso.reportgenerator.reportcalculator; 2 3 import com.calipso.common.DateEx; 4 5 import java.util.HashMap ; 6 import java.io.Serializable ; 7 import java.text.SimpleDateFormat ; 8 9 import com.calipso.reportgenerator.common.InfoException; 10 11 14 public class SharedDate extends SharedData implements Serializable , Comparable , CubeValue { 15 static final private HashMap dates = new HashMap (5003, 0.80f); 16 private DateEx date; 17 18 19 public SharedDate(DateEx value) { 20 this.date = value; 21 dates.put(new Long (value.getDate().getTime()),this); 22 } 23 24 static public SharedDate newFrom(DateEx aValue) { 25 Object dateEx=null; 26 dateEx = dates.get(new Long (aValue.getDate().getTime())); 27 if (dateEx == null) { 28 return new SharedDate(aValue); 29 } 30 else { 31 return (SharedDate) dateEx; 32 } 33 } 34 35 public boolean equals(Object o) { 36 final DateEx dateEx; 37 if (this == o) return true; 38 39 if (o instanceof DateEx) { 40 dateEx = (DateEx) o; 41 } 42 else { 43 dateEx = ((SharedDate) o).getDateEx(); 44 } 45 if (!date.equals(dateEx)) return false; 46 return true; 47 } 48 49 public String toString(){ 50 return date.toString(); 51 } 52 53 public DateEx getDateEx() { 54 return date; 55 } 56 57 public int compareTo(Object o) { 58 return date.compareTo(o); 59 } 60 61 public Object getValue() { 62 return date; 63 } 64 65 68 public String getStringSimpleValue() { 69 SimpleDateFormat format = new SimpleDateFormat ("yyyyMMdd"); 70 return format.format(date); 71 } 72 73 public SharedData getFromStringSimpleValue(String simpleValue) throws InfoException { 74 SimpleDateFormat format = new SimpleDateFormat ("yyyyMMdd"); 75 return SharedDate.newFrom(new DateEx(date)); 76 } 77 } 78 | Popular Tags |