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
2121class ClientIdProcessor : EntryProcessor <String ?, String ?, Long > {
2222 @Throws(EntryProcessorException ::class )
2323 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)
3025 mutableEntry.value = id.toString()
3126 return id
3227 }
Original file line number Diff line number Diff line change @@ -22,6 +22,19 @@ import java.io.FileWriter
2222import java.io.IOException
2323import java.util.*
2424
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+
2538class InMemoryStoreClient : IStoreClient {
2639 companion object {
2740 private val LOG = LoggerFactory .getLogger(InMemoryStoreClient ::class .java)
@@ -79,11 +92,7 @@ class InMemoryStoreClient : IStoreClient {
7992
8093 @Synchronized
8194 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))
8796 put(key, id.toString(), false )
8897 return id
8998 }
You can’t perform that action at this time.
0 commit comments