File tree Expand file tree Collapse file tree 7 files changed +30
-18
lines changed
src/main/kotlin/com/github/azurapi/azurapikotlin Expand file tree Collapse file tree 7 files changed +30
-18
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change @@ -4,13 +4,13 @@ val spekVersion = "2.0.9"
44
55plugins {
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
1212group = " com.github.AzurApi"
13- version = " 2.0.1 "
13+ version = " 3.1.3 "
1414
1515java {
1616 sourceCompatibility = JavaVersion .VERSION_1_8
Original file line number Diff line number Diff line change 11distributionBase =GRADLE_USER_HOME
22distributionPath =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
44zipStoreBase =GRADLE_USER_HOME
55zipStorePath =wrapper/dists
Original file line number Diff line number Diff line change @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
2929set APP_BASE_NAME = %~n0
3030set 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.
3336set DEFAULT_JVM_OPTS = " -Xmx64m" " -Xms64m"
3437
Original file line number Diff line number Diff line change @@ -8,7 +8,6 @@ import com.github.azurapi.azurapikotlin.internal.exceptions.DatabaseException
88import com.github.azurapi.azurapikotlin.internal.exceptions.ShipNotFoundException
99import com.github.azurapi.azurapikotlin.internal.json.Takao
1010import 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 /* *
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ package com.github.azurapi.azurapikotlin.internal.utils.info
44 * API info
55 */
66object AtagoInfo {
7- const val VERSION = " 2.0.1 "
7+ const val VERSION = " 3.1.3 "
88}
You can’t perform that action at this time.
0 commit comments