]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/function/deletebydate/DateInfo.java
Version 19, May 2018
[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 import java.util.TimeZone;
6
7 /**
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
11  */
12 public class DateInfo implements Comparable<DateInfo>
13 {
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;
22
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();
25
26
27         /**
28          * @param inZone Timezone to use for the date identification
29          */
30         public static void setTimezone(TimeZone inZone)
31         {
32                 DEFAULT_DATE_FORMAT.setTimeZone(inZone);
33         }
34
35         /**
36          * Constructor
37          * @param inDate date object from timestamp
38          */
39         public DateInfo(Date inDate)
40         {
41                 _date = inDate;
42                 if (_date == null) {
43                         _dateString = "";
44                 }
45                 else {
46                         _dateString = DEFAULT_DATE_FORMAT.format(_date);
47                 }
48                 _numPoints = 0;
49                 _toDelete = false;
50         }
51
52         /**
53          * @return true if this info is for dateless points (points without timestamp)
54          */
55         public boolean isDateless() {
56                 return (_date == null);
57         }
58
59         /**
60          * @return string representation of date
61          */
62         public String getString() {
63                 return _dateString;
64         }
65
66         /**
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
70          */
71         public boolean isSameDate(Date inDate)
72         {
73                 if (inDate == null) {
74                         return (_date == null);
75                 }
76                 else if (_dateString == null) {
77                         return false;
78                 }
79                 String otherDateString = DEFAULT_DATE_FORMAT.format(inDate);
80                 return _dateString.equals(otherDateString);
81         }
82
83         /**
84          * Increment the point count
85          */
86         public void incrementCount() {
87                 _numPoints++;
88         }
89
90         /**
91          * @return point count
92          */
93         public int getPointCount() {
94                 return _numPoints;
95         }
96
97         /**
98          * @param inFlag true to delete, false to keep
99          */
100         public void setDeleteFlag(boolean inFlag) {
101                 _toDelete = inFlag;
102         }
103
104         /**
105          * @return true to delete, false to keep
106          */
107         public boolean getDeleteFlag() {
108                 return _toDelete;
109         }
110
111         /**
112          * Compare with another DateInfo object for sorting
113          */
114         public int compareTo(DateInfo inOther)
115         {
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);
121         }
122 }