@@ -67,9 +67,7 @@ object IDManager {
6767 val strings: Array <String > =
6868 id.split(Const .SERVICE_ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
6969 .toTypedArray()
70- if (strings.size != 2 ) {
71- throw IllegalArgumentException (" Can't split service id into 2 parts, $id " )
72- }
70+ require(strings.size == 2 ) { " Can't split service id into 2 parts, $id " }
7371 return ServiceIDDefinition (
7472 decode(strings[0 ]),
7573 strings[1 ].toInt() == 1
@@ -90,9 +88,7 @@ object IDManager {
9088 val parts: Array <String > =
9189 entityId.split(Const .RELATION_ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
9290 .toTypedArray()
93- if (parts.size != 2 ) {
94- throw RuntimeException (" Illegal Service Relation entity id" )
95- }
91+ require(parts.size == 2 ) { " Illegal Service Relation entity id" }
9692 return ServiceRelationDefine (parts[0 ], parts[1 ])
9793 }
9894
@@ -125,9 +121,7 @@ object IDManager {
125121 if (instanceName.isBlank()) {
126122 instanceName = Const .BLANK_ENTITY_NAME
127123 }
128- return (serviceId
129- + Const .ID_CONNECTOR
130- ).toString() + encode(instanceName)
124+ return (serviceId + Const .ID_CONNECTOR ) + encode(instanceName)
131125 }
132126
133127 /* *
@@ -136,9 +130,7 @@ object IDManager {
136130 fun analysisId (id : String ): InstanceIDDefinition {
137131 val strings: Array <String > = id.split(Const .ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
138132 .toTypedArray()
139- if (strings.size != 2 ) {
140- throw IllegalArgumentException (" Can't split instance id into 2 parts, $id " )
141- }
133+ require(strings.size == 2 ) { " Can't split instance id into 2 parts, $id " }
142134 return InstanceIDDefinition (
143135 strings[0 ],
144136 decode(strings[1 ])
@@ -160,9 +152,7 @@ object IDManager {
160152 val parts: Array <String > =
161153 entityId.split(Const .RELATION_ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
162154 .toTypedArray()
163- if (parts.size != 2 ) {
164- throw RuntimeException (" Illegal Service Instance Relation entity id" )
165- }
155+ require(parts.size == 2 ) { " Illegal Service Instance Relation entity id" }
166156 return ServiceInstanceRelationDefine (parts[0 ], parts[1 ])
167157 }
168158
@@ -201,9 +191,7 @@ object IDManager {
201191 if (endpointName.isBlank()) {
202192 endpointName = Const .BLANK_ENTITY_NAME
203193 }
204- return (serviceId
205- + Const .ID_CONNECTOR
206- ).toString() + encode(endpointName)
194+ return (serviceId + Const .ID_CONNECTOR ) + encode(endpointName)
207195 }
208196
209197 /* *
@@ -212,9 +200,7 @@ object IDManager {
212200 fun analysisId (id : String ): EndpointIDDefinition {
213201 val strings: Array <String > = id.split(Const .ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
214202 .toTypedArray()
215- if (strings.size != 2 ) {
216- throw IllegalArgumentException (" Can't split endpoint id into 2 parts, $id " )
217- }
203+ require(strings.size == 2 ) { " Can't split endpoint id into 2 parts, $id " }
218204 return EndpointIDDefinition (
219205 strings[0 ],
220206 decode(strings[1 ])
@@ -227,11 +213,11 @@ object IDManager {
227213 fun buildRelationId (define : EndpointRelationDefine ): String {
228214 return (((define.sourceServiceId
229215 + Const .RELATION_ID_CONNECTOR
230- ).toString() + encode(define.source)
216+ ) + encode(define.source)
231217 + Const .RELATION_ID_CONNECTOR
232- ).toString() + define.destServiceId
218+ ) + define.destServiceId
233219 + Const .RELATION_ID_CONNECTOR
234- ).toString() + encode(define.dest)
220+ ) + encode(define.dest)
235221 }
236222
237223 /* *
@@ -241,9 +227,7 @@ object IDManager {
241227 val parts: Array <String > =
242228 entityId.split(Const .RELATION_ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
243229 .toTypedArray()
244- if (parts.size != 4 ) {
245- throw IllegalArgumentException (" Illegal endpoint Relation entity id, $entityId " )
246- }
230+ require(parts.size == 4 ) { " Illegal endpoint Relation entity id, $entityId " }
247231 return EndpointRelationDefine (
248232 parts[0 ],
249233 decode(parts[1 ]),
@@ -292,6 +276,7 @@ object IDManager {
292276 }
293277 return Hashing .sha256().newHasher().putString(
294278 String .format(
279+ Locale .ENGLISH ,
295280 " %s_%s" ,
296281 name, instanceId
297282 ), Charsets .UTF_8
@@ -302,7 +287,7 @@ object IDManager {
302287 * @return encoded process relation id
303288 */
304289 fun buildRelationId (define : ProcessRelationDefine ): String {
305- return (define.sourceId + Const .RELATION_ID_CONNECTOR ).toString() + define.destId
290+ return (define.sourceId + Const .RELATION_ID_CONNECTOR ) + define.destId
306291 }
307292
308293 /* *
@@ -312,9 +297,7 @@ object IDManager {
312297 val parts: Array <String > =
313298 entityId.split(Const .RELATION_ID_PARSER_SPLIT .toRegex()).dropLastWhile { it.isEmpty() }
314299 .toTypedArray()
315- if (parts.size != 2 ) {
316- throw RuntimeException (" Illegal Process Relation entity id" )
317- }
300+ require(parts.size == 2 ) { " Illegal Process Relation entity id" }
318301 return ProcessRelationDefine (parts[0 ], parts[1 ])
319302 }
320303
0 commit comments