1 package tim.prune.function.deletebydate;
3 import java.text.DateFormat;
5 import java.util.TimeZone;
8 * Class to hold the information about a date,
9 * including how many points correspond to the date
10 * and whether it has been selected for deletion or not
12 public class DateInfo implements Comparable<DateInfo>
14 /** Date, or null for no date - used for earlier/later comparison */
15 private Date _date = null;
16 /** String representation of date */
17 private String _dateString = null;
18 /** Number of points with this date */
19 private int _numPoints = 0;
20 /** Flag for deletion or retention */
21 private boolean _toDelete = false;
23 // Doesn't really matter what format is used here, as long as dates are different
24 private static final DateFormat DEFAULT_DATE_FORMAT = DateFormat.getDateInstance();
28 * @param inZone Timezone to use for the date identification
30 public static void setTimezone(TimeZone inZone)
32 DEFAULT_DATE_FORMAT.setTimeZone(inZone);
37 * @param inDate date object from timestamp
39 public DateInfo(Date inDate)
46 _dateString = DEFAULT_DATE_FORMAT.format(_date);
53 * @return true if this info is for dateless points (points without timestamp)
55 public boolean isDateless() {
56 return (_date == null);
60 * @return string representation of date
62 public String getString() {
67 * Compare with a given Date object to see if they represent the same date
68 * @param inDate date to compare
69 * @return true if they're the same date
71 public boolean isSameDate(Date inDate)
74 return (_date == null);
76 else if (_dateString == null) {
79 String otherDateString = DEFAULT_DATE_FORMAT.format(inDate);
80 return _dateString.equals(otherDateString);
84 * Increment the point count
86 public void incrementCount() {
93 public int getPointCount() {
98 * @param inFlag true to delete, false to keep
100 public void setDeleteFlag(boolean inFlag) {
105 * @return true to delete, false to keep
107 public boolean getDeleteFlag() {
112 * Compare with another DateInfo object for sorting
114 public int compareTo(DateInfo inOther)
116 // Dateless goes first
117 if (_date == null || _dateString == null) {return -1;}
118 if (inOther._date == null || inOther._dateString == null) {return 1;}
119 // Just compare dates
120 return _date.compareTo(inOther._date);