1 package tim.prune.function.deletebydate;
3 import java.util.ArrayList;
4 import java.util.Collections;
9 * List of date info objects for use by the table model
11 public class DateInfoList
13 /** list of info about points according to date */
14 private List<DateInfo> _infoList = new ArrayList<DateInfo>();
15 /** previously used dateinfo object to reduce list searching */
16 private DateInfo _previousInfo = null;
17 /** true if the list has been sorted, false otherwise */
18 private boolean _hasBeenSorted = false;
22 * Add a point to the corresponding dateinfo
23 * @param inDate date of current point, or null if no timestamp
25 public void addPoint(Date inDate)
27 DateInfo currentInfo = null;
28 if (_previousInfo != null && _previousInfo.isSameDate(inDate))
31 currentInfo = _previousInfo;
35 // loop through list, to see if date already present
36 for (DateInfo info : _infoList)
38 if (info.isSameDate(inDate))
44 // create new info if necessary
45 if (currentInfo == null)
47 currentInfo = new DateInfo(inDate);
48 _infoList.add(currentInfo);
49 _hasBeenSorted = false;
51 _previousInfo = currentInfo;
53 // Now we've identified the current info or created a new one
54 currentInfo.incrementCount();
58 * Clear the whole list
60 public void clearAll()
64 _hasBeenSorted = true;
68 * @return number of entries in the list, including dateless points
70 public int getNumEntries()
72 return _infoList.size();
76 * @return the total number of points found, which should match the track size
78 public int getTotalNumPoints()
81 for (DateInfo info : _infoList) {
82 total += info.getPointCount();
88 * Sort the info list by ascending timestamps
94 Collections.sort(_infoList);
95 _hasBeenSorted = true;
100 * Get the DateInfo object at the given index
101 * @param inIndex index in (sorted) list
102 * @return corresponding object (may throw exception if out of range)
104 public DateInfo getDateInfo(int inIndex)
107 return _infoList.get(inIndex);