Compare commits
2
Commits
51eb838a36
...
5.5.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
28a2987dc3
|
||
|
|
8069de37f2
|
+8
-1
@@ -2,6 +2,13 @@
|
||||
|
||||
本文件记录 mingli-utils 各版本的主要变更。
|
||||
|
||||
## [5.5.2] - 2026-11-17
|
||||
|
||||
### 新增
|
||||
- **tuple**:实现 `Tuple.compareTo` 字典序比较——同类型可比较元素按自然顺序,
|
||||
其余按字符串形式比较;公共前缀相等时元素个数较少的元组在前。
|
||||
新增 `TestTuple` 测试覆盖 6 种比较场景。
|
||||
|
||||
## [5.5.1] - 2026-11-17
|
||||
|
||||
### 新增
|
||||
@@ -17,7 +24,7 @@
|
||||
等 10 个转换器及 `JsonConverter` 接口,统一由 `BaseJsonConverter` 与 `JsonConverterUtils` 处理;
|
||||
简化 `DateTimeJsonConverter`、`UUIDJsonConverter`、`NetworkEndpointJsonConverter` 与
|
||||
Jackson2/Jackson3 序列化/反序列化桥接实现;精简 `JSONA` 与 `JsonApi` 门面。
|
||||
- **tuple**:`Tuple` 实现 `Comparable<Tuple>`,迭代器改为基于 `toMutableList()` 的简化实现。
|
||||
- **tuple**:`Tuple` 声明实现 `Comparable<Tuple>`;迭代器改为基于 `toMutableList()` 的简化实现。
|
||||
- **springboot**:`JsonAutoConfiguration` 与 `JacksonJsonBuilder` / `JacksonJsonBuilderImpl`
|
||||
同步适配新的 JSON 转换器体系。
|
||||
|
||||
|
||||
+1
-1
@@ -22,4 +22,4 @@
|
||||
JDKVERSIONS=17
|
||||
GROUPSID=com.mingliqiye.utils
|
||||
ARTIFACTID=mingli-utils
|
||||
VERSIONS=5.5.1
|
||||
VERSIONS=5.5.2
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile BaseJsonWriter.kt
|
||||
* LastUpdate 2026-11-17 19:32:34
|
||||
* LastUpdate 2026-11-17 21:10:29
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils.json.witer.base
|
||||
|
||||
import com.mingliqiye.utils.json.judgment.BaseJsonJudgment
|
||||
import com.mingliqiye.utils.json.judgment.base.BaseJsonJudgment
|
||||
|
||||
|
||||
/**
|
||||
@@ -35,30 +35,35 @@ interface BaseJsonWriter : BaseJsonJudgment {
|
||||
* @param objCall 对象写入回调,接收对象写入器并返回它
|
||||
*/
|
||||
fun setObject(objCall: (BaseJsonObjectWriter) -> BaseJsonObjectWriter)
|
||||
|
||||
/**
|
||||
* 写入一个 JSON 数组,通过回调填充数组元素
|
||||
*
|
||||
* @param arrayCall 数组写入回调,接收数组写入器并返回它
|
||||
*/
|
||||
fun setArray(arrayCall: (BaseJsonArrayWriter) -> BaseJsonArrayWriter)
|
||||
|
||||
/**
|
||||
* 写入字符串值
|
||||
*
|
||||
* @param string 待写入的字符串
|
||||
*/
|
||||
fun setString(string: String)
|
||||
|
||||
/**
|
||||
* 写入数值
|
||||
*
|
||||
* @param number 待写入的数值
|
||||
*/
|
||||
fun setNumber(number: Number)
|
||||
|
||||
/**
|
||||
* 写入布尔值
|
||||
*
|
||||
* @param boolean 待写入的布尔值
|
||||
*/
|
||||
fun setBoolean(boolean: Boolean)
|
||||
|
||||
/**
|
||||
* 写入 null 值
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.main
|
||||
* CurrentFile Tuples.kt
|
||||
* LastUpdate 2026-11-17 20:29:54
|
||||
* LastUpdate 2026-11-17 21:11:31
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,32 @@ import java.io.Serializable
|
||||
*/
|
||||
abstract class Tuple(val size: Int = 1) : Serializable, Iterable<Any>, Comparable<Tuple> {
|
||||
|
||||
/**
|
||||
* 按字典序比较当前元组与另一个元组。
|
||||
*
|
||||
* 从第 1 个元素开始逐位比较:两个元素类型相同且都实现 [Comparable] 时按自然顺序比较,
|
||||
* 否则按元素的字符串形式([toString])比较。
|
||||
* 公共位置元素全部相等时,元素个数较少的元组视为较小。
|
||||
*
|
||||
* @param other 要比较的目标元组
|
||||
* @return 负数、零或正数,分别表示当前元组小于、等于或大于 [other]
|
||||
*/
|
||||
override fun compareTo(other: Tuple): Int {
|
||||
val minSize = minOf(size, other.size)
|
||||
for (i in 0..<minSize) {
|
||||
val a = get(i)
|
||||
val b = other.get(i)
|
||||
val result = if (a is Comparable<*> && b is Comparable<*> && a.javaClass == b.javaClass) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(a as Comparable<Any>).compareTo(b)
|
||||
} else {
|
||||
a.toString().compareTo(b.toString())
|
||||
}
|
||||
if (result != 0) return result
|
||||
}
|
||||
return size.compareTo(other.size)
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<Any> {
|
||||
return toMutableList().iterator()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2026 mingliqiye
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* ProjectName mingli-utils
|
||||
* ModuleName mingli-utils.test
|
||||
* CurrentFile TestTuple.kt
|
||||
* LastUpdate 2026-11-17 21:20:00
|
||||
* UpdateUser MingLiPro
|
||||
*/
|
||||
|
||||
package com.mingliqiye.utils
|
||||
|
||||
import com.mingliqiye.utils.tuple.Tuple
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* [Tuple] 字典序比较(compareTo)测试。
|
||||
*/
|
||||
class TestTuple {
|
||||
|
||||
/** 测试首元素不同时按首元素自然顺序比较 */
|
||||
@Test
|
||||
fun compareByFirstElement() {
|
||||
assertTrue(Tuple.of(2, "a") > Tuple.of(1, "z"))
|
||||
assertTrue(Tuple.of(1, "z") < Tuple.of(2, "a"))
|
||||
}
|
||||
|
||||
/** 测试首元素相同时按后续元素逐位比较 */
|
||||
@Test
|
||||
fun compareByLaterElement() {
|
||||
assertTrue(Tuple.of(1, "b") > Tuple.of(1, "a"))
|
||||
assertTrue(Tuple.of(1, 2, 3) < Tuple.of(1, 2, 4))
|
||||
}
|
||||
|
||||
/** 测试公共前缀相等时元素个数少的元组较小 */
|
||||
@Test
|
||||
fun compareBySizeWhenPrefixEqual() {
|
||||
assertTrue(Tuple.of(1) < Tuple.of(1, 0))
|
||||
assertTrue(Tuple.of(1, 0, 0) > Tuple.of(1, 0))
|
||||
}
|
||||
|
||||
/** 测试元素完全相同的元组比较结果为 0 */
|
||||
@Test
|
||||
fun compareEqualTuples() {
|
||||
assertEquals(0, Tuple.of(1, "a").compareTo(Tuple.of(1, "a")))
|
||||
}
|
||||
|
||||
/** 测试非 Comparable 元素按字符串形式比较且不抛异常 */
|
||||
@Test
|
||||
fun compareNonComparableElements() {
|
||||
val a = Any()
|
||||
val b = Any()
|
||||
assertEquals(a.toString().compareTo(b.toString()), Tuple.of(a).compareTo(Tuple.of(b)))
|
||||
}
|
||||
|
||||
/** 测试元组可直接使用 sorted 排序 */
|
||||
@Test
|
||||
fun sortedTuples() {
|
||||
val sorted = listOf(Tuple.of(2, "a"), Tuple.of(1, "z"), Tuple.of(1, "a")).sorted()
|
||||
assertEquals(listOf(listOf(1, "a"), listOf(1, "z"), listOf(2, "a")), sorted.map { it.toList() })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user