V
VisionSet
I have an application that deals with alot of dates, I have classes that
represent time & duration. I do not need to cart around the beast that is
GregorianCalendar.
However I do need to use it to convert data.
eg:
gregCal.setTime(myDate);
gregCal.get(Calendar.DATE);
gregCal.get(Calendar.MONTH_OF_YEAR); // etc
Also I really need a different Calendar, something that I can do this with
myCal.isSpecialDay();
So I'm wondering whether I should subclass Calendar/Gregorian to add my
special dates.
Because I don't see the need to have an instance of this in my time/duration
objects, I'm thinking, I could have a Singleton MyCalendar to use for look
ups.
At present there isn't a threading issue, just one thread. But I'd like to
make it thread safe, none the less. Also if there are multiple threads
eventually, I should convert my Singleton to an Object pool - right?
Anyhow I'd need to synchronise over several calls within MyCalendar to make
sure the date is setup and retrieved correctly:
synchronized public boolean isSpecialDay(Date date) {
setTime(date);
return isSpecialDay();
}
Presumably I should make all methods that set the date synchronized also?
I know there is probably some bad stuff above, how should I do this please?
represent time & duration. I do not need to cart around the beast that is
GregorianCalendar.
However I do need to use it to convert data.
eg:
gregCal.setTime(myDate);
gregCal.get(Calendar.DATE);
gregCal.get(Calendar.MONTH_OF_YEAR); // etc
Also I really need a different Calendar, something that I can do this with
myCal.isSpecialDay();
So I'm wondering whether I should subclass Calendar/Gregorian to add my
special dates.
Because I don't see the need to have an instance of this in my time/duration
objects, I'm thinking, I could have a Singleton MyCalendar to use for look
ups.
At present there isn't a threading issue, just one thread. But I'd like to
make it thread safe, none the less. Also if there are multiple threads
eventually, I should convert my Singleton to an Object pool - right?
Anyhow I'd need to synchronise over several calls within MyCalendar to make
sure the date is setup and retrieved correctly:
synchronized public boolean isSpecialDay(Date date) {
setTime(date);
return isSpecialDay();
}
Presumably I should make all methods that set the date synchronized also?
I know there is probably some bad stuff above, how should I do this please?