]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/deletebydate/DateInfo.java
Version 17, September 2014
[GpsPrune.git] / tim / prune / function / deletebydate / DateInfo.java
1 package tim.prune.function.deletebydate;
2
3 import java.text.DateFormat;
4 import java.util.Date;
5
6 /**
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
10  */
11 public class DateInfo implements Comparable<DateInfo>
12 {
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;
21
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();
24
25         /**
26          * Constructor
27          * @param inDate date object from timestamp
28          */
29         public DateInfo(Date inDate)
30         {
31                 _date = inDate;
32                 if (_date == null) {
33                         _dateString = "";
34                 }
35                 else {
36                         _dateString = DEFAULT_DATE_FORMAT.format(_date);
37                 }
38                 _numPoints = 0;
39                 _toDelete = false;
40         }
41
42         /**
43          * @return true if this info is for dateless points (points without timestamp)
44          */
45         public boolean isDateless() {
46                 return (_date == null);
47         }
48
49         /**
50          * @return date object, or null
51          */
52         public Date getDate() {
53                 return _date;
54         }
55
56         /**
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
60          */
61         public boolean isSameDate(Date inDate)
62         {
63                 if (inDate == null) {
64                         return (_date == null);
65                 }
66                 else if (_dateString == null) {
67                         return false;
68                 }
69                 String otherDateString = DEFAULT_DATE_FORMAT.format(inDate);
70                 return _dateString.equals(otherDateString);
71         }
72
73         /**
74          * Increment the point count
75          */
76         public void incrementCount() {
77                 _numPoints++;
78         }
79
80         /**
81          * @return point count
82          */
83         public int getPointCount() {
84                 return _numPoints;
85         }
86
87         /**
88          * @param inFlag true to delete, false to keep
89          */
90         public void setDeleteFlag(boolean inFlag) {
91                 _toDelete = inFlag;
92         }
93
94         /**
95          * @return true to delete, false to keep
96          */
97         public boolean getDeleteFlag() {
98                 return _toDelete;
99         }
100
101         /**
102          * Compare with another DateInfo object for sorting
103          */
104         public int compareTo(DateInfo inOther)
105         {
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);
111         }
112 }