public Float getAsFloat(String key, Float def) {
   return contentValues.containsKey(key) && contentValues.get(key) != null
       ? contentValues.getAsFloat(key)
       : def;
 }
 @Override
 public Float getAsFloat(String key) {
   return contentValues.getAsFloat(key);
 }
  /**
   * (non-Javadoc)
   *
   * @see android.content.ContentProvider#insert(android.net.Uri, android.content.ContentValues)
   */
  @Override
  public Uri insert(Uri uri, ContentValues values) {
    // Log.d( TAG, "insert on "+uri );
    Uri insertedUri = null;
    int match = GPStrackingProvider.sURIMatcher.match(uri);
    List<String> pathSegments = null;
    long trackId;
    long segmentId;
    long waypointId = -1;
    switch (match) {
      case WAYPOINTS:
        pathSegments = uri.getPathSegments();
        trackId = Integer.parseInt(pathSegments.get(1));
        segmentId = Integer.parseInt(pathSegments.get(3));

        Location loc = new Location(TAG);

        Double latitude = values.getAsDouble(Waypoints.LATITUDE);
        Double longitude = values.getAsDouble(Waypoints.LONGITUDE);
        Long time = values.getAsLong(Waypoints.TIME);
        Float speed = values.getAsFloat(Waypoints.SPEED);
        if (time == null) {
          time = System.currentTimeMillis();
        }
        if (speed == null) {
          speed = 0f;
        }
        loc.setLatitude(latitude);
        loc.setLongitude(longitude);
        loc.setTime(time);
        loc.setSpeed(speed);

        if (values.containsKey(Waypoints.ACCURACY)) {
          loc.setAccuracy(values.getAsFloat(Waypoints.ACCURACY));
        }
        if (values.containsKey(Waypoints.ALTITUDE)) {
          loc.setAltitude(values.getAsDouble(Waypoints.ALTITUDE));
        }
        if (values.containsKey(Waypoints.BEARING)) {
          loc.setBearing(values.getAsFloat(Waypoints.BEARING));
        }
        waypointId = this.mDbHelper.insertWaypoint(trackId, segmentId, loc);
        //            Log.d( TAG, "Have inserted to segment "+segmentId+" with waypoint "+waypointId
        // );
        insertedUri = ContentUris.withAppendedId(uri, waypointId);
        break;
      case SEGMENTS:
        pathSegments = uri.getPathSegments();
        trackId = Integer.parseInt(pathSegments.get(1));
        segmentId = this.mDbHelper.toNextSegment(trackId);
        insertedUri = ContentUris.withAppendedId(uri, segmentId);
        break;
      case TRACKS:
        String name = (values == null) ? "" : values.getAsString(Tracks.NAME);
        trackId = this.mDbHelper.toNextTrack(name);
        insertedUri = ContentUris.withAppendedId(uri, trackId);
        break;
      default:
        Log.e(GPStrackingProvider.LOG_TAG, "Unable to match the URI:" + uri.toString());
        insertedUri = null;
        break;
    }
    return insertedUri;
  }