/**
   * This method determines if an observation record is within a certain radius,
   * _terminalSearchRadius argument, of a stop at the start or end of a trip. <br>
   * Note: all trips' stops within the radius are checked.
   *
   * @param record
   * @return whether the observation is within the search radius
   */
  public boolean isAtPotentialTripTerminal(NycRawLocationRecord record) {

    final CoordinatePoint loc = new CoordinatePoint(record.getLatitude(), record.getLongitude());
    final CoordinateBounds bounds = SphericalGeometryLibrary.bounds(loc, _terminalSearchRadius);

    final List<StopEntry> stops = _transitGraphDao.getStopsByLocation(bounds);
    for (final StopEntry stop : stops) {
      final List<BlockStopTimeIndex> stopTimeIndices =
          _blockIndexService.getStopTimeIndicesForStop(stop);
      for (final BlockStopTimeIndex stopTimeIndex : stopTimeIndices) {
        for (final BlockTripEntry bte : stopTimeIndex.getTrips()) {
          /*
           * is this the first stop on this trip?
           */
          final List<StopTimeEntry> stopsOnTrip = bte.getTrip().getStopTimes();
          if (stop.equals(stopsOnTrip.get(0).getStop())) {
            return true;
          }

          final int numOfStops = stopsOnTrip.size() - 1;
          if (stop.equals(stopsOnTrip.get(numOfStops).getStop())) {
            return true;
          }
        }
      }
    }

    return false;
  }