mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-24 03:53:12 -04:00
chore(purity): IdChecker
This commit is contained in:
parent
8e02069121
commit
a06c5c96e3
@ -49,10 +49,10 @@ allprojects {
|
|||||||
apply(plugin = "io.github.yairm210.purity-plugin")
|
apply(plugin = "io.github.yairm210.purity-plugin")
|
||||||
configure<yairm210.purity.PurityConfiguration>{
|
configure<yairm210.purity.PurityConfiguration>{
|
||||||
wellKnownPureFunctions = setOf(
|
wellKnownPureFunctions = setOf(
|
||||||
"java.util.regex.Pattern.matcher",
|
"java.util.regex.Pattern.matcher", // moved
|
||||||
"java.util.regex.Matcher.find",
|
"java.util.regex.Matcher.find", // moved
|
||||||
"java.util.regex.Matcher.replaceAll",
|
"java.util.regex.Matcher.replaceAll", // moved
|
||||||
"kotlin.collections.linkedMapOf",
|
"kotlin.collections.linkedMapOf", // moved
|
||||||
)
|
)
|
||||||
wellKnownReadonlyFunctions = setOf(
|
wellKnownReadonlyFunctions = setOf(
|
||||||
"com.badlogic.gdx.math.Vector2.len",
|
"com.badlogic.gdx.math.Vector2.len",
|
||||||
@ -66,11 +66,11 @@ allprojects {
|
|||||||
"com.badlogic.gdx.files.FileHandle.isFile",
|
"com.badlogic.gdx.files.FileHandle.isFile",
|
||||||
"com.badlogic.gdx.files.FileHandle.name",
|
"com.badlogic.gdx.files.FileHandle.name",
|
||||||
|
|
||||||
"kotlin.collections.sortBy",
|
"kotlin.collections.sortBy", // moved
|
||||||
"kotlin.Throwable.getStackTrace",
|
"kotlin.Throwable.getStackTrace", // moved
|
||||||
"java.lang.StackTraceElement.getClassName",
|
|
||||||
)
|
)
|
||||||
wellKnownPureClasses = setOf(
|
wellKnownPureClasses = setOf(
|
||||||
|
"java.lang.StackTraceElement" // moved
|
||||||
)
|
)
|
||||||
wellKnownInternalStateClasses = setOf(
|
wellKnownInternalStateClasses = setOf(
|
||||||
"com.badlogic.gdx.math.Vector2",
|
"com.badlogic.gdx.math.Vector2",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.unciv.logic
|
package com.unciv.logic
|
||||||
|
|
||||||
import yairm210.purity.annotations.Readonly
|
import yairm210.purity.annotations.Pure
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
@ -24,14 +24,17 @@ import kotlin.math.abs
|
|||||||
*/
|
*/
|
||||||
object IdChecker {
|
object IdChecker {
|
||||||
|
|
||||||
|
@Pure
|
||||||
fun checkAndReturnPlayerUuid(playerId: String): String? {
|
fun checkAndReturnPlayerUuid(playerId: String): String? {
|
||||||
return checkAndReturnUuiId(playerId, "P")
|
return checkAndReturnUuiId(playerId, "P")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Pure
|
||||||
fun checkAndReturnGameUuid(gameId: String): String? {
|
fun checkAndReturnGameUuid(gameId: String): String? {
|
||||||
return checkAndReturnUuiId(gameId, "G")
|
return checkAndReturnUuiId(gameId, "G")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Pure
|
||||||
private fun checkAndReturnUuiId(id: String, prefix: String): String? {
|
private fun checkAndReturnUuiId(id: String, prefix: String): String? {
|
||||||
val trimmedPlayerId = id.trim()
|
val trimmedPlayerId = id.trim()
|
||||||
if (trimmedPlayerId.length == 40) { // length of a UUID (36) with pre- and postfix
|
if (trimmedPlayerId.length == 40) { // length of a UUID (36) with pre- and postfix
|
||||||
@ -56,7 +59,7 @@ object IdChecker {
|
|||||||
/**
|
/**
|
||||||
* Adapted from https://wiki.openmrs.org/display/docs/Check+Digit+Algorithm
|
* Adapted from https://wiki.openmrs.org/display/docs/Check+Digit+Algorithm
|
||||||
*/
|
*/
|
||||||
@Readonly
|
@Pure
|
||||||
fun getCheckDigit(uuid: String): Int? {
|
fun getCheckDigit(uuid: String): Int? {
|
||||||
// allowable characters within identifier
|
// allowable characters within identifier
|
||||||
@Suppress("SpellCheckingInspection")
|
@Suppress("SpellCheckingInspection")
|
||||||
@ -69,8 +72,7 @@ object IdChecker {
|
|||||||
var sum = 0
|
var sum = 0
|
||||||
|
|
||||||
// loop through digits from right to left
|
// loop through digits from right to left
|
||||||
for (i in idWithoutCheckdigit.indices) {
|
idWithoutCheckdigit.indices.forEach { i ->
|
||||||
|
|
||||||
//set ch to "current" character to be processed
|
//set ch to "current" character to be processed
|
||||||
val ch = idWithoutCheckdigit[idWithoutCheckdigit.length - i - 1]
|
val ch = idWithoutCheckdigit[idWithoutCheckdigit.length - i - 1]
|
||||||
|
|
||||||
@ -82,7 +84,7 @@ object IdChecker {
|
|||||||
|
|
||||||
// weight will be the current digit's contribution to
|
// weight will be the current digit's contribution to
|
||||||
// the running total
|
// the running total
|
||||||
var weight: Int
|
val weight: Int
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
|
|
||||||
// for alternating digits starting with the rightmost, we
|
// for alternating digits starting with the rightmost, we
|
||||||
@ -102,7 +104,6 @@ object IdChecker {
|
|||||||
}
|
}
|
||||||
// keep a running total of weights
|
// keep a running total of weights
|
||||||
sum += weight
|
sum += weight
|
||||||
|
|
||||||
}
|
}
|
||||||
// avoid sum less than 10 (if characters below "0" allowed,
|
// avoid sum less than 10 (if characters below "0" allowed,
|
||||||
// this could happen)
|
// this could happen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user