Mercurial > cgi-bin > hgweb.cgi > PassMan
comparison src/main/kotlin/name/blackcap/passman/Entry.kt @ 7:f245b9a53495
Efficiency improvements.
author | David Barts <n5jrn@me.com> |
---|---|
date | Tue, 20 Sep 2022 21:54:32 -0700 |
parents | ad997df1f560 |
children | 698c4a3d758d |
comparison
equal
deleted
inserted
replaced
6:711cc42e96d7 | 7:f245b9a53495 |
---|---|
1 package name.blackcap.passman | 1 package name.blackcap.passman |
2 | 2 |
3 import java.util.* | 3 import java.util.* |
4 import kotlin.reflect.KProperty | |
5 import kotlin.reflect.full.declaredMemberProperties | |
4 | 6 |
5 class Entry(val name: String, val username: String, val password: CharArray, val notes: String, | 7 class Entry(val name: String, val username: String, val password: CharArray, val notes: String, |
6 val created: Date? = null, val modified: Date? = null, val accessed: Date? = null) { | 8 val created: Date? = null, val modified: Date? = null, val accessed: Date? = null) { |
7 | 9 |
8 companion object { | 10 companion object { |
11 private val FIELD_MAP = mutableMapOf<String, KProperty.Getter<*>>().apply { | |
12 Entry::class.declaredMemberProperties.forEach{ | |
13 this[it.name] = it.getter | |
14 } | |
15 } | |
16 | |
9 fun withPromptedPassword() = Entry( | 17 fun withPromptedPassword() = Entry( |
10 name = _getName(), | 18 name = _getName(), |
11 username = _getUsername(), | 19 username = _getUsername(), |
12 password = _getPassword(), | 20 password = _getPassword(), |
13 notes = _getNotes() | 21 notes = _getNotes() |
55 printDate("Created", created) | 63 printDate("Created", created) |
56 printDate("Modified", modified) | 64 printDate("Modified", modified) |
57 printDate("Accessed", accessed) | 65 printDate("Accessed", accessed) |
58 } | 66 } |
59 | 67 |
68 fun getField(name: String): Any? { | |
69 return FIELD_MAP[name]!!.call(this) | |
70 } | |
71 | |
60 private fun printDate(tag: String, date: Date?) { | 72 private fun printDate(tag: String, date: Date?) { |
61 kotlin.io.print("${tag}: ") | 73 kotlin.io.print("${tag}: ") |
62 if (date == null) { | 74 if (date == null) { |
63 println("never") | 75 println("never") |
64 } else { | 76 } else { |