<commit_before>package com.mapbox.services.geocoding.v5;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mapbox.services.Constants;
import com.mapbox.services.commons.MapboxBuilder;
import com.mapbox.services.commons.MapboxService;
import com.mapbox.services.commons.ServicesException;
import com.mapbox.services.commons.geojson.Geometry;
import com.mapbox.services.commons.models.Position;
import com.mapbox.services.commons.utils.TextUtils;
import com.mapbox.services.geocoding.v5.gson.CarmenGeometryDeserializer;
import com.mapbox.services.geocoding.v5.models.GeocodingResponse;

import java.io.IOException;
import java.util.Locale;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * The Mapbox geocoding client (v5).
 */
public class MapboxGeocoding extends MapboxService<GeocodingResponse> {

    private Builder builder = null;
    private GeocodingService service = null;
    private Call<GeocodingResponse> call = null;
    private Observable<GeocodingResponse> observable = null;

    // Allows testing
    private String baseUrl = Constants.BASE_API_URL;

    public MapboxGeocoding(Builder builder) {
        this.builder = builder;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public GeocodingService getService() {
        // No need to recreate it
        if (service != null) return service;

        // Gson instance with type adapters
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Geometry.class, new CarmenGeometryDeserializer())
                .create();

        Retrofit retrofit = new Retrofit.Builder()
                .client(getOkHttpClient())
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

        service = retrofit.create(GeocodingService.class);
        return service;
    }

    public Call<GeocodingResponse> getCall() {
        // No need to recreate it
        if (call != null) return call;

        call = getService().getCall(
                getHeaderUserAgent(),
                builder.getMode(),
                builder.getQuery(),
                builder.getAccessToken(),
                builder.getCountry(),
                builder.getProximity(),
                builder.getGeocodingTypes(),
                builder.getAutocomplete(),
                builder.getBbox());

        return call;
    }

    @Override
    public Response<GeocodingResponse> executeCall() throws IOException {
        return getCall().execute();
    }

    @Override
    public void enqueueCall(Callback<GeocodingResponse> callback) {
        getCall().enqueue(callback);
    }

    @Override
    public void cancelCall() {
        getCall().cancel();
    }

    @Override
    public Call<GeocodingResponse> cloneCall() {
        return getCall().clone();
    }

    @Override
    public Observable<GeocodingResponse> getObservable() {
        // No need to recreate it
        if (observable != null) return observable;

        observable = getService().getObservable(
                getHeaderUserAgent(),
                builder.getMode(),
                builder.getQuery(),
                builder.getCountry(),
                builder.getAccessToken(),
                builder.getProximity(),
                builder.getGeocodingTypes(),
                builder.getAutocomplete(),<commit_msg>one more place where https://github.com/mapbox/mapbox-java/pull/98 is necessary<commit_after>package com.mapbox.services.geocoding.v5;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mapbox.services.Constants;
import com.mapbox.services.commons.MapboxBuilder;
import com.mapbox.services.commons.MapboxService;
import com.mapbox.services.commons.ServicesException;
import com.mapbox.services.commons.geojson.Geometry;
import com.mapbox.services.commons.models.Position;
import com.mapbox.services.commons.utils.TextUtils;
import com.mapbox.services.geocoding.v5.gson.CarmenGeometryDeserializer;
import com.mapbox.services.geocoding.v5.models.GeocodingResponse;

import java.io.IOException;
import java.util.Locale;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

/**
 * The Mapbox geocoding client (v5).
 */
public class MapboxGeocoding extends MapboxService<GeocodingResponse> {

    private Builder builder = null;
    private GeocodingService service = null;
    private Call<GeocodingResponse> call = null;
    private Observable<GeocodingResponse> observable = null;

    // Allows testing
    private String baseUrl = Constants.BASE_API_URL;

    public MapboxGeocoding(Builder builder) {
        this.builder = builder;
    }

    public void setBaseUrl(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public GeocodingService getService() {
        // No need to recreate it
        if (service != null) return service;

        // Gson instance with type adapters
        Gson gson = new GsonBuilder()
                .registerTypeAdapter(Geometry.class, new CarmenGeometryDeserializer())
                .create();

        Retrofit retrofit = new Retrofit.Builder()
                .client(getOkHttpClient())
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

        service = retrofit.create(GeocodingService.class);
        return service;
    }

    public Call<GeocodingResponse> getCall() {
        // No need to recreate it
        if (call != null) return call;

        call = getService().getCall(
                getHeaderUserAgent(),
                builder.getMode(),
                builder.getQuery(),
                builder.getAccessToken(),
                builder.getCountry(),
                builder.getProximity(),
                builder.getGeocodingTypes(),
                builder.getAutocomplete(),
                builder.getBbox());

        return call;
    }

    @Override
    public Response<GeocodingResponse> executeCall() throws IOException {
        return getCall().execute();
    }

    @Override
    public void enqueueCall(Callback<GeocodingResponse> callback) {
        getCall().enqueue(callback);
    }

    @Override
    public void cancelCall() {
        getCall().cancel();
    }

    @Override
    public Call<GeocodingResponse> cloneCall() {
        return getCall().clone();
    }

    @Override
    public Observable<GeocodingResponse> getObservable() {
        // No need to recreate it
        if (observable != null) return observable;

        observable = getService().getObservable(
                getHeaderUserAgent(),
                builder.getMode(),
                builder.getQuery(),
                builder.getAccessToken(),
                builder.getCountry(),
                builder.getProximity(),
                builder.getGeocodingTypes(),
                builder.getAutocomplete(),
{'fraction_non_alphanumeric': 0.09527008868583714, 'fraction_numerical': 0.002956194571351787, 'mean_word_length': 2.5697841726618704, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6819421', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1972, 'n_words': 403}