-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Candidate and CandidateType; implement db.match(text:)
- Loading branch information
1 parent
bbce823
commit 226c7c3
Showing
4 changed files
with
44 additions
and
9 deletions.
There are no files selected for viewing
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
19 changes: 17 additions & 2 deletions
19
app/src/main/java/org/jyutping/jyutping/keyboard/Candidate.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
package org.jyutping.jyutping.keyboard | ||
|
||
data class Candidate( | ||
val type: CandidateType = CandidateType.CANTONESE, | ||
val type: CandidateType = CandidateType.Cantonese, | ||
val text: String, | ||
val lexiconText: String = text, | ||
val romanization: String, | ||
val input: String, | ||
val mark: String = input, | ||
val order: Int = 0 | ||
) | ||
) { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (other !is Candidate) return false | ||
if (this.type != other.type) return false | ||
if (this.type.isCantonese() && other.type.isCantonese()) { | ||
return (this.text == other.text) && (this.romanization == other.romanization) | ||
} else { | ||
return this.text == other.text | ||
} | ||
} | ||
override fun hashCode(): Int = when (type) { | ||
CandidateType.Cantonese -> (text.hashCode() * 31 + romanization.hashCode()) | ||
else -> text.hashCode() | ||
} | ||
} |
12 changes: 7 additions & 5 deletions
12
app/src/main/java/org/jyutping/jyutping/keyboard/CandidateType.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
package org.jyutping.jyutping.keyboard | ||
|
||
enum class CandidateType { | ||
CANTONESE, | ||
TEXT, | ||
EMOJI, | ||
SYMBOL, | ||
COMPOSE | ||
Cantonese, | ||
Text, | ||
Emoji, | ||
Symbol, | ||
Compose | ||
} | ||
|
||
fun CandidateType.isCantonese(): Boolean = (this == CandidateType.Cantonese) |
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