Compare commits

..
Author SHA1 Message Date
minglipro e4bb9884c1 Merge pull request 'refactor(stream): 重构流处理相关代码' (#8) from dev into master
Reviewed-on: #8
2025-09-15 17:27:10 +08:00
minglipro cc3156572f refactor(stream): 重构流处理相关代码
- 移除 InOutSteam、InputStreanWrapper、OutputStreamWrapper 类
- 删除 Getable、GetIdable、GetKeyable、GetNameable 接口- 更新 ByteUtils 和 Collection.kt 中的流处理逻辑
- 新增 InputStreamUtils.kt 文件,提供输入流相关扩展函数
- 更新项目版本号至 4.0.5
2025-09-15 17:26:39 +08:00
minglipro 0b1aac8ecc Merge pull request 'refactor(mybatis): 更新类型处理器以支持 JDBC 类型参数为 null' (#7) from dev into master
Reviewed-on: #7
2025-09-15 13:55:22 +08:00
minglipro 9a6c6cd662 refactor(mybatis): 更新类型处理器以支持 JDBC 类型参数为 null
- 修改 DateTimeTypeHandler、MysqlUUIDBinaryTypeHandler 和 UUIDTypeHandler
- 将 setNonNullParameter 方法的 jdbcType 参数变更为可空类型
- 更新方法实现以适应新的可空参数
- 提升代码的健壮性和灵活性,允许在某些情况下不指定 JDBC 类型
2025-09-15 13:55:01 +08:00
minglipro 3d1f249970 Merge pull request 'dev' (#6) from dev into master
Reviewed-on: #6
2025-09-15 12:46:12 +08:00
minglipro b329953377 feat(foreach): 增加带有提前终止功能的遍历方法并优化代码结构
- 新增 forEachB 系列函数,支持在遍历过程中提前终止
- 为数组和集合添加专门的 forEach 和 forEachB 函数
- 优化现有 forEach 函数的实现,提高性能
- 添加针对 Map 类型的 forEachMap 和 forEachMapB 函数
- 更新函数注释,明确参数和返回值的含义
2025-09-15 12:45:59 +08:00
minglipro f9e96fccd3 feat(foreach): 增加带有提前终止功能的遍历方法并优化代码结构
- 新增 forEachB 系列函数,支持在遍历过程中提前终止
- 为数组和集合添加专门的 forEach 和 forEachB 函数
- 优化现有 forEach 函数的实现,提高性能
- 添加针对 Map 类型的 forEachMap 和 forEachMapB 函数
- 更新函数注释,明确参数和返回值的含义
2025-09-15 12:45:16 +08:00
18 changed files with 596 additions and 2174 deletions
+2 -2
View File
@@ -16,10 +16,10 @@
# ProjectName mingli-utils
# ModuleName mingli-utils
# CurrentFile gradle.properties
# LastUpdate 2025-09-15 12:01:24
# LastUpdate 2025-09-15 17:24:10
# UpdateUser MingLiPro
#
JDKVERSIONS=1.8
GROUPSID=com.mingliqiye.utils
ARTIFACTID=mingli-utils
VERSIONS=4.0.2
VERSIONS=4.0.5
@@ -1,279 +0,0 @@
package com.mingliqiye.utils.stream;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.jetbrains.annotations.NotNull;
/**
* 自定义的输入输出流工具类,支持线程安全的数据读写操作。<br>
* 谁闲着没事干用本地输入输出<br>
* 实现了 AutoCloseable、Closeable 和 Flushable 接口,便于资源管理。
*
* @author MingLiPro
*/
public class InOutSteam implements AutoCloseable, Closeable, Flushable {
private final Lock lock = new ReentrantLock();
List<Byte> bytes;
/**
* 从内部缓冲区中读取最多 len 个字节到指定的字节数组 b 中。
*
* @param b 目标字节数组,用于存储读取的数据
* @param off 起始偏移位置
* @param len 最大读取字节数
* @return 实际读取的字节数;如果已到达流末尾,则返回 -1
* @throws IndexOutOfBoundsException 如果 off 或 len 参数非法
*/
public int read(byte@NotNull [] b, int off, int len) {
if (bytes == null) return -1;
if (bytes.isEmpty()) {
return 0;
}
if (off < 0 || len < 0 || off + len > b.length) {
throw new IndexOutOfBoundsException();
}
try {
lock.lock();
int bytesRead = Math.min(len, bytes.size());
for (int i = 0; i < bytesRead; i++) {
b[off + i] = bytes.get(i);
}
if (bytesRead > 0) {
bytes.subList(0, bytesRead).clear();
}
return bytesRead;
} finally {
lock.unlock();
}
}
/**
* 读取一个字节的数据。
*
* @return 下一个字节数据(0~255),如果已到达流末尾则返回 -1
*/
public int read() {
if (bytes == null) return -1;
try {
lock.lock();
if (bytes.isEmpty()) {
return -1;
}
return bytes.remove(0);
} finally {
lock.unlock();
}
}
/**
* 从内部缓冲区中读取最多 b.length 个字节到指定的字节数组 b 中。
*
* @param b 目标字节数组,用于存储读取的数据
* @return 实际读取的字节数;如果已到达流末尾,则返回 -1
*/
public int read(byte@NotNull [] b) {
if (bytes == null) return -1;
return read(b, 0, b.length);
}
/**
* 跳过并丢弃此输入流中数据的 n 个字节。
*
* @param n 要跳过的字节数
* @return 实际跳过的字节数
*/
public long skip(long n) {
if (bytes == null) return -1;
if (bytes.isEmpty()) {
return 0;
}
try {
lock.lock();
if (n <= 0) {
return 0;
}
long bytesToSkip = Math.min(n, bytes.size());
// 移除跳过的字节
if (bytesToSkip > 0) {
bytes.subList(0, (int) bytesToSkip).clear();
}
return bytesToSkip;
} finally {
lock.unlock();
}
}
/**
* 返回此输入流下一个方法调用可以不受阻塞地从此输入流读取(或跳过)的估计字节数。
*
* @return 可以无阻塞读取的字节数
*/
public int available() {
if (bytes == null) return -1;
try {
lock.lock();
return bytes.size();
} finally {
lock.unlock();
}
}
/**
* 获取与当前对象关联的 InputStream 实例。
*
* @return InputStream 实例
*/
public InputStream getInputStream() {
if (inputStream == null) {
inputStream = inputStream();
}
return inputStream;
}
private InputStream inputStream;
private OutputStream outputStream;
/**
* 获取与当前对象关联的 OutputStream 实例。
*
* @return OutputStream 实例
*/
public OutputStream getOutputStream() {
if (outputStream == null) {
outputStream = outputStream();
}
return outputStream;
}
/**
* 创建并返回一个包装后的 InputStream 实例。
*
* @return 新创建的 InputStream 实例
*/
private InputStream inputStream() {
return new InputStreanWrapper(
new InputStream() {
@Override
public int read() {
return InOutSteam.this.read();
}
@Override
public int read(byte@NotNull [] b, int off, int len) {
return InOutSteam.this.read(b, off, len);
}
@Override
public long skip(long n) {
return InOutSteam.this.skip(n);
}
@Override
public int available() {
return InOutSteam.this.available();
}
}
);
}
/**
* 创建并返回一个 OutputStream 实例。
*
* @return 新创建的 OutputStream 实例
*/
private OutputStream outputStream() {
return new OutputStream() {
@Override
public void write(int b) {
InOutSteam.this.write(b);
}
@Override
public void write(byte@NotNull [] b, int off, int len) {
InOutSteam.this.write(b, off, len);
}
};
}
/**
* 构造函数,初始化内部字节列表。
*/
public InOutSteam() {
bytes = new ArrayList<>();
}
/**
* 将指定的字节写入此输出流。
*
* @param b 要写入的字节
*/
public void write(int b) {
try {
lock.lock();
bytes.add((byte) b);
} finally {
lock.unlock();
}
}
/**
* 将指定字节数组中的部分数据写入此输出流。
*
* @param b 数据源字节数组
* @param off 起始偏移位置
* @param len 写入的字节数
* @throws IndexOutOfBoundsException 如果 off 或 len 参数非法
*/
public void write(byte@NotNull [] b, int off, int len) {
if (off < 0 || len < 0 || off + len > b.length) {
throw new IndexOutOfBoundsException("Invalid offset or length");
}
try {
lock.lock();
for (int i = off; i < off + len; i++) {
bytes.add(b[i]);
}
} finally {
lock.unlock();
}
}
/**
* 将整个字节数组写入此输出流。
*
* @param b 要写入的字节数组
*/
public void write(byte@NotNull [] b) {
write(b, 0, b.length);
}
/**
* 刷新此输出流并强制写出所有缓冲的输出字节。
* 当前实现为空方法。
*/
@Override
public void flush() {}
/**
* 关闭此流并释放与其相关的所有资源。
* 清空并置空内部字节列表。
*/
@Override
public void close() {
bytes.clear();
bytes = null;
}
}
@@ -1,123 +0,0 @@
/*
* Copyright 2025 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.main
* CurrentFile InputStreamUtils.java
* LastUpdate 2025-09-15 08:30:57
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.stream;
import com.mingliqiye.utils.collection.Collections;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
/**
* 输入流工具类,提供对InputStream的常用操作封装
*/
public class InputStreamUtils {
/**
* 默认缓冲区大小:1MB
*/
public static final int DEFAULT_BUFFER_SIZE = 1024 * 1024;
/**
* 将输入流读取到字节数组中<br>
* 请在外部自行关闭输入流对象 避免资源泄露
*
* @param inputStream 输入流对象,用于读取数据
* @return 包含输入流所有数据的字节数组
* @throws IOException 当读取输入流或写入输出流时发生IO异常
*/
public static byte[] readToArray(InputStream inputStream)
throws IOException {
// 使用ByteArrayOutputStream来收集输入流中的所有数据
try (val byteArrayOutputStream = new ByteArrayOutputStream()) {
val bytes = new byte[DEFAULT_BUFFER_SIZE];
int length;
// 循环读取输入流数据,直到读取完毕
while ((length = inputStream.read(bytes)) != -1) {
byteArrayOutputStream.write(bytes, 0, length);
}
return byteArrayOutputStream.toByteArray();
}
}
/**
* 将输入流读取到Byte列表中<br>
* 请在外部自行关闭输入流对象 避免资源泄露
*
* @param inputStream 输入流对象,用于读取数据
* @return 包含输入流所有数据的Byte列表
* @throws IOException 当读取输入流时发生IO异常
*/
public static @NotNull List<Byte> readToList(InputStream inputStream)
throws IOException {
return Collections.newArrayLists(readToArray(inputStream));
}
/**
* 将输入流读取为字符串<br>
* 请在外部自行关闭输入流对象 避免资源泄露
*
* @param inputStream 输入流对象,用于读取数据
* @return 输入流对应的字符串内容
* @throws IOException 当读取输入流时发生IO异常
*/
public static String readToString(InputStream inputStream)
throws IOException {
return new String(readToArray(inputStream));
}
/**
* 将输入流的数据传输到输出流中<br>
* 请在外部自行关闭输入流输出流对象 避免资源泄露
*
* @param inputStream 源输入流,用于读取数据
* @param outputStream 目标输出流,用于写入数据
* @return 传输的总字节数
* @throws IOException 当读取或写入流时发生IO异常
*/
public static long transferTo(
InputStream inputStream,
OutputStream outputStream
) throws IOException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream can not be null");
}
if (outputStream == null) {
throw new IllegalArgumentException("outputStream can not be null");
}
val bytes = new byte[DEFAULT_BUFFER_SIZE];
int length;
long readAll = 0L;
// 循环读取并写入数据,直到输入流读取完毕
while ((length = inputStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, length);
readAll += length;
}
outputStream.flush();
return readAll;
}
}
@@ -1,120 +0,0 @@
/*
* Copyright 2025 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.main
* CurrentFile InputStreanWrapper.java
* LastUpdate 2025-09-14 22:12:16
* UpdateUser MingLiPro
*/
package com.mingliqiye.utils.stream;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
public class InputStreanWrapper extends InputStream implements AutoCloseable {
@Getter
private final InputStream inputStream;
public InputStreanWrapper(InputStream inputStream) {
this.inputStream = inputStream;
}
private static InputStreanWrapper of(InputStream inputStream) {
return new InputStreanWrapper(inputStream);
}
@Override
public int available() throws IOException {
return inputStream.available();
}
@Override
public int read() throws IOException {
return inputStream.read();
}
@Override
public int read(byte@NotNull [] b) throws IOException {
return inputStream.read(b);
}
@Override
public int read(byte@NotNull [] b, int off, int len) throws IOException {
return inputStream.read(b, off, len);
}
@Override
public long skip(long n) throws IOException {
return inputStream.skip(n);
}
@Override
public void mark(int readlimit) {
inputStream.mark(readlimit);
}
@Override
public void reset() throws IOException {
inputStream.reset();
}
@Override
public boolean markSupported() {
return inputStream.markSupported();
}
@Override
public void close() {
try {
inputStream.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 输入流转换为输出流 <br>
* jdk8 兼容实现 jdk9+ <br>
* 请使用 InputStream.transferTo()
*
* @param outputStream 输出流
* @return 转换的字节数
* @throws IOException IO错误
*/
public long transferToOutputStream(OutputStream outputStream)
throws IOException {
return InputStreamUtils.transferTo(inputStream, outputStream);
}
public byte[] readToArray() throws IOException {
return InputStreamUtils.readToArray(inputStream);
}
public List<Byte> readToList() throws IOException {
return InputStreamUtils.readToList(inputStream);
}
public String readToString() throws IOException {
return InputStreamUtils.readToString(inputStream);
}
}
@@ -1,81 +0,0 @@
package com.mingliqiye.utils.stream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
public class OutputStreamWrapper extends OutputStream implements AutoCloseable {
@Getter
private final OutputStream outputStream;
private final ByteArrayOutputStream byteArrayOutputStream =
new ByteArrayOutputStream();
public OutputStreamWrapper(OutputStream outputStream) {
this.outputStream = outputStream;
}
public static OutputStreamWrapper of(OutputStream outputStream) {
return new OutputStreamWrapper(outputStream);
}
@Override
public void write(int b) throws IOException {
byteArrayOutputStream.write(b);
}
@Override
public void write(byte@NotNull [] b) throws IOException {
byteArrayOutputStream.write(b);
}
public void write(List<Byte> b) throws IOException {
write(b, 0, b.size());
}
@Override
public void write(byte@NotNull [] b, int off, int len) throws IOException {
byteArrayOutputStream.write(b, off, len);
}
public void write(List<Byte> b, int off, int len) throws IOException {
byte[] bytes = new byte[b.size()];
for (int i = 0; i < b.size(); i++) {
bytes[i] = b.get(i);
}
byteArrayOutputStream.write(bytes, off, len);
}
@Override
public void flush() throws IOException {
outputStream.write(byteArrayOutputStream.toByteArray());
byteArrayOutputStream.reset();
}
public int getBufferCachedSize() {
return byteArrayOutputStream.size();
}
public byte[] getBufferCachedBytes() {
return byteArrayOutputStream.toByteArray();
}
@Override
public void close() {
try {
outputStream.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public long transferFromOutputStream(InputStream inputStream)
throws IOException {
return InputStreamUtils.transferTo(inputStream, outputStream);
}
}
File diff suppressed because it is too large Load Diff
@@ -1,9 +0,0 @@
package com.mingliqiye.utils.stream.interfaces;
public interface GetIdable<T> extends Getable<T> {
T getId();
default T get() {
return getId();
}
}
@@ -1,9 +0,0 @@
package com.mingliqiye.utils.stream.interfaces;
public interface GetKeyable<T> {
T getKey();
default T get() {
return getKey();
}
}
@@ -1,9 +0,0 @@
package com.mingliqiye.utils.stream.interfaces;
public interface GetNameable<T> extends Getable<T> {
T getName();
default T get() {
return getName();
}
}
@@ -1,5 +0,0 @@
package com.mingliqiye.utils.stream.interfaces;
public interface Getable<T> {
T get();
}
@@ -16,15 +16,13 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile ByteUtils.kt
* LastUpdate 2025-09-15 00:07:22
* LastUpdate 2025-09-15 17:26:34
* UpdateUser MingLiPro
*/
@file:JvmName("ByteUtils")
package com.mingliqiye.utils.bytes
import com.mingliqiye.utils.stream.SuperStream
const val ESC_ASC: Byte = 0x10
const val ESC_DESC: Byte = 0x1B
const val ESC_NONE: Byte = 0x00
@@ -43,6 +41,6 @@ const val ESC_RESERVED: Byte = 0x06
fun ByteArray.getByteArrayString(): MutableList<String> {
return this.toList().stream()
.map { a -> String.format("0X%02X", a!!.toInt() and 0xFF) }
.collect(SuperStream.Collectors.toList())
.collect(com.mingliqiye.utils.stream.toList()) as MutableList<String>
}
@@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile Collection.kt
* LastUpdate 2025-09-15 09:30:37
* LastUpdate 2025-09-15 17:26:00
* UpdateUser MingLiPro
*/
@@ -24,8 +24,8 @@
package com.mingliqiye.utils.collection
import com.mingliqiye.utils.stream.SuperStream
import java.util.*
import java.util.stream.Collectors
inline fun <reified T> Collection<T>.toArray(): Array<T> {
@@ -34,15 +34,15 @@ inline fun <reified T> Collection<T>.toArray(): Array<T> {
inline fun <reified T, V> Collection<T>.toMap(noinline v: (T) -> V): Map<T, V> {
return this.stream().collect(
SuperStream.Collectors.toMap(
SuperStream.Collectors::getThis, v
com.mingliqiye.utils.stream.toMapValueThis(
v
)
)
}
inline fun <reified T, V, K> Collection<T>.toMap(noinline k: (T) -> K, noinline v: (T) -> V): Map<K, V> {
return this.stream().collect(
SuperStream.Collectors.toMap(
Collectors.toMap(
k, v
)
)
@@ -16,24 +16,30 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile ForEach.kt
* LastUpdate 2025-09-15 12:01:36
* LastUpdate 2025-09-15 12:44:46
* UpdateUser MingLiPro
*/
@file:JvmName("ForEach")
package com.mingliqiye.utils.foreach
import com.mingliqiye.utils.functions.P1Function
import com.mingliqiye.utils.functions.P1RFunction
import com.mingliqiye.utils.functions.P2Function
import com.mingliqiye.utils.functions.P2RFunction
import com.mingliqiye.utils.functions.*
/**
* 对给定的可迭代对象执行指定的操作,同时处理元素值和索引。
* 根据可迭代对象是否实现 RandomAccess 接口选择最优的遍历方式。
*
* @param iterable 要遍历的可迭代对象
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
* @param <T> 可迭代对象中元素的类型
*/
fun <T> forEach(
iterable: Iterable<T>, action: P2Function<in T, in Int>
) {
when (iterable) {
is RandomAccess if iterable is MutableList<*> -> {
// 如果是支持随机访问的可变列表,则使用索引遍历以提高性能
val list = iterable as MutableList<T>
for (i in list.indices) {
action.call(list[i], i)
@@ -41,6 +47,7 @@ fun <T> forEach(
}
is MutableList<*> -> {
// 对于普通可变列表,使用迭代器进行遍历,并手动维护索引
var index = 0
val it = iterable.iterator()
while (it.hasNext()) {
@@ -50,6 +57,7 @@ fun <T> forEach(
}
else -> {
// 对于其他类型的可迭代对象,使用增强 for 循环并手动维护索引
var index = 0
for (element in iterable) {
action.call(element, index)
@@ -66,27 +74,39 @@ fun <T> forEach(
* @param iterable 要遍历的可迭代对象
* @param action 要对每个元素执行的操作,只接收元素值作为参数
* @param <T> 可迭代对象中元素的类型
**/
*/
fun <T> forEach(
iterable: Iterable<T>, action: P1Function<in T>
) {
if (iterable is RandomAccess) {
// 如果是支持随机访问的列表,则使用索引遍历以提高性能
val list = iterable as MutableList<T>
for (i in list.indices) {
action.call(list[i])
}
} else {
// 否则使用增强 for 循环进行遍历
for (element in iterable) {
action.call(element)
}
}
}
fun <T> forEach(
/**
* 对给定的可迭代对象执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
* 根据可迭代对象是否实现 RandomAccess 接口选择最优的遍历方式。
*
* @param iterable 要遍历的可迭代对象
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
* @param <T> 可迭代对象中元素的类型
*/
fun <T> forEachB(
iterable: Iterable<T>, action: P2RFunction<in T, in Int, out Boolean>
) {
when (iterable) {
is RandomAccess if iterable is MutableList<*> -> {
// 如果是支持随机访问的可变列表,则使用索引遍历以提高性能
val list = iterable as MutableList<T>
for (i in list.indices) {
if (action.call(list[i], i)) return
@@ -94,6 +114,7 @@ fun <T> forEach(
}
is MutableList<*> -> {
// 对于普通可变列表,使用迭代器进行遍历,并手动维护索引
var index = 0
val it = iterable.iterator()
while (it.hasNext()) {
@@ -103,6 +124,7 @@ fun <T> forEach(
}
else -> {
// 对于其他类型的可迭代对象,使用增强 for 循环并手动维护索引
var index = 0
for (element in iterable) {
if (action.call(element, index)) return
@@ -114,242 +136,574 @@ fun <T> forEach(
/**
* 对给定的可迭代对象执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
* 根据可迭代对象是否实现 RandomAccess 接口选择最优的遍历方式。
*
* @param iterable 要遍历的可迭代对象
* @param action 要对每个元素执行的操作,只接收元素值作为参数
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
* @param <T> 可迭代对象中元素的类型
**/
fun <T> forEach(
*/
fun <T> forEachB(
iterable: Iterable<T>, action: P1RFunction<in T, out Boolean>
) {
if (iterable is RandomAccess) {
// 如果是支持随机访问的列表,则使用索引遍历以提高性能
val list = iterable as MutableList<T>
for (i in list.indices) {
if (action.call(list[i])) return
}
} else {
// 否则使用增强 for 循环进行遍历
for (element in iterable) {
if (action.call(element)) return
}
}
}
/**
* 对给定的数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
* @param <T> 数组中元素的类型
*/
fun <T> forEach(
array: Array<T>, action: P2Function<in T, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
* @param <T> 数组中元素的类型
*/
fun <T> forEach(
array: Array<T>, action: P1Function<in T>
) {
forEach(array.toList(), action)
}
fun <T> forEach(
/**
* 对给定的数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
* @param <T> 数组中元素的类型
*/
fun <T> forEachB(
array: Array<T>, action: P2RFunction<in T, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun <T> forEach(
/**
* 对给定的数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
* @param <T> 数组中元素的类型
*/
fun <T> forEachB(
array: Array<T>, action: P1RFunction<in T, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的字节数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的字节数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: ByteArray, action: P2Function<in Byte, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的字节数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的字节数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: ByteArray, action: P1Function<in Byte>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的字节数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的字节数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: ByteArray, action: P2RFunction<in Byte, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的字节数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的字节数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: ByteArray, action: P1RFunction<in Byte, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的字符数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的字符数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: CharArray, action: P2Function<in Char, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的字符数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的字符数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: CharArray, action: P1Function<in Char>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的字符数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的字符数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: CharArray, action: P2RFunction<in Char, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的字符数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的字符数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: CharArray, action: P1RFunction<in Char, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的整型数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: IntArray, action: P2Function<in Int, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的整型数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: IntArray, action: P1Function<in Int>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的整型数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: IntArray, action: P2RFunction<in Int, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的整型数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: IntArray, action: P1RFunction<in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的长整型数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的长整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: LongArray, action: P2Function<in Long, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的长整型数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的长整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: LongArray, action: P1Function<in Long>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的长整型数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的长整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: LongArray, action: P2RFunction<in Long, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的长整型数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的长整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: LongArray, action: P1RFunction<in Long, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的短整型数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的短整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: ShortArray, action: P2Function<in Short, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的短整型数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的短整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: ShortArray, action: P1Function<in Short>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的短整型数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的短整型数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: ShortArray, action: P2RFunction<in Short, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的短整型数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的短整型数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: ShortArray, action: P1RFunction<in Short, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的浮点数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的浮点数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: FloatArray, action: P2Function<in Float, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的浮点数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的浮点数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: FloatArray, action: P1Function<in Float>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的浮点数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的浮点数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: FloatArray, action: P2RFunction<in Float, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的浮点数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的浮点数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: FloatArray, action: P1RFunction<in Float, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的双精度浮点数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的双精度浮点数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: DoubleArray, action: P2Function<in Double, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的双精度浮点数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的双精度浮点数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: DoubleArray, action: P1Function<in Double>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的双精度浮点数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的双精度浮点数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: DoubleArray, action: P2RFunction<in Double, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的双精度浮点数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的双精度浮点数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: DoubleArray, action: P1RFunction<in Double, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的布尔数组执行指定的操作,同时处理元素值和索引。
*
* @param array 要遍历的布尔数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数
*/
fun forEach(
array: BooleanArray, action: P2Function<in Boolean, in Int>
) {
forEach(array.toList(), action)
}
/**
* 对给定的布尔数组执行指定的操作,仅处理元素值。
*
* @param array 要遍历的布尔数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数
*/
fun forEach(
array: BooleanArray, action: P1Function<in Boolean>
) {
forEach(array.toList(), action)
}
fun forEach(
/**
* 对给定的布尔数组执行指定的操作,同时处理元素值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的布尔数组
* @param action 要对每个元素执行的操作,接收元素值和索引作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: BooleanArray, action: P2RFunction<in Boolean, in Int, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
fun forEach(
/**
* 对给定的布尔数组执行指定的操作,仅处理元素值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的布尔数组
* @param action 要对每个元素执行的操作,只接收元素值作为参数,返回 Boolean 表示是否提前终止
*/
fun forEachB(
array: BooleanArray, action: P1RFunction<in Boolean, out Boolean>
) {
forEach(array.toList(), action)
forEachB(array.toList(), action)
}
/**
* 对给定的键值对集合执行指定的操作,同时处理键、值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的键值对集合
* @param action 要对每个键值对执行的操作,接收键、值和索引作为参数,返回 Boolean 表示是否提前终止
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 集合的具体类型
*/
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachB(
array: A, action: P3RFunction<in K, in V, in Int, out Boolean>
) {
forEachB(array, P2RFunction<Map.Entry<K, V>, Int, Boolean> { p1, p2 -> action.call(p1.key, p1.value, p2) })
}
/**
* 对给定的映射执行指定的操作,同时处理键、值和索引。
* 如果操作返回 true,则提前终止遍历。
*
* @param map 要遍历的映射
* @param action 要对每个键值对执行的操作,接收键、值和索引作为参数,返回 Boolean 表示是否提前终止
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 映射的具体类型
*/
fun <K, V, A : Map<K, V>> forEachB(
map: A, action: P3RFunction<in K, in V, in Int, out Boolean>
) {
forEachB(map.entries, P2RFunction<Map.Entry<K, V>, Int, Boolean> { p1, p2 -> action.call(p1.key, p1.value, p2) })
}
/**
* 对给定的键值对集合执行指定的操作,仅处理键和值。
*
* @param array 要遍历的键值对集合
* @param action 要对每个键值对执行的操作,接收键和值作为参数
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 集合的具体类型
*/
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMap(
array: A, action: P2Function<in K, in V>
) {
forEach(array, P1Function<Map.Entry<K, V>> { p1 -> action.call(p1.key, p1.value) })
}
/**
* 对给定的映射执行指定的操作,仅处理键和值。
*
* @param map 要遍历的映射
* @param action 要对每个键值对执行的操作,接收键和值作为参数
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 映射的具体类型
*/
fun <K, V, A : Map<K, V>> forEachMap(
map: A, action: P2Function<in K, in V>
) {
forEach(map.entries, P1Function<Map.Entry<K, V>> { p1 -> action.call(p1.key, p1.value) })
}
/**
* 对给定的键值对集合执行指定的操作,仅处理键和值。
* 如果操作返回 true,则提前终止遍历。
*
* @param array 要遍历的键值对集合
* @param action 要对每个键值对执行的操作,接收键和值作为参数,返回 Boolean 表示是否提前终止
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 集合的具体类型
*/
fun <K, V, A : Collection<Map.Entry<K, V>>> forEachMapB(
array: A, action: P2RFunction<in K, in V, out Boolean>
) {
forEachB(array, P1RFunction<Map.Entry<K, V>, Boolean> { p1 -> action.call(p1.key, p1.value) })
}
/**
* 对给定的映射执行指定的操作,仅处理键和值。
* 如果操作返回 true,则提前终止遍历。
*
* @param map 要遍历的映射
* @param action 要对每个键值对执行的操作,接收键和值作为参数,返回 Boolean 表示是否提前终止
* @param <K> 键的类型
* @param <V> 值的类型
* @param <A> 映射的具体类型
*/
fun <K, V, A : Map<K, V>> forEachMapB(
map: A, action: P2RFunction<in K, in V, out Boolean>
) {
forEachB(map.entries, P1RFunction<Map.Entry<K, V>, Boolean> { p1 -> action.call(p1.key, p1.value) })
}
@@ -0,0 +1,50 @@
/*
* Copyright 2025 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.main
* CurrentFile InputStreamUtils.kt
* LastUpdate 2025-09-15 17:26:34
* UpdateUser MingLiPro
*/
@file:JvmName("InputStreamUtils")
package com.mingliqiye.utils.io
import java.io.InputStream
import java.io.OutputStream
import java.nio.charset.Charset
fun InputStream.readAllText(charset: Charset = Charsets.UTF_8): String {
return this.readAllBytes().toString(charset)
}
fun InputStream.readAllBytes(): ByteArray {
return this.readBytes()
}
fun InputStream.exportBytes(out: OutputStream) {
out.write(this.readAllBytes())
out.flush()
}
fun InputStream.readToList(): List<Byte> {
return this.readBytes().toList()
}
@@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile DateTimeTypeHandler.kt
* LastUpdate 2025-09-14 18:19:29
* LastUpdate 2025-09-15 13:53:53
* UpdateUser MingLiPro
*/
@file:JvmName("DateTimeConvertor")
@@ -65,8 +65,8 @@ class DateTimeTypeHandler : BaseTypeHandler<DateTime>() {
override fun setNonNullParameter(
ps: PreparedStatement,
i: Int,
parameter: DateTime, // 移除了 ?,因为这是 non-null 方法
jdbcType: JdbcType
parameter: DateTime,
jdbcType: JdbcType?
) {
// 使用 setObject 允许传入 null,由数据库处理
ps.setObject(i, toLocalDateTime(parameter))
@@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile UUIDTypeHandler.kt
* LastUpdate 2025-09-14 18:19:29
* LastUpdate 2025-09-15 13:54:18
* UpdateUser MingLiPro
*/
@file:JvmName("UUIDConvertor")
@@ -112,7 +112,7 @@ class UUIDBinaryTypeHandler : BaseTypeHandler<UUID>() {
* @param jdbcType JDBC类型
*/
override fun setNonNullParameter(
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType?
) {
ps.setBytes(i, uuidToByteArray(parameter))
}
@@ -172,7 +172,7 @@ class UUIDStringTypeHandler : BaseTypeHandler<UUID>() {
* @param jdbcType JDBC类型
*/
override fun setNonNullParameter(
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType?
) {
ps.setString(i, uuidToString(parameter))
}
@@ -234,7 +234,7 @@ class UUIDTypeHandler : BaseTypeHandler<UUID>() {
* @param jdbcType JDBC类型
*/
override fun setNonNullParameter(
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType
ps: PreparedStatement, i: Int, parameter: UUID, jdbcType: JdbcType?
) {
ps.setObject(i, parameter.getUuid())
}
@@ -16,7 +16,7 @@
* ProjectName mingli-utils
* ModuleName mingli-utils.main
* CurrentFile MysqlUUIDBinaryTypeHandler.kt
* LastUpdate 2025-09-14 18:19:29
* LastUpdate 2025-09-15 13:54:29
* UpdateUser MingLiPro
*/
@@ -72,7 +72,7 @@ class MysqlUUIDBinaryTypeHandler : BaseTypeHandler<UUID>() {
ps: PreparedStatement,
i: Int,
parameter: UUID,
jdbcType: JdbcType
jdbcType: JdbcType?
) {
ps.setBytes(i, toByteArray(parameter))
}
@@ -0,0 +1,122 @@
/*
* Copyright 2025 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.main
* CurrentFile SuperStream.kt
* LastUpdate 2025-09-15 17:17:48
* UpdateUser MingLiPro
*/
@file:JvmName("Colls")
package com.mingliqiye.utils.stream
import java.util.stream.Collector
import java.util.stream.Collectors
import java.util.stream.Stream
class SuperStream<T> private constructor(val stream: Stream<T>) : Stream<T> by stream {
companion object {
@JvmStatic
fun <T> of(stream: Stream<T>): SuperStream<T> {
return SuperStream(stream)
}
@JvmStatic
fun <T> of(collection: Collection<T>): SuperStream<T> {
return SuperStream(collection.stream())
}
@JvmStatic
fun <T : Map<K, V>, K, V> of(map: T): SuperStream<Map.Entry<K, V>> {
return of(map.entries)
}
@JvmStatic
fun <T> of(vararg array: T): SuperStream<T> {
return of(array.toList())
}
@JvmStatic
fun <T> of(iterator: Iterator<T>): SuperStream<T> {
val data = ArrayList<T>(20)
while (iterator.hasNext()) {
data.add(iterator.next())
}
return of(data)
}
}
}
interface Gettable<T> {
fun get(): T
}
interface KeyGettable<T> : Gettable<T> {
fun getKey(): T
override fun get(): T {
return getKey()
}
}
interface IdGettable<T> : Gettable<T> {
fun getId(): T
override fun get(): T {
return getId()
}
}
fun <T> getThis(t: T): T {
return t
}
fun <T, U> toMapValueThis(valueMapper: java.util.function.Function<in T, out U>): Collector<T, *, Map<T, U>> {
return Collectors.toMap(
java.util.function.Function<T, T> { it },
valueMapper
) as Collector<T, *, Map<T, U>>
}
fun <T, K> toMap(keyMapper: java.util.function.Function<in T, out K>): Collector<T, *, Map<K, T>> {
return Collectors.toMap(
keyMapper,
java.util.function.Function<T, T> { it },
) as Collector<T, *, Map<K, T>>
}
fun <K> toMapGet(): Collector<Gettable<K>, *, Map<K, Gettable<K>>> {
return Collectors.toMap(
java.util.function.Function<Gettable<K>, K> { it.get() },
java.util.function.Function<Gettable<K>, Gettable<K>> { it },
) as Collector<Gettable<K>, *, Map<K, Gettable<K>>>
}
fun <K, V> toMap(): Collector<Map.Entry<K, V>, *, Map<K, V>> {
return Collectors.toMap(
{ entry: Map.Entry<K, V> -> entry.key },
{ entry: Map.Entry<K, V> -> entry.value }
) as Collector<Map.Entry<K, V>, *, Map<K, V>>
}
fun <T> toList(): Collector<T, *, List<T>> {
return Collectors.toList<T>()
}
fun <T> toSet(): Collector<T, *, Set<T>> {
return Collectors.toSet<T>()
}