VehicleLocationRecord record = _tripsLibrary.createVehicleLocationRecordForUpdate(result, update);
if (record != null) {
if (record.getTripId() != null) {
result.addUnmatchedTripId(record.getTripId().toString());
}
AgencyAndId vehicleId = record.getVehicleId();
seenVehicles.add(vehicleId);
Date timestamp = new Date(record.getTimeOfRecord());
Date prev = _lastVehicleUpdate.get(vehicleId);
if (prev == null || prev.before(timestamp)) {
_vehicleLocationListener.handleVehicleLocationRecord(record);
_lastVehicleUpdate.put(vehicleId, timestamp);
}
}
}
Calendar c = Calendar.getInstance();
c.add(Calendar.MINUTE, -15);
Date staleRecordThreshold = c.getTime();
Iterator<Map.Entry<AgencyAndId, Date>> it = _lastVehicleUpdate.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<AgencyAndId, Date> entry = it.next();
AgencyAndId vehicleId = entry.getKey();
Date lastUpdateTime = entry.getValue();
if (!seenVehicles.contains(vehicleId)
&& lastUpdateTime.before(staleRecordThreshold)) {
it.remove();
}