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 if (_previousInfo != null && _previousInfo.isSameDate(inDate))
30 _previousInfo.incrementCount();
34 // loop through list, seeing if date already present
35 boolean foundDate = false;
36 for (DateInfo info : _infoList)
38 if (info.isSameDate(inDate))
40 info.incrementCount();
46 // create new info if necessary
49 _previousInfo = new DateInfo(inDate);
50 _previousInfo.incrementCount();
51 _infoList.add(_previousInfo);
52 _hasBeenSorted = false;
58 * Clear the whole list
60 public void clearAll()
64 _hasBeenSorted = true;
68 * not used, can be removed
69 * @return true if any points without dates were found
71 public boolean hasDatelessPoints()
73 if (_infoList.isEmpty()) {return false;}
75 DateInfo firstInfo = _infoList.get(0);
76 return (firstInfo != null && firstInfo.isDateless() && firstInfo.getPointCount() > 0);
80 * @return number of entries in the list, including dateless points
82 public int getNumEntries()
84 return _infoList.size();
88 * @return the total number of points found, which should match the track size
90 public int getTotalNumPoints()
93 for (DateInfo info : _infoList) {
94 total += info.getPointCount();
100 * Sort the info list by ascending timestamps
106 Collections.sort(_infoList);
107 _hasBeenSorted = true;
112 * Get the DateInfo object at the given index
113 * @param inIndex index in (sorted) list
114 * @return corresponding object (may throw exception if out of range)
116 public DateInfo getDateInfo(int inIndex)
119 return _infoList.get(inIndex);