01: package com.calipso.reportgenerator.reportcalculator;
02:
03: import com.calipso.common.DateEx;
04:
05: import java.util.HashMap;
06: import java.io.Serializable;
07: import java.text.SimpleDateFormat;
08:
09: import com.calipso.reportgenerator.common.InfoException;
10:
11: /**
12: * Administra las distintas instancias de DateEx
13: */
14: public class SharedDate extends SharedData implements Serializable,
15: Comparable, CubeValue {
16: static final private HashMap dates = new HashMap(5003, 0.80f);
17: private DateEx date;
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: } else {
30: return (SharedDate) dateEx;
31: }
32: }
33:
34: public boolean equals(Object o) {
35: final DateEx dateEx;
36: if (this == o)
37: return true;
38:
39: if (o instanceof DateEx) {
40: dateEx = (DateEx) o;
41: } else {
42: dateEx = ((SharedDate) o).getDateEx();
43: }
44: if (!date.equals(dateEx))
45: 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: /*public String toNumberFormat() {
66: return date.toNumberFormat();
67: }*/
68: public String getStringSimpleValue() {
69: SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
70: return format.format(date);
71: }
72:
73: public SharedData getFromStringSimpleValue(String simpleValue)
74: throws InfoException {
75: SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
76: return SharedDate.newFrom(new DateEx(date));
77: }
78: }
|