public class FormatUtil extends Object
a thread-safe and low memory-fragmentation formatter, can handle
- `{}` in slf4j
- `%` in printf
- `{0}` in Message
| 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)
Count string occurrences
|
static @NotNull Object[] |
fixArgs(int size,
Object... args)
Completing and padding null parameters with empty string
|
static @NotNull String |
format(CharSequence fmt,
Object... args)
handle `%` in printf,Involves copying arrays, with a small performance loss.
|
static @NotNull String |
join(boolean skipNull,
String joiner,
Iterable<?> objs) |
static @NotNull String |
leftFix(@Nullable Object obj,
int fix,
char pad)
Left padding or left truncation to ensure fixed length
|
static @NotNull String |
logback(CharSequence fmt,
Object... args)
handle `{}` slf4j's placeholder, eg.
|
static String |
message(CharSequence fmt,
Object... args)
handle `{0}` in MessageFormat, auto completes the parameter with empty string.
|
static @NotNull String |
rightFix(@Nullable Object obj,
int fix,
char pad)
Right padding or right truncation to ensure fixed length
|
static @NotNull String |
sortParam(@NotNull Map<?,?> params)
use `&` and `=` sort and join the string as http query string, sort by ascii asc
|
static @NotNull String |
sortParam(@NotNull Map<?,?> param,
@NotNull String join1,
@NotNull String join2)
use `join1` and `join2` sort and join the string as http query string.
|
static @NotNull String |
toString(boolean[] arr) |
static @NotNull String |
toString(double[] arr) |
static @NotNull String |
toString(float[] arr) |
static @NotNull String |
toString(int[] arr) |
static @NotNull String |
toString(long[] arr) |
static @NotNull String |
toString(short[] arr) |
static void |
toString(StringBuilder buff,
boolean[] arr) |
static void |
toString(StringBuilder buff,
double[] arr) |
static void |
toString(StringBuilder buff,
float[] arr) |
static void |
toString(StringBuilder buff,
int[] arr) |
static void |
toString(StringBuilder buff,
long[] arr) |
static void |
toString(StringBuilder buff,
short[] arr) |
@NotNull public static @NotNull String sortParam(@NotNull @NotNull Map<?,?> params)
use `&` and `=` sort and join the string as http query string, sort by ascii asc
sortParam(Map, String, String)@NotNull public static @NotNull String sortParam(@NotNull @NotNull Map<?,?> param, @NotNull @NotNull String join1, @NotNull @NotNull String join2)
use `join1` and `join2` sort and join the string as http query string. sort by ascii asc by default, ignore param is its key is null.
@NotNull public static @NotNull String logback(CharSequence fmt, Object... args)
handle `{}` slf4j's placeholder, eg.
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"
public static String message(CharSequence fmt, Object... args)
MessageFormat@NotNull public static @NotNull String format(CharSequence fmt, Object... args)
handle `%` in printf,Involves copying arrays, with a small performance loss. Thread-safe, auto-complete String#format. A more elegant format suggests using java.text.MessageFormat.
Formatter,
String.format(String, Object...)@NotNull public static @NotNull Object[] fixArgs(int size, Object... args)
@NotNull public static @NotNull String leftFix(@Nullable @Nullable Object obj, int fix, char pad)
obj - the objectfix - the fixed lengthpad - padding char@NotNull public static @NotNull String rightFix(@Nullable @Nullable Object obj, int fix, char pad)
obj - the objectfix - the fixed lengthpad - padding charpublic 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 - callbacksrc - sourcesub - substring to count@NotNull public static @NotNull String toString(boolean[] arr)
public static void toString(StringBuilder buff, boolean[] arr)
@NotNull public static @NotNull String toString(short[] arr)
public static void toString(StringBuilder buff, short[] arr)
@NotNull public static @NotNull String toString(int[] arr)
public static void toString(StringBuilder buff, int[] arr)
@NotNull public static @NotNull String toString(long[] arr)
public static void toString(StringBuilder buff, long[] arr)
@NotNull public static @NotNull String toString(float[] arr)
public static void toString(StringBuilder buff, float[] arr)
@NotNull public static @NotNull String toString(double[] arr)
public static void toString(StringBuilder buff, double[] arr)
Copyright © 2024. All rights reserved.