KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportcalculator > SharedDate


1 package com.calipso.reportgenerator.reportcalculator;
2
3 import com.calipso.common.DateEx;
4
5 import java.util.HashMap JavaDoc;
6 import java.io.Serializable JavaDoc;
7 import java.text.SimpleDateFormat JavaDoc;
8
9 import com.calipso.reportgenerator.common.InfoException;
10
11 /**
12  * Administra las distintas instancias de DateEx
13  */

14 public class SharedDate extends SharedData implements Serializable JavaDoc, Comparable JavaDoc, CubeValue {
15    static final private HashMap JavaDoc dates = new HashMap JavaDoc(5003, 0.80f);
16    private DateEx date;
17
18
19   public SharedDate(DateEx value) {
20     this.date = value;
21     dates.put(new Long JavaDoc(value.getDate().getTime()),this);
22   }
23
24   static public SharedDate newFrom(DateEx aValue) {
25     Object JavaDoc dateEx=null;
26     dateEx = dates.get(new Long JavaDoc(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 JavaDoc 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 JavaDoc toString(){
50     return date.toString();
51   }
52
53   public DateEx getDateEx() {
54     return date;
55   }
56
57   public int compareTo(Object JavaDoc o) {
58     return date.compareTo(o);
59   }
60
61   public Object JavaDoc getValue() {
62     return date;
63   }
64
65   /*public String toNumberFormat() {
66     return date.toNumberFormat();
67   }*/

68   public String JavaDoc getStringSimpleValue() {
69     SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("yyyyMMdd");
70     return format.format(date);
71   }
72
73   public SharedData getFromStringSimpleValue(String JavaDoc simpleValue) throws InfoException {
74     SimpleDateFormat JavaDoc format = new SimpleDateFormat JavaDoc("yyyyMMdd");
75     return SharedDate.newFrom(new DateEx(date));
76   }
77 }
78
Popular Tags