fix code analyze issue

This commit is contained in:
2022-07-19 11:34:31 +08:00
parent 248d9a57d4
commit c4ff209d72
38 changed files with 117 additions and 131 deletions

View File

@@ -0,0 +1,3 @@
package com.synebula.gaea.bus
interface IMessage

View File

@@ -1,6 +1,6 @@
package com.synebula.gaea.event
package com.synebula.gaea.bus
interface IEventBus {
interface IMessageBus {
/**
* 注册事件Listener
@@ -16,13 +16,13 @@ interface IEventBus {
/**
* 同步发布事件
* @param event 事件
* @param message 事件
*/
fun publish(event: IEvent)
fun publish(message: IMessage)
/**
* 异步发布事件
* @param event 事件
* @param message 事件
*/
fun publishAsync(event: IEvent)
fun publishAsync(message: IMessage)
}

View File

@@ -11,13 +11,13 @@ import java.util.*
* 参数:年=y月=M日=d时=H分=m秒=s毫秒=S。位数最好使用默认最大长度。
*/
class DateCode(pattern: String = "yyyyMMdd") : ICodeGenerator<Long> {
var formator = SimpleDateFormat()
var formatter = SimpleDateFormat()
init {
formator.applyPattern(pattern)
formatter.applyPattern(pattern)
}
override fun generate(): Long {
return java.lang.Long.parseLong(formator.format(Date()))
return java.lang.Long.parseLong(formatter.format(Date()))
}
}

View File

@@ -1,6 +1,7 @@
package com.synebula.gaea.data.code
import java.util.*
import kotlin.math.pow
/**
* 固定长度随机编号生成。
@@ -9,8 +10,8 @@ import java.util.*
* @since 2016年10月24日 上午10:58:05
*/
class FixedRandomCode(
//生成的随机编号长度。
var length: Int
//生成的随机编号长度。
var length: Int,
) : ICodeGenerator<String> {
/**
@@ -32,12 +33,12 @@ class FixedRandomCode(
var format = String.format("%s%d%dd", "%", 0, calcMaxLength)
val count = this.length / calcMaxLength
for (i in 0 until count) {
buffer.append(String.format(format, (random.nextDouble() * Math.pow(10.0, calcMaxLength.toDouble())).toInt()))
buffer.append(String.format(format, (random.nextDouble() * 10.0.pow(calcMaxLength.toDouble())).toInt()))
}
val last = this.length % calcMaxLength
if (last != 0) {
format = String.format("%s%d%dd", "%", 0, last)
buffer.append(String.format(format, (random.nextDouble() * Math.pow(10.0, last.toDouble())).toInt()))
buffer.append(String.format(format, (random.nextDouble() * 10.0.pow(last.toDouble())).toInt()))
}
return buffer.toString()
}

View File

@@ -13,7 +13,7 @@ package com.synebula.gaea.data.code
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br></br>
* 1位标识由于long基本类型在Java中是带符号的最高位是符号位正数是0负数是1所以id一般是正数最高位是0<br></br>
* 41位时间截(毫秒级)注意41位时间截不是存储当前时间的时间截而是存储时间截的差值当前时间截 - 开始时间截)<br></br>
* 得到的值这里的的开始时间截一般是我们的id生成器开始使用的时间由我们程序来指定的如下下面程序Snowflake类的twepoch属性)。<br></br>
* 得到的值这里的的开始时间截一般是我们的id生成器开始使用的时间由我们程序来指定的如下下面程序Snowflake类的origin属性)。<br></br>
* 41位的时间截可以使用69年年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69 <br></br>
* 10位的数据机器位可以部署在1024个节点包括5位datacenter和5位worker <br></br>
* 12位序列毫秒内的计数12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br></br>
@@ -35,7 +35,7 @@ open class SnowflakeCode(
/**
* 开始时间截 (2018-01-01)
*/
private val twepoch = 1514736000000L
private val origin = 1514736000000L
/**
* 机器id所占的位数
@@ -142,7 +142,7 @@ open class SnowflakeCode(
lastTimestamp = current
//移位并通过或运算拼到一起组成64位的ID
return (current - twepoch shl timestampLeftShift
return (current - origin shl timestampLeftShift
or (datacenter shl datacenterShift)
or (worker shl workerShift)
or sequence)

View File

@@ -275,7 +275,6 @@ class DateTime() : Comparable<DateTime> {
* @return true or false
*/
fun isBetween(start: DateTime, end: DateTime): Boolean {
//return this in start..end
return start.dateNoTime.compareTo(this.dateNoTime) * this.dateNoTime.compareTo(end.dateNoTime) >= 0
}

View File

@@ -1,21 +0,0 @@
package com.synebula.gaea.domain.model
import java.util.*
/**
* 记录聚合根
* 聚合根外添加了创建和修改的人\时间信息
*/
abstract class AggregateRecord<TKey> : AggregateRoot<TKey>() {
var creator: String? = null
var creatorName: String? = null
var created: Date = Date()
set(value) {
field = value
modified = value
}
var modifier: String? = null
var modifierName: String? = null
var modified: Date = Date()
}

View File

@@ -1,3 +0,0 @@
package com.synebula.gaea.domain.model.complex
abstract class ComplexAggregateRoot<TKey, TSecond> : ComplexEntity<TKey, TSecond>(), IComplexAggregateRoot<TKey, TSecond>

View File

@@ -1,5 +0,0 @@
package com.synebula.gaea.domain.model.complex
abstract class ComplexEntity<TKey, TSecond> : IComplexEntity<TKey, TSecond> {
}

View File

@@ -1,9 +0,0 @@
package com.synebula.gaea.domain.model.complex
/**
* 继承本接口,说明对象为聚合根。
*
* @param <TKey> 主键的类型。
* @author alex
*/
interface IComplexAggregateRoot<TKey, TSecond> : IComplexEntity<TKey, TSecond>

View File

@@ -1,7 +0,0 @@
package com.synebula.gaea.domain.model.complex
import com.synebula.gaea.domain.model.IEntity
interface IComplexEntity<TKey, TSecond> : IEntity<TKey> {
var secondary: TSecond?
}

View File

@@ -0,0 +1,21 @@
package com.synebula.gaea.domain.record
import java.util.*
/**
* 记录信息
* 添加了创建和修改的人\时间信息
*/
abstract class Record<TKey> {
//记录增加信息
var creator: String? = null
var creatorName: String? = null
var createTime: Date = Date()
//记录修改信息
var modifier: String? = null
var modifierName: String? = null
var modifyTime: Date = Date()
}

View File

@@ -8,5 +8,6 @@ package com.synebula.gaea.domain.service
* @since 2020-05-15
*/
open class Command : ICommand {
override var payload = ""
override var timestamp = 0L
}

View File

@@ -8,6 +8,12 @@ package com.synebula.gaea.domain.service
* @since 2020-05-15
*/
interface ICommand {
/**
* 命令载荷, 实际的业务数据
*/
var payload: String
/**
* 时间戳。
*/

View File

@@ -1,6 +1,5 @@
package com.synebula.gaea.domain.service
import com.synebula.gaea.data.IObjectConverter
import com.synebula.gaea.data.message.DataMessage
import com.synebula.gaea.data.message.Message
import com.synebula.gaea.domain.model.IAggregateRoot

View File

@@ -1,4 +0,0 @@
package com.synebula.gaea.event
interface IEvent {
}

View File

@@ -34,10 +34,11 @@ object ClassPath {
// 判断路径最后一个字符是不是"/",如果不是加上
path = if (path.lastIndexOf("/") != path.length - 1) "$path/" else path
var resources: Enumeration<URL>? = null
val resources: Enumeration<URL>?
try {
resources = ClassLoaderContext.get().getResources(path)
} catch (e: IOException) {
} catch (ex: IOException) {
throw RuntimeException(ex)
}
while (resources!!.hasMoreElements()) {

View File

@@ -30,7 +30,8 @@ class ClassScanner(private var packageName: String) {
/**
* 文件过滤器
*/
private val fileFilter = FileFilter { file -> file.isDirectory || file.name.endsWith(".class") || file.name.endsWith(".jar") }
private val fileFilter =
FileFilter { file -> file.isDirectory || file.name.endsWith(".class") || file.name.endsWith(".jar") }
/**
@@ -81,12 +82,15 @@ class ClassScanner(private var packageName: String) {
val files = scanDirectory(realPath)
for (file in files) {
val fileName = file.toString()
if (fileName.contains(".jar") && !fileName.endsWith(".class"))
if (fileName.contains(".jar") && !fileName.endsWith(".class")) {
scanJar(file)
else if (fileName.endsWith(".class"))
scanClass(realPath, file)
}
// else if (fileName.endsWith(".class")) {
// }
scanClass(realPath, file)
}
} catch (e: UnsupportedEncodingException) {
} catch (ex: UnsupportedEncodingException) {
throw ex
}
}
}
@@ -145,6 +149,7 @@ class ClassScanner(private var packageName: String) {
}
jar.close()
} catch (ex: Throwable) {
throw ex
}
}
@@ -191,7 +196,7 @@ class ClassScanner(private var packageName: String) {
}
}
} catch (ex: Throwable) {
throw ex
}
}

View File

@@ -2,25 +2,28 @@ package com.synebula.gaea.log
/**
* 日志等级
* @author Looly
*/
enum class Level {
/**
* 'TRACE' log level.
*/
TRACE,
/**
* 'DEBUG' log level.
*/
DEBUG,
/**
* 'INFO' log level.
*/
INFO,
/**
* 'WARN' log level.
*/
WARN,
/**
* 'ERROR' log level.
*/

View File

@@ -3,7 +3,6 @@ package com.synebula.gaea.log.logger
/**
* DEBUG级别日志接口
*
* @author Looly
*/
interface IDebugLogger {
/**

View File

@@ -2,7 +2,6 @@ package com.synebula.gaea.log.logger
/**
* ERROR级别日志接口
* @author Looly
*/
interface IErrorLogger {
/**

View File

@@ -2,7 +2,6 @@ package com.synebula.gaea.log.logger
/**
* INFO级别日志接口
* @author Looly
*/
interface IInfoLogger {
/**

View File

@@ -3,7 +3,6 @@ package com.synebula.gaea.log.logger
/**
* TRACE级别日志接口
*
* @author Looly
*/
interface ITraceLogger {
/**

View File

@@ -2,7 +2,6 @@ package com.synebula.gaea.log.logger
/**
* WARN级别日志接口
* @author Looly
*/
interface IWarnLogger {
/**