Skip to content

Commit 6309a1d

Browse files
committed
feature: introduce functions to split items in two sorts
1 parent f5bf437 commit 6309a1d

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group = "com.github.attacktive"
14-
version = "1.1.4"
14+
version = "1.2.0"
1515
java.sourceCompatibility = JavaVersion.VERSION_21
1616

1717
configurations {

src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/common/Properties.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package com.github.attacktive.troubleshootereditor.domain.common
22

3+
import java.util.function.Predicate
4+
35
data class Properties(private val list: List<Property> = mutableListOf()) {
6+
fun containsKey(key: String) = keys().contains(key)
7+
fun containsKeyThat(predicate: Predicate<String>) = keys().any { predicate.test(it) }
8+
49
fun add(pair: Pair<String, String>) = list.addLast(Property(pair))
510
fun asSequence() = list.asSequence()
611
fun toMap() = list.associate { it.key to it.value }
712

8-
private fun findByKey(key: String) = list.find { it.key == key }
9-
1013
fun diff(those: Properties): Properties {
11-
val thoseKeys = those.list.map { it.key }.toMutableList()
14+
val thoseKeys = those.keys().toMutableList()
1215

1316
val withThese = list.map { `this` ->
1417
val key = `this`.key
@@ -36,4 +39,8 @@ data class Properties(private val list: List<Property> = mutableListOf()) {
3639

3740
return Properties(withThese + withThose)
3841
}
42+
43+
private fun keys() = list.map { it.key }.toSet()
44+
45+
private fun findByKey(key: String) = list.find { it.key == key }
3946
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
package com.github.attacktive.troubleshootereditor.domain.common
22

3+
import com.fasterxml.jackson.annotation.JsonGetter
34
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
45
import com.github.attacktive.troubleshootereditor.domain.company.Company
56
import com.github.attacktive.troubleshootereditor.domain.item.Item
67
import com.github.attacktive.troubleshootereditor.domain.roster.Roster
78

89
data class SaveData(val company: Company, val rosters: List<Roster>, val items: List<Item>) {
910
override fun toString(): String = jacksonObjectMapper().writeValueAsString(this)
11+
12+
@JsonGetter
13+
fun gears() = items.filter { it.isGear() }
14+
15+
@JsonGetter
16+
fun consumables() = items.filter { !it.isGear() }
1017
}

src/main/kotlin/com/github/attacktive/troubleshootereditor/domain/item/Item.kt

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ data class Item(val id: Long, val type: String, val count: Long, val status: Str
5858
return DiffResult(id, type, count, status, properties)
5959
}
6060

61+
fun isGear(): Boolean {
62+
if (properties.containsKey("Binded") || properties.containsKey("Lv") || properties.containsKey("Transmog")) {
63+
return true
64+
}
65+
66+
return properties.containsKeyThat{ it.matches(Regex("Option/.+", RegexOption.IGNORE_CASE)) }
67+
}
68+
6169
data class DiffResult(val id: Long, val type: String?, val count: Long?, val status: String?, override val properties: Properties): PropertiesDiffAware {
6270
override fun generateStatements(connection: Connection): List<PreparedStatement> {
6371
val statements: List<PreparedStatement> = mutableListOf()

0 commit comments

Comments
 (0)