mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
e4d7d6b7d4
commit
ce11e7147d
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.collection;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.codec.hash.Hash32;
|
||||
import cn.hutool.core.collection.iter.IterUtil;
|
||||
import cn.hutool.core.collection.iter.IteratorEnumeration;
|
||||
import cn.hutool.core.comparator.CompareUtil;
|
||||
@ -9,7 +10,8 @@ import cn.hutool.core.comparator.PropertyComparator;
|
||||
import cn.hutool.core.convert.CompositeConverter;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.codec.hash.Hash32;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.core.lang.func.SerConsumer3;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.reflect.ClassUtil;
|
||||
import cn.hutool.core.reflect.ConstructorUtil;
|
||||
@ -21,7 +23,6 @@ import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.AbstractCollection;
|
||||
import java.util.ArrayList;
|
||||
@ -1942,14 +1943,14 @@ public class CollUtil {
|
||||
// ------------------------------------------------------------------------------------------------- forEach
|
||||
|
||||
/**
|
||||
* 循环遍历 {@link Iterable},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
* 循环遍历 {@link Iterable},使用{@link SerBiConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param iterable {@link Iterable}
|
||||
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
|
||||
* @param consumer {@link SerBiConsumer} 遍历的每条数据处理器
|
||||
* @since 5.4.7
|
||||
*/
|
||||
public static <T> void forEach(final Iterable<T> iterable, final IndexedConsumer<T> consumer) {
|
||||
public static <T> void forEach(final Iterable<T> iterable, final SerBiConsumer<T, Integer> consumer) {
|
||||
if (iterable == null) {
|
||||
return;
|
||||
}
|
||||
@ -1957,13 +1958,13 @@ public class CollUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环遍历 {@link Iterator},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
* 循环遍历 {@link Iterator},使用{@link SerBiConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param iterator {@link Iterator}
|
||||
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
|
||||
* @param consumer {@link SerBiConsumer} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <T> void forEach(final Iterator<T> iterator, final IndexedConsumer<T> consumer) {
|
||||
public static <T> void forEach(final Iterator<T> iterator, final SerBiConsumer<T, Integer> consumer) {
|
||||
if (iterator == null) {
|
||||
return;
|
||||
}
|
||||
@ -1975,13 +1976,13 @@ public class CollUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环遍历 {@link Enumeration},使用{@link IndexedConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
* 循环遍历 {@link Enumeration},使用{@link SerBiConsumer} 接受遍历的每条数据,并针对每条数据做处理
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param enumeration {@link Enumeration}
|
||||
* @param consumer {@link IndexedConsumer} 遍历的每条数据处理器
|
||||
* @param consumer {@link SerBiConsumer} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <T> void forEach(final Enumeration<T> enumeration, final IndexedConsumer<T> consumer) {
|
||||
public static <T> void forEach(final Enumeration<T> enumeration, final SerBiConsumer<T, Integer> consumer) {
|
||||
if (enumeration == null) {
|
||||
return;
|
||||
}
|
||||
@ -1993,15 +1994,15 @@ public class CollUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 循环遍历Map,使用{@link IndexedKVConsumer} 接受遍历的每条数据,并针对每条数据做处理<br>
|
||||
* 循环遍历Map,使用{@link SerConsumer3} 接受遍历的每条数据,并针对每条数据做处理<br>
|
||||
* 和JDK8中的map.forEach不同的是,此方法支持index
|
||||
*
|
||||
* @param <K> Key类型
|
||||
* @param <V> Value类型
|
||||
* @param map {@link Map}
|
||||
* @param kvConsumer {@link IndexedKVConsumer} 遍历的每条数据处理器
|
||||
* @param kvConsumer {@link SerConsumer3} 遍历的每条数据处理器
|
||||
*/
|
||||
public static <K, V> void forEach(final Map<K, V> map, final IndexedKVConsumer<K, V> kvConsumer) {
|
||||
public static <K, V> void forEach(final Map<K, V> map, final SerConsumer3<K, V, Integer> kvConsumer) {
|
||||
if (map == null) {
|
||||
return;
|
||||
}
|
||||
@ -2260,46 +2261,6 @@ public class CollUtil {
|
||||
iterable.forEach(x -> Optional.ofNullable(map.get(keyGenerate.apply(x))).ifPresent(y -> biConsumer.accept(x, y)));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------------------- Interface start
|
||||
|
||||
/**
|
||||
* 针对一个参数做相应的操作<br>
|
||||
* 此函数接口与JDK8中Consumer不同是多提供了index参数,用于标记遍历对象是第几个。
|
||||
*
|
||||
* @param <T> 处理参数类型
|
||||
* @author Looly
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IndexedConsumer<T> extends Serializable {
|
||||
/**
|
||||
* 接受并处理一个参数
|
||||
*
|
||||
* @param value 参数值
|
||||
* @param index 参数在集合中的索引
|
||||
*/
|
||||
void accept(T value, int index);
|
||||
}
|
||||
|
||||
/**
|
||||
* 针对两个参数做相应的操作,例如Map中的KEY和VALUE
|
||||
*
|
||||
* @param <K> KEY类型
|
||||
* @param <V> VALUE类型
|
||||
* @author Looly
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface IndexedKVConsumer<K, V> extends Serializable {
|
||||
/**
|
||||
* 接受并处理一对参数
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param index 参数在集合中的索引
|
||||
*/
|
||||
void accept(K key, V value, int index);
|
||||
}
|
||||
// ---------------------------------------------------------------------------------------------- Interface end
|
||||
|
||||
/**
|
||||
* 获取Collection或者iterator的大小,此方法可以处理的对象类型如下:
|
||||
* <ul>
|
||||
|
@ -13,6 +13,7 @@ import cn.hutool.core.io.file.Tailer;
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.io.unit.DataSizeUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.thread.ThreadUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
@ -2269,10 +2270,10 @@ public class FileUtil extends PathUtil {
|
||||
* 按行处理文件内容,编码为UTF-8
|
||||
*
|
||||
* @param file 文件
|
||||
* @param lineHandler {@link LineHandler}行处理器
|
||||
* @param lineHandler {@link SerConsumer}行处理器
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static void readUtf8Lines(final File file, final LineHandler lineHandler) throws IORuntimeException {
|
||||
public static void readUtf8Lines(final File file, final SerConsumer<String> lineHandler) throws IORuntimeException {
|
||||
readLines(file, CharsetUtil.UTF_8, lineHandler);
|
||||
}
|
||||
|
||||
@ -2281,10 +2282,10 @@ public class FileUtil extends PathUtil {
|
||||
*
|
||||
* @param file 文件
|
||||
* @param charset 编码
|
||||
* @param lineHandler {@link LineHandler}行处理器
|
||||
* @param lineHandler {@link SerConsumer}行处理器
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static void readLines(final File file, final Charset charset, final LineHandler lineHandler) throws IORuntimeException {
|
||||
public static void readLines(final File file, final Charset charset, final SerConsumer<String> lineHandler) throws IORuntimeException {
|
||||
FileReader.of(file, charset).readLines(lineHandler);
|
||||
}
|
||||
|
||||
@ -2293,15 +2294,15 @@ public class FileUtil extends PathUtil {
|
||||
*
|
||||
* @param file {@link RandomAccessFile}文件
|
||||
* @param charset 编码
|
||||
* @param lineHandler {@link LineHandler}行处理器
|
||||
* @param lineHandler {@link SerConsumer}行处理器
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static void readLines(final RandomAccessFile file, final Charset charset, final LineHandler lineHandler) {
|
||||
public static void readLines(final RandomAccessFile file, final Charset charset, final SerConsumer<String> lineHandler) {
|
||||
String line;
|
||||
try {
|
||||
while ((line = file.readLine()) != null) {
|
||||
lineHandler.handle(CharsetUtil.convert(line, CharsetUtil.ISO_8859_1, charset));
|
||||
lineHandler.accept(CharsetUtil.convert(line, CharsetUtil.ISO_8859_1, charset));
|
||||
}
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
@ -2313,14 +2314,14 @@ public class FileUtil extends PathUtil {
|
||||
*
|
||||
* @param file {@link RandomAccessFile}文件
|
||||
* @param charset 编码
|
||||
* @param lineHandler {@link LineHandler}行处理器
|
||||
* @param lineHandler {@link SerConsumer}行处理器
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static void readLine(final RandomAccessFile file, final Charset charset, final LineHandler lineHandler) {
|
||||
public static void readLine(final RandomAccessFile file, final Charset charset, final SerConsumer<String> lineHandler) {
|
||||
final String line = readLine(file, charset);
|
||||
if (null != line) {
|
||||
lineHandler.handle(line);
|
||||
lineHandler.accept(line);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3352,7 +3353,7 @@ public class FileUtil extends PathUtil {
|
||||
* @param file 文件
|
||||
* @param handler 行处理器
|
||||
*/
|
||||
public static void tail(final File file, final LineHandler handler) {
|
||||
public static void tail(final File file, final SerConsumer<String> handler) {
|
||||
tail(file, CharsetUtil.UTF_8, handler);
|
||||
}
|
||||
|
||||
@ -3364,7 +3365,7 @@ public class FileUtil extends PathUtil {
|
||||
* @param charset 编码
|
||||
* @param handler 行处理器
|
||||
*/
|
||||
public static void tail(final File file, final Charset charset, final LineHandler handler) {
|
||||
public static void tail(final File file, final Charset charset, final SerConsumer<String> handler) {
|
||||
new Tailer(file, charset, handler).start();
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.copy.ReaderWriterCopier;
|
||||
import cn.hutool.core.io.copy.StreamCopier;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
@ -621,7 +622,7 @@ public class IoUtil extends NioUtil {
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static <T extends Collection<String>> T readLines(final Reader reader, final T collection) throws IORuntimeException {
|
||||
readLines(reader, (LineHandler) collection::add);
|
||||
readLines(reader, (SerConsumer<String>) collection::add);
|
||||
return collection;
|
||||
}
|
||||
|
||||
@ -633,7 +634,7 @@ public class IoUtil extends NioUtil {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.1.1
|
||||
*/
|
||||
public static void readUtf8Lines(final InputStream in, final LineHandler lineHandler) throws IORuntimeException {
|
||||
public static void readUtf8Lines(final InputStream in, final SerConsumer<String> lineHandler) throws IORuntimeException {
|
||||
readLines(in, CharsetUtil.UTF_8, lineHandler);
|
||||
}
|
||||
|
||||
@ -646,7 +647,7 @@ public class IoUtil extends NioUtil {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public static void readLines(final InputStream in, final Charset charset, final LineHandler lineHandler) throws IORuntimeException {
|
||||
public static void readLines(final InputStream in, final Charset charset, final SerConsumer<String> lineHandler) throws IORuntimeException {
|
||||
readLines(getReader(in, charset), lineHandler);
|
||||
}
|
||||
|
||||
@ -659,12 +660,12 @@ public class IoUtil extends NioUtil {
|
||||
* @param lineHandler 行处理接口,实现handle方法用于编辑一行的数据后入到指定地方
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public static void readLines(final Reader reader, final LineHandler lineHandler) throws IORuntimeException {
|
||||
public static void readLines(final Reader reader, final SerConsumer<String> lineHandler) throws IORuntimeException {
|
||||
Assert.notNull(reader);
|
||||
Assert.notNull(lineHandler);
|
||||
|
||||
for (final String line : lineIter(reader)) {
|
||||
lineHandler.handle(line);
|
||||
lineHandler.accept(line);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,15 +0,0 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
/**
|
||||
* 行处理器
|
||||
* @author Looly
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface LineHandler {
|
||||
/**
|
||||
* 处理一行数据,可以编辑后存入指定地方
|
||||
* @param line 行
|
||||
*/
|
||||
void handle(String line);
|
||||
}
|
@ -3,9 +3,9 @@ package cn.hutool.core.io.file;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.LineHandler;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
@ -179,7 +179,7 @@ public class FileReader extends FileWrapper {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 3.0.9
|
||||
*/
|
||||
public void readLines(final LineHandler lineHandler) throws IORuntimeException{
|
||||
public void readLines(final SerConsumer<String> lineHandler) throws IORuntimeException{
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = FileUtil.getReader(file, charset);
|
||||
|
@ -2,8 +2,8 @@ package cn.hutool.core.io.file;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.LineHandler;
|
||||
import cn.hutool.core.io.watch.SimpleWatcher;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
@ -21,16 +21,16 @@ public class LineReadWatcher extends SimpleWatcher implements Runnable {
|
||||
|
||||
private final RandomAccessFile randomAccessFile;
|
||||
private final Charset charset;
|
||||
private final LineHandler lineHandler;
|
||||
private final SerConsumer<String> lineHandler;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param randomAccessFile {@link RandomAccessFile}
|
||||
* @param charset 编码
|
||||
* @param lineHandler 行处理器{@link LineHandler}实现
|
||||
* @param lineHandler 行处理器{@link SerConsumer}实现
|
||||
*/
|
||||
public LineReadWatcher(final RandomAccessFile randomAccessFile, final Charset charset, final LineHandler lineHandler) {
|
||||
public LineReadWatcher(final RandomAccessFile randomAccessFile, final Charset charset, final SerConsumer<String> lineHandler) {
|
||||
this.randomAccessFile = randomAccessFile;
|
||||
this.charset = charset;
|
||||
this.lineHandler = lineHandler;
|
||||
@ -45,7 +45,7 @@ public class LineReadWatcher extends SimpleWatcher implements Runnable {
|
||||
public void onModify(final WatchEvent<?> event, final Path currentPath) {
|
||||
final RandomAccessFile randomAccessFile = this.randomAccessFile;
|
||||
final Charset charset = this.charset;
|
||||
final LineHandler lineHandler = this.lineHandler;
|
||||
final SerConsumer<String> lineHandler = this.lineHandler;
|
||||
|
||||
try {
|
||||
final long currentLength = randomAccessFile.length();
|
||||
|
@ -4,8 +4,8 @@ import cn.hutool.core.date.DateUnit;
|
||||
import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.LineHandler;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
||||
@ -30,12 +30,15 @@ import java.util.concurrent.TimeUnit;
|
||||
public class Tailer implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final LineHandler CONSOLE_HANDLER = new ConsoleLineHandler();
|
||||
/**
|
||||
* 控制台打印的处理类
|
||||
*/
|
||||
public static final SerConsumer<String> CONSOLE_HANDLER = new ConsoleLineHandler();
|
||||
|
||||
/** 编码 */
|
||||
private final Charset charset;
|
||||
/** 行处理器 */
|
||||
private final LineHandler lineHandler;
|
||||
private final SerConsumer<String> lineHandler;
|
||||
/** 初始读取的行数 */
|
||||
private final int initReadLine;
|
||||
/** 定时任务检查间隔时长 */
|
||||
@ -50,7 +53,7 @@ public class Tailer implements Serializable {
|
||||
* @param file 文件
|
||||
* @param lineHandler 行处理器
|
||||
*/
|
||||
public Tailer(final File file, final LineHandler lineHandler) {
|
||||
public Tailer(final File file, final SerConsumer<String> lineHandler) {
|
||||
this(file, lineHandler, 0);
|
||||
}
|
||||
|
||||
@ -61,7 +64,7 @@ public class Tailer implements Serializable {
|
||||
* @param lineHandler 行处理器
|
||||
* @param initReadLine 启动时预读取的行数
|
||||
*/
|
||||
public Tailer(final File file, final LineHandler lineHandler, final int initReadLine) {
|
||||
public Tailer(final File file, final SerConsumer<String> lineHandler, final int initReadLine) {
|
||||
this(file, CharsetUtil.UTF_8, lineHandler, initReadLine, DateUnit.SECOND.getMillis());
|
||||
}
|
||||
|
||||
@ -72,7 +75,7 @@ public class Tailer implements Serializable {
|
||||
* @param charset 编码
|
||||
* @param lineHandler 行处理器
|
||||
*/
|
||||
public Tailer(final File file, final Charset charset, final LineHandler lineHandler) {
|
||||
public Tailer(final File file, final Charset charset, final SerConsumer<String> lineHandler) {
|
||||
this(file, charset, lineHandler, 0, DateUnit.SECOND.getMillis());
|
||||
}
|
||||
|
||||
@ -85,7 +88,7 @@ public class Tailer implements Serializable {
|
||||
* @param initReadLine 启动时预读取的行数
|
||||
* @param period 检查间隔
|
||||
*/
|
||||
public Tailer(final File file, final Charset charset, final LineHandler lineHandler, final int initReadLine, final long period) {
|
||||
public Tailer(final File file, final Charset charset, final SerConsumer<String> lineHandler, final int initReadLine, final long period) {
|
||||
checkFile(file);
|
||||
this.charset = charset;
|
||||
this.lineHandler = lineHandler;
|
||||
@ -188,7 +191,7 @@ public class Tailer implements Serializable {
|
||||
|
||||
// 输出缓存栈中的内容
|
||||
while (false == stack.isEmpty()) {
|
||||
this.lineHandler.handle(stack.pop());
|
||||
this.lineHandler.accept(stack.pop());
|
||||
}
|
||||
}
|
||||
|
||||
@ -221,9 +224,10 @@ public class Tailer implements Serializable {
|
||||
* @author looly
|
||||
* @since 4.5.2
|
||||
*/
|
||||
public static class ConsoleLineHandler implements LineHandler {
|
||||
public static class ConsoleLineHandler implements SerConsumer<String> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@Override
|
||||
public void handle(final String line) {
|
||||
public void accepting(final String line) {
|
||||
Console.log(line);
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package cn.hutool.core.io.watch;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.WatchEvent;
|
||||
|
||||
/**
|
||||
* 监听事件处理函数接口
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.4.0
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface WatchAction {
|
||||
|
||||
/**
|
||||
* 事件处理,通过实现此方法处理各种事件。
|
||||
*
|
||||
* 事件可以调用 {@link WatchEvent#kind()}获取,对应事件见{@link WatchKind}
|
||||
*
|
||||
* @param event 事件
|
||||
* @param currentPath 事件发生的当前Path路径
|
||||
*/
|
||||
void doAction(WatchEvent<?> event, Path currentPath);
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io.watch;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
@ -132,7 +133,7 @@ public class WatchServer extends Thread implements Closeable, Serializable {
|
||||
* @param watchFilter 监听过滤接口,通过实现此接口过滤掉不需要监听的情况,{@link Predicate#test(Object)}为{@code true}保留,null表示不过滤
|
||||
* @since 5.4.0
|
||||
*/
|
||||
public void watch(final WatchAction action, final Predicate<WatchEvent<?>> watchFilter) {
|
||||
public void watch(final SerBiConsumer<WatchEvent<?>, Path> action, final Predicate<WatchEvent<?>> watchFilter) {
|
||||
final WatchKey wk;
|
||||
try {
|
||||
wk = watchService.take();
|
||||
@ -150,7 +151,7 @@ public class WatchServer extends Thread implements Closeable, Serializable {
|
||||
continue;
|
||||
}
|
||||
|
||||
action.doAction(event, currentPath);
|
||||
action.accept(event, currentPath);
|
||||
}
|
||||
|
||||
wk.reset();
|
||||
|
@ -6,6 +6,7 @@ import cn.hutool.core.tree.MapTree;
|
||||
* 树节点解析器 可以参考{@link DefaultNodeParser}
|
||||
*
|
||||
* @param <T> 转换的实体 为数据源里的对象类型
|
||||
* @param <E> ID类型
|
||||
* @author liangbaikai
|
||||
*/
|
||||
@FunctionalInterface
|
||||
|
4
hutool-core/src/main/java/cn/hutool/core/tree/parser/package-info.java
Executable file
4
hutool-core/src/main/java/cn/hutool/core/tree/parser/package-info.java
Executable file
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 节点解析器封装
|
||||
*/
|
||||
package cn.hutool.core.tree.parser;
|
@ -56,7 +56,7 @@ public class CoordinateUtil {
|
||||
* WGS84 转换为 火星坐标系 (GCJ-02)
|
||||
*
|
||||
* @param lng 经度值
|
||||
* @param lat 维度值
|
||||
* @param lat 纬度值
|
||||
* @return 火星坐标 (GCJ-02)
|
||||
*/
|
||||
public static Coordinate wgs84ToGcj02(final double lng, final double lat) {
|
||||
@ -67,7 +67,7 @@ public class CoordinateUtil {
|
||||
* WGS84 坐标转为 百度坐标系 (BD-09) 坐标
|
||||
*
|
||||
* @param lng 经度值
|
||||
* @param lat 维度值
|
||||
* @param lat 纬度值
|
||||
* @return bd09 坐标
|
||||
*/
|
||||
public static Coordinate wgs84ToBd09(final double lng, final double lat) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
@ -27,7 +28,7 @@ public class IoUtilTest {
|
||||
@Test
|
||||
public void readLinesTest() {
|
||||
try (final BufferedReader reader = ResourceUtil.getUtf8Reader("test_lines.csv")) {
|
||||
IoUtil.readLines(reader, (LineHandler) Assert::assertNotNull);
|
||||
IoUtil.readLines(reader, (SerConsumer<String>) Assert::assertNotNull);
|
||||
} catch (final IOException e) {
|
||||
throw new IORuntimeException(e);
|
||||
}
|
||||
|
@ -2,12 +2,17 @@ package cn.hutool.cron.task;
|
||||
|
||||
/**
|
||||
* {@link Runnable} 的 {@link Task}包装
|
||||
* @author Looly
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
public class RunnableTask implements Task {
|
||||
private final Runnable runnable;
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param runnable {@link Runnable}
|
||||
*/
|
||||
public RunnableTask(final Runnable runnable) {
|
||||
this.runnable = runnable;
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.hutool.http;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.StopWatch;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.net.ssl.SSLProtocols;
|
||||
import cn.hutool.core.net.url.UrlBuilder;
|
||||
@ -19,6 +20,7 @@ import java.util.Map;
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public class HttpRequestTest {
|
||||
final String url = "http://photo.qzone.qq.com/fcgi-bin/fcg_list_album?uin=88888&outstyle=2";
|
||||
|
||||
@ -218,4 +220,34 @@ public class HttpRequestTest {
|
||||
final HttpResponse execute = HttpRequest.get("http://localhost:8888/getCookier").execute();
|
||||
Console.log(execute.getCookies());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void optionsTest() {
|
||||
final HttpRequest options = HttpRequest.options("https://hutool.cn");
|
||||
Assert.notNull(options.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteTest() {
|
||||
final HttpRequest options = HttpRequest.delete("https://hutool.cn");
|
||||
Assert.notNull(options.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traceTest() {
|
||||
final HttpRequest options = HttpRequest.trace("https://hutool.cn");
|
||||
Assert.notNull(options.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getToStringTest() {
|
||||
final HttpRequest a = HttpRequest.get("https://hutool.cn/").form("a", 1);
|
||||
Assert.notNull(a.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postToStringTest() {
|
||||
final HttpRequest a = HttpRequest.post("https://hutool.cn/").form("a", 1);
|
||||
Console.log(a.toString());
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
|
||||
@ -125,7 +126,7 @@ public class CsvBaseReader implements Serializable {
|
||||
* @param csvStr CSV字符串
|
||||
* @param rowHandler 行处理器,用于一行一行的处理数据
|
||||
*/
|
||||
public void readFromStr(final String csvStr, final CsvRowHandler rowHandler) {
|
||||
public void readFromStr(final String csvStr, final SerConsumer<CsvRow> rowHandler) {
|
||||
read(parse(new StringReader(csvStr)), rowHandler);
|
||||
}
|
||||
|
||||
@ -242,7 +243,7 @@ public class CsvBaseReader implements Serializable {
|
||||
* @param rowHandler 行处理器,用于一行一行的处理数据
|
||||
* @throws IORuntimeException IO异常
|
||||
*/
|
||||
public void read(final Reader reader, final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
public void read(final Reader reader, final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
read(parse(reader), rowHandler);
|
||||
}
|
||||
|
||||
@ -256,10 +257,10 @@ public class CsvBaseReader implements Serializable {
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.0.4
|
||||
*/
|
||||
private void read(final CsvParser csvParser, final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
private void read(final CsvParser csvParser, final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
try {
|
||||
while (csvParser.hasNext()){
|
||||
rowHandler.handle(csvParser.next());
|
||||
rowHandler.accept(csvParser.next());
|
||||
}
|
||||
} finally {
|
||||
IoUtil.close(csvParser);
|
||||
|
@ -3,6 +3,7 @@ package cn.hutool.poi.csv;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.func.SerConsumer;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.File;
|
||||
@ -120,7 +121,7 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
|
||||
* @throws IORuntimeException IO异常
|
||||
* @since 5.0.4
|
||||
*/
|
||||
public void read(final CsvRowHandler rowHandler) throws IORuntimeException {
|
||||
public void read(final SerConsumer<CsvRow> rowHandler) throws IORuntimeException {
|
||||
read(this.reader, rowHandler);
|
||||
}
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
package cn.hutool.poi.csv;
|
||||
|
||||
/**
|
||||
* CSV的行处理器,实现此接口用于按照行处理数据
|
||||
*
|
||||
* @author Looly
|
||||
* @since 5.0.4
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CsvRowHandler {
|
||||
|
||||
/**
|
||||
* 处理行数据
|
||||
*
|
||||
* @param row 行数据
|
||||
*/
|
||||
void handle(CsvRow row);
|
||||
}
|
@ -2,8 +2,8 @@ package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.poi.excel.cell.CellEditor;
|
||||
import cn.hutool.poi.excel.cell.CellHandler;
|
||||
import cn.hutool.poi.excel.cell.CellUtil;
|
||||
import cn.hutool.poi.excel.reader.BeanSheetReader;
|
||||
import cn.hutool.poi.excel.reader.ColumnSheetReader;
|
||||
@ -252,7 +252,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
* @param cellHandler 单元格处理器,用于处理读到的单元格及其数据
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public void read(final CellHandler cellHandler) {
|
||||
public void read(final SerBiConsumer<Cell, Object> cellHandler) {
|
||||
read(0, Integer.MAX_VALUE, cellHandler);
|
||||
}
|
||||
|
||||
@ -265,7 +265,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
* @param cellHandler 单元格处理器,用于处理读到的单元格及其数据
|
||||
* @since 5.3.8
|
||||
*/
|
||||
public void read(int startRowIndex, int endRowIndex, final CellHandler cellHandler) {
|
||||
public void read(int startRowIndex, int endRowIndex, final SerBiConsumer<Cell, Object> cellHandler) {
|
||||
checkNotClosed();
|
||||
|
||||
startRowIndex = Math.max(startRowIndex, this.sheet.getFirstRowNum());// 读取起始行(包含)
|
||||
@ -280,7 +280,7 @@ public class ExcelReader extends ExcelBase<ExcelReader> {
|
||||
Cell cell;
|
||||
for (short x = 0; x < columnSize; x++) {
|
||||
cell = row.getCell(x);
|
||||
cellHandler.handle(cell, CellUtil.getCellValue(cell));
|
||||
cellHandler.accept(cell, CellUtil.getCellValue(cell));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package cn.hutool.poi.excel.cell;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
|
||||
/**
|
||||
* 单元格处理器接口<br>
|
||||
* 用于在读取Excel单元格值时自定义结果值的获取,如在获取值的同时,获取单元格样式、坐标等信息,或根据单元格信息,装饰转换结果值
|
||||
*
|
||||
* @author Looly
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface CellHandler {
|
||||
|
||||
/**
|
||||
* 处理
|
||||
*
|
||||
* @param cell 单元格对象,可以获取单元格行、列样式等信息
|
||||
* @param value 单元格值
|
||||
*/
|
||||
void handle(Cell cell, Object value);
|
||||
}
|
@ -15,9 +15,13 @@ import java.io.InputStream;
|
||||
*/
|
||||
public interface ExcelSaxReader<T> {
|
||||
|
||||
// sheet r:Id前缀
|
||||
/**
|
||||
* sheet r:Id前缀
|
||||
*/
|
||||
String RID_PREFIX = "rId";
|
||||
// sheet name前缀
|
||||
/**
|
||||
* sheet name前缀
|
||||
*/
|
||||
String SHEET_NAME_PREFIX = "sheetName:";
|
||||
|
||||
/**
|
||||
|
@ -20,6 +20,7 @@ import java.util.List;
|
||||
* <pre>
|
||||
* <sheetData></sheetData>
|
||||
* </pre>
|
||||
*
|
||||
* @since 5.5.3
|
||||
*/
|
||||
public class SheetDataSaxHandler extends DefaultHandler {
|
||||
@ -61,6 +62,11 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
// 存储每行的列元素
|
||||
private List<Object> rowCellList = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param rowHandler 行处理器
|
||||
*/
|
||||
public SheetDataSaxHandler(final RowHandler rowHandler) {
|
||||
this.rowHandler = rowHandler;
|
||||
}
|
||||
|
@ -2,10 +2,11 @@ package cn.hutool.poi.excel;
|
||||
|
||||
import cn.hutool.core.io.resource.ResourceUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import cn.hutool.core.lang.func.SerBiConsumer;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.cell.CellHandler;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@ -231,7 +232,7 @@ public class ExcelReadTest {
|
||||
@Ignore
|
||||
public void readNullRowTest(){
|
||||
final ExcelReader reader = ExcelUtil.getReader("d:/test/1.-.xls");
|
||||
reader.read((CellHandler) Console::log);
|
||||
reader.read((SerBiConsumer<Cell, Object>) Console::log);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user