<commit_before>package com.rxbytes.splitpal.utils

import android.provider.ContactsContract.CommonDataKinds.Phone
import com.rxbytes.splitpal.ui.main.fragments.contacts.Contact
import macroid.ContextWrapper

/**
  * Created by pnagarjuna on 09/12/15.
  */
object Contactsq {

  def retrievePhoneContacts(implicit contextWrapper: ContextWrapper): Seq[Contact] = {
    val uri = Phone.CONTENT_URI
    val projection = Array[String](
      Phone.NUMBER
    )

    Seq.empty[Contact]
  }

}<commit_msg>cursor to list converter<commit_after>package com.rxbytes.splitpal.utils

import android.database.Cursor
import android.provider.ContactsContract
import android.provider.ContactsContract.CommonDataKinds.Phone
import android.util.Log
import com.rxbytes.splitpal.ui.main.fragments.contacts.Contact
import macroid.ContextWrapper

import scala.annotation.tailrec
import scala.concurrent.{ExecutionContext, Future}
import scala.util.{Failure, Success, Try}

/**
  * Created by pnagarjuna on 09/12/15.
  */
object Contacts {

  val LOG_TAG = classOf[Contacts.type].getSimpleName

  /*
  def retrievePhoneContacts(implicit contextWrapper: ContextWrapper): Seq[Contact] = {
    val cursor = contextWrapper.application.getContentResolver.query(Phone.CONTENT_URI, null, null, null, null)
    cursorToContactsList(cursor) {
      cursor =>
        var contacts = Seq.empty[Contact]
        cursor.moveToFirst()
        while (!cursor.isAfterLast) {
          val number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER))
          val contact = Contact(1, "", "Name", number, 100)
          contacts = contacts ++ Seq(contact)
          cursor.moveToNext()
        }
        contacts
    }
  }

  private[this] def cursorToContactsList(cursor: Cursor)(f: Cursor => Seq[Contact]): Seq[Contact] = {
    try {
      f(cursor)
    } catch {
      case ex: Exception =>
        Log.d(LOG_TAG, ex.getMessage)
        Seq.empty[Contact]
    } finally {
      cursor.close()
    }
  } **/

  def getListFromCursor[T](cursor: Option[Cursor], conversionFunction: Cursor => T): Seq[T] = {
    @tailrec
    def getListFromEntityLoop(cursor: Cursor, result: Seq[T]): Seq[T] = {
      cursor match {
        case validCursor if validCursor.isAfterLast => result
        case _ => {
          val entity = conversionFunction(cursor)
          cursor.moveToNext
          getListFromEntityLoop(cursor, entity +: result)
        }
      }
    }

    cursor match {
      case Some(cursorObject) =>
       val entityList = getListFromEntityLoop(cursorObject, Seq.empty[T])
        cursorObject.close()
        entityList
      case _ => Seq.empty[T]
    }

  }

  def tryToFuture[T](f: => Try[T])(implicit executionContext: ExecutionContext): Future[T] =
    Future(f).flatMap {
      case Success(success) => Future.successful(success)
      case Failure(failure) => Future.failed(failure)
    }


}
{'fraction_non_alphanumeric': 0.11007911936704506, 'fraction_numerical': 0.005503955968352253, 'mean_word_length': 3.2514619883040936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '5104283', 'n_tokens_mistral': 903, 'n_tokens_neox': 878, 'n_words': 170}