1 package tim.prune.function.deletebydate;
3 import java.text.DateFormat;
7 * Class to hold the information about a date,
8 * including how many points correspond to the date
9 * and whether it has been selected for deletion or not
11 public class DateInfo implements Comparable<DateInfo>
13 /** Date, or null for no date - used for earlier/later comparison */
14 private Date _date = null;
15 /** String representation of date, for equality comparison */
16 private String _dateString = null;
17 /** Number of points with this date */
18 private int _numPoints = 0;
19 /** Flag for deletion or retention */
20 private boolean _toDelete = false;
22 // Doesn't really matter what format is used here, as long as dates are different
23 private static final DateFormat DEFAULT_DATE_FORMAT = DateFormat.getDateInstance();
27 * @param inDate date object from timestamp
29 public DateInfo(Date inDate)
36 _dateString = DEFAULT_DATE_FORMAT.format(_date);
43 * @return true if this info is for dateless points (points without timestamp)
45 public boolean isDateless() {
46 return (_date == null);
50 * @return date object, or null
52 public Date getDate() {
57 * Compare with a given Date object to see if they represent the same date
58 * @param inDate date to compare
59 * @return true if they're the same date
61 public boolean isSameDate(Date inDate)
64 return (_date == null);
66 else if (_dateString == null) {
69 String otherDateString = DEFAULT_DATE_FORMAT.format(inDate);
70 return _dateString.equals(otherDateString);
74 * Increment the point count
76 public void incrementCount() {
83 public int getPointCount() {
88 * @param inFlag true to delete, false to keep
90 public void setDeleteFlag(boolean inFlag) {
95 * @return true to delete, false to keep
97 public boolean getDeleteFlag() {
102 * Compare with another DateInfo object for sorting
104 public int compareTo(DateInfo inOther)
106 // Dateless goes first
107 if (_date == null || _dateString == null) {return -1;}
108 if (inOther._date == null || inOther._dateString == null) {return 1;}
109 // Just compare dates
110 return _date.compareTo(inOther._date);