1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
package tim.prune.function.deletebydate;
import java.text.DateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* Class to hold the information about a date,
* including how many points correspond to the date
* and whether it has been selected for deletion or not
*/
public class DateInfo implements Comparable<DateInfo>
{
/** Date, or null for no date - used for earlier/later comparison */
private final Date _date;
/** String representation of date */
private final String _dateString;
/** Number of points with this date */
private int _numPoints = 0;
/** Flag for deletion or retention */
private boolean _toDelete = false;
// Doesn't really matter what format is used here, as long as dates are different
private static final DateFormat DEFAULT_DATE_FORMAT = DateFormat.getDateInstance();
/**
* @param inZone Timezone to use for the date identification
*/
public static void setTimezone(TimeZone inZone)
{
DEFAULT_DATE_FORMAT.setTimeZone(inZone);
}
/**
* Constructor
* @param inDate date object from timestamp
*/
public DateInfo(Date inDate)
{
_date = inDate;
if (_date == null) {
_dateString = "";
}
else {
_dateString = DEFAULT_DATE_FORMAT.format(_date);
}
_numPoints = 0;
_toDelete = false;
}
/**
* @return true if this info is for dateless points (points without timestamp)
*/
public boolean isDateless() {
return (_date == null);
}
/**
* @return string representation of date
*/
public String getString() {
return _dateString;
}
/**
* Compare with a given Date object to see if they represent the same date
* @param inDate date to compare
* @return true if they're the same date
*/
public boolean isSameDate(Date inDate)
{
if (inDate == null) {
return (_date == null);
}
else if (_dateString == null) {
return false;
}
String otherDateString = DEFAULT_DATE_FORMAT.format(inDate);
return _dateString.equals(otherDateString);
}
/**
* Increment the point count
*/
public void incrementCount() {
_numPoints++;
}
/**
* @return point count
*/
public int getPointCount() {
return _numPoints;
}
/**
* @param inFlag true to delete, false to keep
*/
public void setDeleteFlag(boolean inFlag) {
_toDelete = inFlag;
}
/**
* @return true to delete, false to keep
*/
public boolean getDeleteFlag() {
return _toDelete;
}
/**
* Compare with another DateInfo object for sorting
*/
public int compareTo(DateInfo inOther)
{
// Dateless goes first
if (_date == null || _dateString == null) {return -1;}
if (inOther._date == null || inOther._dateString == null) {return 1;}
// Just compare dates
return _date.compareTo(inOther._date);
}
}
|