package com.example.criminalintent
import java.util.*

object CrimeLab {
//singleton object, never be more than one of them
    private val mCrimes:MutableList<Crime>?
    val crimes:List<Crime>?
        get() = mCrimes

    //Because mCrimes is private, it can't be used outside the class
    //but crimes variable can be.  notice that it's not even set to anything
    //it doesn't even a value, but a get() is defined for it, it just returns mCrimes

    //In Kotlin, if I use something like y = MyStuff.x , it doesn't
    //really look at the x variable, it calls a get() method
    //For something like MyStuff.x = y, even though I don't have
    //the word set() in there, it's calling set method
    fun getCrime (id:UUID?):Crime? {
        for (crime in mCrimes!!)
            if (crime.mId==id) return crime
        return null
    }

    init { //runs first
        mCrimes = ArrayList()
        for (i in 0..99) {
            val crime = Crime()
            crime.mTitle = "Crime #${i}"
            crime.mSolved = i%2==0
            mCrimes.add(crime)
        }
    }
}
