<commit_before>package net.azib.photos.cast

import android.app.Activity
import android.widget.ArrayAdapter
import android.widget.Filter
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.URL
import java.util.Collections.emptyList

class PhotoDirsSuggestionAdapter(context: Activity) : ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line) {
  private var suggestions: List<String> = emptyList()
  private val accessToken = context.getString(R.string.photos_dirs_access_token)
  private val url = context.getString(R.string.photos_dirs_url)

  override fun getCount() = suggestions.size
  override fun getItem(index: Int) = suggestions[index]

  fun getSuggestions(dir: String): List<String> {
    try {
      val url = URL("$url?dir=$dir&accessToken=$accessToken")
      BufferedReader(InputStreamReader(url.openStream())).useLines { return it.toList() }
    } catch (e: Exception) {
      return emptyList()
    }
  }

  override fun getFilter(): Filter {
    return object : Filter() {
      override fun performFiltering(constraint: CharSequence?): Filter.FilterResults {
        val results = Filter.FilterResults()
        if (constraint == null) return results
        suggestions = getSuggestions(constraint.toString())
        results.values = suggestions
        results.count = suggestions.size
        return results
      }

      override fun publishResults(constraint: CharSequence?, results: Filter.FilterResults) {
        if (results.count > 0)
          notifyDataSetChanged()
        else
          notifyDataSetInvalidated()
      }
    }
  }
}<commit_msg>even easier way to cope nullability<commit_after>package net.azib.photos.cast

import android.app.Activity
import android.widget.ArrayAdapter
import android.widget.Filter
import java.net.URL
import java.util.Collections.emptyList

class PhotoDirsSuggestionAdapter(context: Activity) : ArrayAdapter<String>(context, android.R.layout.simple_dropdown_item_1line) {
  private var suggestions: List<String> = emptyList()
  private val accessToken = context.getString(R.string.photos_dirs_access_token)
  private val url = context.getString(R.string.photos_dirs_url)

  override fun getCount() = suggestions.size
  override fun getItem(index: Int) = suggestions[index]

  fun getSuggestions(dir: CharSequence?): List<String> {
    try {
      val url = URL("$url?dir=$dir&accessToken=$accessToken")
      url.openStream().bufferedReader().useLines { return it.toList() }
    } catch (e: Exception) {
      return emptyList()
    }
  }

  override fun getFilter(): Filter {
    return object : Filter() {
      override fun performFiltering(constraint: CharSequence?): Filter.FilterResults {
        val results = Filter.FilterResults()
        suggestions = getSuggestions(constraint)
        results.values = suggestions
        results.count = suggestions.size
        return results
      }

      override fun publishResults(constraint: CharSequence?, results: Filter.FilterResults) {
        if (results.count > 0)
          notifyDataSetChanged()
        else
          notifyDataSetInvalidated()
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.0977084659452578, 'fraction_numerical': 0.001273074474856779, 'mean_word_length': 3.7477341389728096, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '2009921', 'n_tokens_mistral': 864, 'n_tokens_neox': 845, 'n_words': 194}