File tree Expand file tree Collapse file tree 2 files changed +15
-11
lines changed
model-server/src/main/kotlin/org/modelix/model/server/store Expand file tree Collapse file tree 2 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -21,12 +21,7 @@ import javax.cache.processor.MutableEntry
21
21
class ClientIdProcessor : EntryProcessor <String ?, String ?, Long > {
22
22
@Throws(EntryProcessorException ::class )
23
23
override fun process (mutableEntry : MutableEntry <String ?, String ?>, vararg objects : Any ): Long {
24
- val idStr = mutableEntry.value
25
- val id = try {
26
- idStr?.toLong() ? : 0L
27
- } catch (e : NumberFormatException ) {
28
- 0L
29
- } + 1L
24
+ val id = generateId(mutableEntry.value)
30
25
mutableEntry.value = id.toString()
31
26
return id
32
27
}
Original file line number Diff line number Diff line change @@ -22,6 +22,19 @@ import java.io.FileWriter
22
22
import java.io.IOException
23
23
import java.util.*
24
24
25
+ fun generateId (idStr : String? ): Long {
26
+ return try {
27
+ val candidate = idStr?.toLong()
28
+ if (candidate == null || candidate == Long .MAX_VALUE || candidate < 0L ) {
29
+ 0L
30
+ } else {
31
+ candidate
32
+ }
33
+ } catch (e : NumberFormatException ) {
34
+ 0L
35
+ } + 1L
36
+ }
37
+
25
38
class InMemoryStoreClient : IStoreClient {
26
39
companion object {
27
40
private val LOG = LoggerFactory .getLogger(InMemoryStoreClient ::class .java)
@@ -79,11 +92,7 @@ class InMemoryStoreClient : IStoreClient {
79
92
80
93
@Synchronized
81
94
override fun generateId (key : String ): Long {
82
- val id = try {
83
- get(key)?.toLong() ? : 0L
84
- } catch (e : NumberFormatException ) {
85
- 0L
86
- } + 1L
95
+ val id = generateId(get(key))
87
96
put(key, id.toString(), false )
88
97
return id
89
98
}
You can’t perform that action at this time.
0 commit comments