public class FormatUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
FormatUtil.V |
| Constructor and Description |
|---|
FormatUtil() |
| Modifier and Type | Method and Description |
|---|---|
static int[] |
count(CharSequence src,
String... sub) |
static int |
count(CharSequence src,
String sub) |
static int[] |
count(FormatUtil.V viz,
CharSequence src,
String... sub)
统计字符窜出现次数
|
static @NotNull String |
format(CharSequence fmt,
Object... args)
处理 printf的`%`占位符
安全的,自动补全的 String#format
|
static @NotNull String |
leftFix(@Nullable Object obj,
int fix,
char pad)
左填充或左截断,保证固定位数
|
static @NotNull String |
logback(CharSequence fmt,
Object... args)
处理slf4j的 `{}`占位符
|
static @NotNull String |
rightFix(@Nullable Object obj,
int fix,
char pad)
右填充或右截断,保证固定位数
|
@NotNull public static @NotNull String logback(CharSequence fmt, Object... args)
format(null, new Object[]{"a"}) return ""
format("{} {} {a}", null) return "{null} {null} {a}"
format("{} {} {a}", new Object[]{"b"}) return "{b} {null} {a}"
format("{} {} {a}", new Object[]{"b", "c", "d"}) return "{b} {c} {a}"
format("abc", new Object[]{"a"}) return "abc"
format("{{}}", new Object[]{"a"}) return "{a}"
format("\\{\\}", new Object[]{"a"}) return "{}"
format("\\{}", new Object[]{"a"}) return "{}"
format("\\\\", new Object[]{"a"}) return "\"
format("{c", new Object[]{"a"}) return "{c"
fmt - 格式args - 参数@NotNull public static @NotNull String format(CharSequence fmt, Object... args)
fmt - 格式args - 参数Formatter,
String.format(String, Object...)@NotNull public static @NotNull String leftFix(@Nullable @Nullable Object obj, int fix, char pad)
obj - 对象fix - 固定位数pad - 填充字符@NotNull public static @NotNull String rightFix(@Nullable @Nullable Object obj, int fix, char pad)
obj - 对象fix - 固定位数pad - 填充字符public static int count(CharSequence src, String sub)
public static int[] count(CharSequence src, String... sub)
public static int[] count(FormatUtil.V viz, CharSequence src, String... sub)
viz - 回调src - 源sub - 目标Copyright © 2020. All rights reserved.