<commit_before>package com.intellibins.glassware.binlocation

import android.app.Application
import android.content.Context
import android.content.res.Resources
import android.util.Log
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.intellibins.glassware.R
import com.intellibins.glassware.model.Bin
import com.intellibins.glassware.model.nyc.BinData
import rx.Observable
import rx.Subscriber

class NycBinLocation implements IBinLocation {

    private Application mApp

    NycBinLocation(Application app) {
        mApp = app
    }

    private BinData parseJson(String jsonText) {
        Gson gson = new GsonBuilder().setPrettyPrinting().create()
        gson.fromJson(jsonText, BinData.class)
    }

    private Observable<String> getJsonText(Context context) {
        try {
            Resources res = context.getResources()
            InputStream inputStream = res.openRawResource(R.raw.json)
            byte[] b = new byte[inputStream.available()]
            int bytes = inputStream.read(b)
            bytes == -1 ? Observable.<String> empty()
                    : Observable.just(new String(b))
        } catch (Exception e) {
            Observable.empty()
        }
    }

    private Observable<Bin> makeBins(final BinData binData) {
        Observable.create({
            Subscriber<Bin> subscriber ->
                Thread.start({
                    List<List<String>> lists = binData.getData()
                    for (List<String> strings : lists) {
                        try {
                            int len = strings.size()
                            Bin bin = new Bin.Builder(strings.get(len - 4))
                                    .address(strings.get(len - 3))
                                    .latitude(Double.parseDouble(strings.get(len - 2)))
                                    .longitude(Double.parseDouble(strings.get(len - 1)))
                                    .build()
                            subscriber.onNext(bin)
                        } catch (Exception ex) {
                            Log.e(NycBinLocation.getSimpleName(), ex.toString())
                        }
                    }
                    subscriber.onCompleted()
                })
        } as Observable.OnSubscribe<Bin>)
    }

    @Override
    Observable<Bin> getBins() {
        getJsonText(mApp.getApplicationContext())
                .map({ String jsonText -> parseJson(jsonText) })
                .flatMap({ BinData binData -> makeBins(binData) })
    }
}<commit_msg>groovify :guitar:<commit_after>package com.intellibins.glassware.binlocation

import android.app.Application
import android.content.Context
import android.content.res.Resources
import android.util.Log
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.intellibins.glassware.R
import com.intellibins.glassware.model.Bin
import com.intellibins.glassware.model.nyc.BinData
import rx.Observable
import rx.Subscriber

class NycBinLocation implements IBinLocation {

    private Application mApp

    NycBinLocation(Application app) {
        mApp = app
    }

    private BinData parseJson(String jsonText) {
        Gson gson = new GsonBuilder().setPrettyPrinting().create()
        gson.fromJson(jsonText, BinData.class)
    }

    private Observable<String> getJsonText(Context context) {
        try {
            Resources res = context.getResources()
            InputStream inputStream = res.openRawResource(R.raw.json)
            byte[] b = new byte[inputStream.available()]
            int bytes = inputStream.read(b)
            bytes == -1 ? Observable.<String> empty()
                    : Observable.just(new String(b))
        } catch (Exception e) {
            Observable.empty()
        }
    }

    private Observable<Bin> makeBins(final BinData binData) {
        Observable.create({
            Subscriber<Bin> subscriber ->
                Thread.start({
                    List<List<String>> lists = binData.getData()
                    lists.each { ls ->
                        try {
                            int len = ls.size()
                            Bin bin = new Bin.Builder(ls.get(len - 4))
                                    .address(ls.get(len - 3))
                                    .latitude(Double.parseDouble(ls.get(len - 2)))
                                    .longitude(Double.parseDouble(ls.get(len - 1)))
                                    .build()
                            subscriber.onNext(bin)
                        } catch (Exception ex) {
                            Log.e(NycBinLocation.getSimpleName(), ex.toString())
                        }
                    }
                    subscriber.onCompleted()
                })
        } as Observable.OnSubscribe<Bin>)
    }

    @Override
    Observable<Bin> getBins() {
        getJsonText(mApp.getApplicationContext())
                .map({ String jsonText -> parseJson(jsonText) })
                .flatMap({ BinData binData -> makeBins(binData) })
    }
}
{'fraction_non_alphanumeric': 0.09684461202619567, 'fraction_numerical': 0.0019845207382417148, 'mean_word_length': 1.6442812172088144, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5834361', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1292, 'n_words': 251}