<commit_before>package com.gaiagps.iburn.database;

import android.support.annotation.NonNull;

import com.gaiagps.iburn.BuildConfig;
import com.gaiagps.iburn.CurrentDateProvider;
import com.gaiagps.iburn.PrefsHelper;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;

/**
 * A data restriction policy that ensures location data never leaves the database
 * before {@link #EMBARGO_DATE} and without {@link PrefsHelper#enteredValidUnlockCode()}
 *
 * Created by davidbrodsky on 7/1/15.
 */
public class Embargo implements DataProvider.QueryInterceptor {

    // 2015 Embargo date is August 25, 2015.
    public  static final Date   EMBARGO_DATE   = new GregorianCalendar(2015, Calendar.AUGUST, 30, 0, 0).getTime();

    // For debug builds, force user to enter unlock code
    private static final boolean FORCE_EMBARGO = BuildConfig.MOCK;
    private static final String NULL_LATITUDE  = "NULL AS " + PlayaItemTable.latitude;
    private static final String NULL_LONGITUDE = "NULL AS " + PlayaItemTable.longitude;
    private static final String NULL_ADDRESS = "NULL AS " + PlayaItemTable.playaAddress;

    private PrefsHelper prefs;

    public Embargo(PrefsHelper prefs) {
        this.prefs = prefs;
    }

    @Override
    public String onQueryIntercepted(@NonNull String query, @NonNull Iterable<String> tables) {
        // If Embargo is active and this query does not select from POIS
        if (isEmbargoActive(prefs) && !isPoiTableQuery(tables)) {
            return query.replace(PlayaItemTable.latitude, NULL_LATITUDE)
                    .replace(PlayaItemTable.longitude, NULL_LONGITUDE)
                    .replace(PlayaItemTable.playaAddress, NULL_ADDRESS)
                    .replace("SELECT *", "SELECT *, " + NULL_LATITUDE + ", " + NULL_LONGITUDE + ", " + NULL_ADDRESS);
        }
        return query;
    }

    private boolean isPoiTableQuery(Iterable<String> tables) {
        Iterator<String> tableIterator = tables.iterator();
        String tableName = tableIterator.next();<commit_msg>2016 embargo date<commit_after>package com.gaiagps.iburn.database;

import android.support.annotation.NonNull;

import com.gaiagps.iburn.BuildConfig;
import com.gaiagps.iburn.CurrentDateProvider;
import com.gaiagps.iburn.PrefsHelper;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;

/**
 * A data restriction policy that ensures location data never leaves the database
 * before {@link #EMBARGO_DATE} and without {@link PrefsHelper#enteredValidUnlockCode()}
 *
 * Created by davidbrodsky on 7/1/15.
 */
public class Embargo implements DataProvider.QueryInterceptor {

    // 2015 Embargo date is August 25, 2015.
    public  static final Date   EMBARGO_DATE   = new GregorianCalendar(2016, Calendar.AUGUST, 28, 0, 0).getTime();

    // For debug builds, force user to enter unlock code
    private static final boolean FORCE_EMBARGO = BuildConfig.MOCK;
    private static final String NULL_LATITUDE  = "NULL AS " + PlayaItemTable.latitude;
    private static final String NULL_LONGITUDE = "NULL AS " + PlayaItemTable.longitude;
    private static final String NULL_ADDRESS = "NULL AS " + PlayaItemTable.playaAddress;

    private PrefsHelper prefs;

    public Embargo(PrefsHelper prefs) {
        this.prefs = prefs;
    }

    @Override
    public String onQueryIntercepted(@NonNull String query, @NonNull Iterable<String> tables) {
        // If Embargo is active and this query does not select from POIS
        if (isEmbargoActive(prefs) && !isPoiTableQuery(tables)) {
            return query.replace(PlayaItemTable.latitude, NULL_LATITUDE)
                    .replace(PlayaItemTable.longitude, NULL_LONGITUDE)
                    .replace(PlayaItemTable.playaAddress, NULL_ADDRESS)
                    .replace("SELECT *", "SELECT *, " + NULL_LATITUDE + ", " + NULL_LONGITUDE + ", " + NULL_ADDRESS);
        }
        return query;
    }

    private boolean isPoiTableQuery(Iterable<String> tables) {
        Iterator<String> tableIterator = tables.iterator();
        String tableName = tableIterator.next();
{'fraction_non_alphanumeric': 0.0893371757925072, 'fraction_numerical': 0.011527377521613832, 'mean_word_length': 3.5124593716143013, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '6612240', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1220, 'n_words': 321}