<commit_before>package bookdlab.bookd.database;

import android.util.Log;

import com.firebase.geofire.GeoLocation;
import com.firebase.geofire.GeoQueryEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

import bookdlab.bookd.interfaces.NearbyBusinessCallback;
import bookdlab.bookd.interfaces.UserCheckCallback;
import bookdlab.bookd.models.Business;
import bookdlab.bookd.models.User;

/**
 * Created by pranavkonduru on 11/19/16.
 */

public class QueryHelper {

    private static final String TAG = "QueryHelper";

    public static void isUserPresentInDatabase(String email, UserCheckCallback callback){
        Queries queries = new Queries();
        queries.getUserFromEmail(email).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Iterable<DataSnapshot> children = dataSnapshot.getChildren();
                if(!children.iterator().hasNext()){
                    Log.d(TAG, "User not present in database");
                    callback.userIsNotPresent();
                } else {
                    User signedInUser = new User();
                    for(DataSnapshot child : children){
                        signedInUser = child.getValue(User.class);
                    }
                    callback.userIsPresent(signedInUser);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

    public static void getBusinessesInArea(Double lat, Double lng, Double radius, NearbyBusinessCallback callback){
        Queries queries = new Queries();
        ArrayList<String> businessIds = new ArrayList<>();

        queries.getNearbyBusiness(lat, lng, radius).addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
                Log.d(TAG, "onKeyEntered: "+key);
                businessIds.add(key);
            }

            @Override
            public void onKeyExited(String key) {

            }

            @Override
            public void onKeyMoved(String key, GeoLocation location) {

            }

            @Override
            public void onGeoQueryReady() {
                Log.d(TAG, "onGeoQueryReady: all queries complete");
                getBusinessNearByFromId(businessIds, callback);
            }

            @Override
            public void onGeoQueryError(DatabaseError error) {

            }
        });
    }

    private static void getBusinessNearByFromId(ArrayList<String> ids, NearbyBusinessCallback callback){
        Queries queries = new Queries();
        ArrayList<Business> businesses = new ArrayList<>();
        for(String id: ids) {
            queries.getBusinessById(id).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for(DataSnapshot child: dataSnapshot.getChildren()){
                        Log.d(TAG, "onDataChange: adding business");
                        Business business = child.getValue(Business.class);
                        businesses.add(business);

                        // After adding all businesses, callback
                        if(businesses.size() == ids.size()){
                            callback.onNearbyBusinessesFound(businesses);
                        }
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }

    }
}
<commit_msg>ability to remove events<commit_after>package bookdlab.bookd.database;

import android.util.Log;

import com.firebase.geofire.GeoLocation;
import com.firebase.geofire.GeoQueryEventListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

import bookdlab.bookd.interfaces.NearbyBusinessCallback;
import bookdlab.bookd.interfaces.UserCheckCallback;
import bookdlab.bookd.models.Business;
import bookdlab.bookd.models.User;

/**
 * Created by pranavkonduru on 11/19/16.
 */

public class QueryHelper {

    private static final String TAG = "QueryHelper";

    public static void isUserPresentInDatabase(String email, UserCheckCallback callback){
        Queries queries = new Queries();
        queries.getUserFromEmail(email).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                Iterable<DataSnapshot> children = dataSnapshot.getChildren();
                if(!children.iterator().hasNext()){
                    Log.d(TAG, "User not present in database");
                    callback.userIsNotPresent();
                } else {
                    User signedInUser = new User();
                    for(DataSnapshot child : children){
                        signedInUser = child.getValue(User.class);
                    }
                    callback.userIsPresent(signedInUser);
                }
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    }

    public static void getBusinessesInArea(Double lat, Double lng, Double radius, NearbyBusinessCallback callback){
        Queries queries = new Queries();
        ArrayList<String> businessIds = new ArrayList<>();

        queries.getNearbyBusiness(lat, lng, radius).addGeoQueryEventListener(new GeoQueryEventListener() {
            @Override
            public void onKeyEntered(String key, GeoLocation location) {
                Log.d(TAG, "onKeyEntered: "+key);
                businessIds.add(key);
            }

            @Override
            public void onKeyExited(String key) {

            }

            @Override
            public void onKeyMoved(String key, GeoLocation location) {

            }

            @Override
            public void onGeoQueryReady() {
                Log.d(TAG, "onGeoQueryReady: all queries complete");
                getBusinessNearByFromId(businessIds, callback);
            }

            @Override
            public void onGeoQueryError(DatabaseError error) {

            }
        });
    }

    private static void getBusinessNearByFromId(ArrayList<String> ids, NearbyBusinessCallback callback){
        Queries queries = new Queries();
        ArrayList<Business> businesses = new ArrayList<>();
        for(String id: ids) {
            queries.getBusinessById(id).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {
                    for(DataSnapshot child: dataSnapshot.getChildren()){
                        Log.d(TAG, "onDataChange: adding business");
                        Business business = child.getValue(Business.class);
                        businesses.add(business);

                        // After adding all businesses, callback
                        if(businesses.size() == ids.size()){
                            callback.onNearbyBusinessesFound(businesses);
                        }
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    }

    public static void removeEventWithId(String eventId, OnSuccessListener<Void> listener){
        Queries queries = new Queries();
        queries.getBookedBusinessesForEvent(eventId).addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                dataSnapshot.getRef().setValue(null);
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
        FirebaseDatabase.getInstance().getReference().child("events").child(eventId).removeValue().addOnSuccessListener(listener);
    }
}

{'fraction_non_alphanumeric': 0.08441172978748665, 'fraction_numerical': 0.0014246705449364834, 'mean_word_length': 1.9914772727272727, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '1084854', 'n_tokens_mistral': 2119, 'n_tokens_neox': 1981, 'n_words': 420}