I'm pulling the date and time of emails using the notes.jar lotus notes api. When I add them to a collection, if add them like this:
Vector times = doc.getItemValueDateTimeArray("PostedDate");
for (int j=0; j<times.size(); j++) {
Object time = times.elementAt(j);
if (time.getClass().getName().endsWith("DateTime")) {
String Listadd = ((DateTime)time).getLocalTime();
NotesDates.add((DateTime)time);
I get the error:
lotus.domino.local.DateTime cannot be cast to java.lang.Comparable
When I add the values as String the code runs, but I cannot sort the collection.
How can I sort the collection of dates and times to find the earliest and latest?
You have a few options. Here are two.
Use a collection of java.util.Date instead of lotus.domino.local.DateTime
The lotus notes DateTime object has a method toJavaDate(), and a java.util.Date implements the Comparable interface for you
Implement a custom comparator for lotus.domino.local.DateTime object. It would probably be easiest to convert the date to a java date again, and use it's compare method, instead of re-inventing the wheel.
Create a custom Comparator that take as input the DateTime of Lotus.
Inside the code compare the DateTime as you need, for example converting them to a standard java.util.Date or getting single elements (year, month, date...) and comparing them singularly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With