Last active
March 5, 2022 18:27
-
-
Save evilthreads669966/2208bbf704c8804558ced6cf5aaa31ed to your computer and use it in GitHub Desktop.
check register..just playing around
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun main(){ | |
val user = User().apply { | |
val account = Account("Capital One", 12345) | |
createAccount(account) | |
val cocaCola = Vendor("Coca Cola") | |
createVendor(cocaCola) | |
val beverages = Category("beverages") | |
createCategory(beverages) | |
writeCheck(account, 1, cocaCola, beverages, 113.30) | |
} | |
user.checks.forEach { println(it) } | |
} | |
data class Category(val name: String) | |
data class Account(val name: String, val id: Int){ | |
private val _checkRegister = CheckRegister() | |
val checks: List<Check> | |
get() = _checkRegister.checks | |
fun addCheck(check: Check) = _checkRegister.checks.add(check) | |
fun removeCheck(check: Check) = _checkRegister.checks.remove(check) | |
} | |
data class User( | |
private val _accounts: MutableList<Account> = mutableListOf(), | |
private val _vendors: MutableList<Vendor> = mutableListOf(), | |
private val _categories: MutableList<Category> = mutableListOf() | |
){ | |
val checks: List<Check> | |
get(){ | |
return mutableListOf<Check>().apply { | |
_accounts.forEach { addAll(it.checks) } | |
} | |
} | |
fun createAccount(vararg account: Account) = account.forEach { _accounts.add(it) } | |
fun writeCheck(account: Account, id: Int, vendor: Vendor, category: Category, amount: Double){ | |
val newCheck = Check(id, vendor, category, amount, System.currentTimeMillis()) | |
this._accounts.first { it.equals(account) }.addCheck(newCheck) | |
} | |
fun createCategory(vararg category: Category) = category.forEach { _categories.add(it) } | |
fun createVendor(vararg vendor: Vendor) = vendor.forEach { _vendors.add(it) } | |
} | |
@JvmInline | |
value class CheckRegister(val checks: MutableList<Check> = mutableListOf()) | |
data class Check( | |
val id: Int, | |
val vendor: Vendor, | |
val category: Category, | |
val amount: Double, | |
val date: Long | |
) | |
data class Vendor(val name: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment