mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
BetweenFormatter支持自定义设置单位
This commit is contained in:
parent
d556f5b62f
commit
51c1588081
@ -10,6 +10,7 @@
|
|||||||
* 【core 】 CollUtil.subtract增加空判定(issue#3605@Github)
|
* 【core 】 CollUtil.subtract增加空判定(issue#3605@Github)
|
||||||
* 【core 】 优化DateUtil.format(Date date, String format)接口效率(pr#1226@Gitee)
|
* 【core 】 优化DateUtil.format(Date date, String format)接口效率(pr#1226@Gitee)
|
||||||
* 【csv 】 CsvWriter.writeBeans增加重载,可选是否写出表头(issue#IA57W2@Gitee)
|
* 【csv 】 CsvWriter.writeBeans增加重载,可选是否写出表头(issue#IA57W2@Gitee)
|
||||||
|
* 【core 】 BetweenFormatter支持自定义设置单位(pr#1228@Gitee)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【core 】 修复AnnotationUtil可能的空指针错误
|
* 【core 】 修复AnnotationUtil可能的空指针错误
|
||||||
|
@ -19,10 +19,6 @@ import java.util.function.Function;
|
|||||||
public class BetweenFormatter implements Serializable {
|
public class BetweenFormatter implements Serializable {
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
|
||||||
* 单位格式化器
|
|
||||||
*/
|
|
||||||
public static Function<Level, String> DEFAULT_LEVEL_FORMATTER = (level) -> level.name;
|
|
||||||
/**
|
/**
|
||||||
* 时长毫秒数
|
* 时长毫秒数
|
||||||
*/
|
*/
|
||||||
@ -38,7 +34,7 @@ public class BetweenFormatter implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 格式化器
|
* 格式化器
|
||||||
*/
|
*/
|
||||||
private Function<Level, String> levelFormatter = DEFAULT_LEVEL_FORMATTER;
|
private Function<Level, String> levelFormatter = Level::getName;
|
||||||
/**
|
/**
|
||||||
* 分隔符
|
* 分隔符
|
||||||
*/
|
*/
|
||||||
@ -86,7 +82,7 @@ public class BetweenFormatter implements Serializable {
|
|||||||
final int level = this.level.ordinal();
|
final int level = this.level.ordinal();
|
||||||
int levelCount = 0;
|
int levelCount = 0;
|
||||||
|
|
||||||
if (isLevelCountValid(levelCount) && 0 != day && level >= Level.DAY.ordinal()) {
|
if (isLevelCountValid(levelCount) && day > 0) {
|
||||||
sb.append(day).append(levelFormatter.apply(Level.DAY)).append(separator);
|
sb.append(day).append(levelFormatter.apply(Level.DAY)).append(separator);
|
||||||
levelCount++;
|
levelCount++;
|
||||||
}
|
}
|
||||||
@ -172,7 +168,7 @@ public class BetweenFormatter implements Serializable {
|
|||||||
* @return this
|
* @return this
|
||||||
*/
|
*/
|
||||||
public BetweenFormatter setSeparator(String separator) {
|
public BetweenFormatter setSeparator(String separator) {
|
||||||
this.separator = separator == null ? StrUtil.EMPTY : separator;
|
this.separator = StrUtil.nullToEmpty(separator);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user