Skip to content

Commit 6def2ff

Browse files
committed
3.1.3
Fix case sensitive option getShipById Improve ship finding when exact name is requested
1 parent 1d2fceb commit 6def2ff

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 3.1.3 (2020-18-02)
4+
5+
### Bug fixes
6+
7+
- Fix case sensitive option in `getShipById`
8+
39
## 3.1.2 (2020-01-26)
410

511
### Bug fixes
@@ -70,4 +76,4 @@ Pre release
7076

7177
- **getShipByName**: returns the closest ship which name matches the requested name
7278
- **getShipById**: returns ship with the given ID
73-
- **getAllShips**: returns a list of all available ships in database
79+
- **getAllShips**: returns a list of all available ships in database

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ val spekVersion = "2.0.9"
44

55
plugins {
66
java
7-
`maven-publish`
7+
maven
88
kotlin("jvm") version "1.3.61"
99
id("org.jmailen.kotlinter") version "2.3.0"
1010
}
1111

1212
group = "com.github.AzurApi"
13-
version = "2.0.1"
13+
version = "3.1.3"
1414

1515
java {
1616
sourceCompatibility = JavaVersion.VERSION_1_8
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

gradlew.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929
set APP_BASE_NAME=%~n0
3030
set APP_HOME=%DIRNAME%
3131

32+
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
33+
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34+
3235
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
3336
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
3437

src/main/kotlin/com/github/azurapi/azurapikotlin/api/Atago.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import com.github.azurapi.azurapikotlin.internal.exceptions.DatabaseException
88
import com.github.azurapi.azurapikotlin.internal.exceptions.ShipNotFoundException
99
import com.github.azurapi.azurapikotlin.internal.json.Takao
1010
import com.github.azurapi.azurapikotlin.internal.utils.info.AtagoInfo
11-
import java.util.stream.Collectors
1211

1312
/**
1413
* API class
@@ -47,8 +46,8 @@ object Atago {
4746
* @param id id of the ship
4847
*/
4948
fun getShipById(id: String, caseSensitive: Boolean = false): Ship {
50-
val formattedId = if (caseSensitive) id.toLowerCase() else id
51-
return (if (caseSensitive) database.shipsById.mapKeys { it.key.toLowerCase() } else
49+
val formattedId = if (!caseSensitive) id.toLowerCase() else id
50+
return (if (!caseSensitive) database.shipsById.mapKeys { it.key.toLowerCase() } else
5251
database.shipsById)[formattedId] ?: throw ShipNotFoundException("Could not find ship with id: $id")
5352
}
5453

@@ -58,7 +57,7 @@ object Atago {
5857
* Get list of all ships
5958
*/
6059
fun getAllShips(): List<Ship> {
61-
return database.shipsById.values.stream().collect(Collectors.toList())
60+
return database.shipsById.values.toList()
6261
}
6362

6463
/**

src/main/kotlin/com/github/azurapi/azurapikotlin/internal/json/Takao.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,27 @@ internal class Takao {
9292
* @param search
9393
*/
9494
fun findShip(search: String, lang: Lang): Ship? {
95-
val cosine = Cosine()
96-
var bestScore = 0.0
97-
var result: Ship? = null
9895
val databaseLang = when (lang) {
9996
Lang.EN -> shipsByEnName
10097
Lang.CN -> shipsByCnName
10198
Lang.JP -> shipsByJpName
10299
Lang.KR -> shipsByKrName
103100
Lang.ANY -> shipsByEnName + shipsByCnName + shipsByJpName + shipsByKrName
104101
}
105-
for ((name, ship) in databaseLang.entries) {
106-
val score = cosine.similarity(search.toLowerCase(), name.toLowerCase())
107-
if (score > bestScore) {
108-
result = ship
109-
bestScore = score
102+
return if (databaseLang.containsKey(search)) {
103+
databaseLang[search]
104+
} else {
105+
val cosine = Cosine()
106+
var bestScore = 0.0
107+
var result: Ship? = null
108+
for ((name, ship) in databaseLang.entries) {
109+
val score = cosine.similarity(search.toLowerCase(), name.toLowerCase())
110+
if (score > bestScore) {
111+
result = ship
112+
bestScore = score
113+
}
110114
}
115+
result
111116
}
112-
return result
113117
}
114118
}

src/main/kotlin/com/github/azurapi/azurapikotlin/internal/utils/info/AtagoInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package com.github.azurapi.azurapikotlin.internal.utils.info
44
* API info
55
*/
66
object AtagoInfo {
7-
const val VERSION = "2.0.1"
7+
const val VERSION = "3.1.3"
88
}

0 commit comments

Comments
 (0)