public final class Lang
extends java.lang.Object
| 限定符和类型 | 方法和说明 |
|---|---|
static java.lang.Object[] |
array(java.lang.Object... objs)
array.
|
static <T> void |
each(java.util.function.BiConsumer<T,java.lang.Integer> consumer,
T... array)
Each.
|
static <T> void |
each(java.lang.Iterable<T> iterable,
java.util.function.BiConsumer<T,java.lang.Integer> consumer)
Each.
|
static <T> void |
each(T[] array,
java.util.function.BiConsumer<T,java.lang.Integer> consumer)
Each.
|
static boolean |
equals(java.lang.Object target,
java.lang.Object otherTarget)
安全的equals,防止空指针异常 .
|
static java.lang.StackTraceElement |
getInvoker()
获取调用getInvoker方法所在的方法被调用的信息(即调用方法、类等) .
|
static java.lang.StackTraceElement |
getInvoker(int depth)
获取调用getInvoker方法所在的方法被调用的信息(即调用方法、类等) .
|
static java.util.List<java.lang.StackTraceElement> |
getInvokers()
获取调用此方法的调用方法栈 .
|
static int |
hashCode(java.lang.Object o)
返回hash code,如果传入参数为null,返回0.
|
static <O,R extends O> |
ifEmpty(O object,
java.util.function.Supplier<R> empty,
java.util.function.Function<O,R> notEmpty)
判断传入对象是否为空,(String、Collection、Map、Array还要判断长度是否为0),如果为空则执行传入的方法 .
|
static <O,R extends O> |
ifEmpty(O object,
java.util.function.Supplier<R> empty,
java.util.function.Supplier<R> notEmpty)
判断传入对象是否为空,(String、Collection、Map、Array还要判断长度是否为0),如果为空则执行传入的方法 .
|
static void |
ifExists(java.io.File file,
java.util.function.Consumer<java.io.File> consumer)
判断传入文件对象代表的物理文件是否存在,存在则执行传入方法 .
|
static <R> R |
ifExists(java.io.File file,
java.util.function.Function<java.io.File,R> exists,
java.util.function.Function<java.io.File,R> notExists)
判断传入文件对象代表的物理文件是否存在,存在则执行传入方法 .
|
static <R> R |
ifFalse(boolean bool,
java.util.function.Supplier<R> isFalse,
java.util.function.Supplier<R> isTrue)
ifTrue.
|
static <O> void |
ifNotEmpty(O object,
java.util.function.Consumer<O> consumer)
判断传入对象是否不为空,(String、Collection、Map、Array还要判断长度是否为0),如果不为空则执行传入的方法 .
|
static <O,R extends O> |
ifNotEmpty(O object,
java.util.function.Function<O,R> notEmpty,
java.util.function.Supplier<R> empty)
判断传入对象是否不为空,(String、Collection、Map、Array还要判断长度是否为0),如果不为空则执行传入的方法 .
|
static <O,R extends O> |
ifNotEmpty(O object,
java.util.function.Supplier<R> notEmpty,
java.util.function.Supplier<R> empty)
判断传入对象是否不为空,(String、Collection、Map、Array还要判断长度是否为0),如果不为空则执行传入的方法 .
|
static void |
ifNotExists(java.io.File file,
java.util.function.Consumer<java.io.File> consumer)
判断传入文件对象代表的物理文件是否不存在,不存在则执行传入方法 .
|
static <R> R |
ifNotExists(java.io.File file,
java.util.function.Function<java.io.File,R> notExists,
java.util.function.Function<java.io.File,R> exists)
判断传入文件对象代表的物理文件是否不存在,不存在则执行传入方法 .
|
static <R> R |
ifNotExists(java.io.File file,
java.util.function.Supplier<R> supplier)
判断传入文件对象代表的物理文件是否不存在,不存在则执行传入方法 .
|
static <R> R |
ifTrue(boolean bool,
java.util.function.Supplier<R> isTrue,
java.util.function.Supplier<R> isFalse)
ifTrue.
|
static boolean |
isEmpty(java.util.Collection<?> collection)
返回传入集合是否为空(是null或size=0) .
|
static boolean |
isEmpty(java.util.Map<?,?> map)
返回传入map是否为空(是null或size=0) .
|
static boolean |
isEmpty(java.lang.Object object)
返回传入对象是否为空,(String、Collection、Map、Array还要判断长度是否为0) .
|
static boolean |
isEmpty(java.lang.Object[] array)
返回数组是否为空(是null或是空数组) .
|
static boolean |
isEmpty(java.util.Optional<?> optional)
返回传入Optional是否为空(是null或者内部数据为null) .
|
static boolean |
isEmpty(java.lang.String string)
返回传入字符串是否为空(是null或是空字符串) .
|
static boolean |
isExists(java.io.File file)
判断传入文件对象代表的物理文件是否存在 .
|
static boolean |
isNotEmpty(java.util.Collection<?> collection)
返回传入集合是否不为空(不是null或size>0) .
|
static boolean |
isNotEmpty(java.util.Map<?,?> map)
返回传入map是否不为空(不是null或size>0) .
|
static boolean |
isNotEmpty(java.lang.Object object)
返回传入对象是否不为空(String、Collection、Map、Array还要判断长度是否为0) .
|
static boolean |
isNotEmpty(java.lang.Object[] array)
返回数组是否不为空(null或空数组) .
|
static boolean |
isNotEmpty(java.util.Optional<?> optional)
返回传入Optional是否不为空(不是null或者内部数据不为null) .
|
static boolean |
isNotEmpty(java.lang.String string)
返回传入字符串是否不为空(不是null或不是空字符串) .
|
static boolean |
isNotExists(java.io.File file)
判断传入文件对象代表的物理文件是否不存在 .
|
static <E> java.util.List<E> |
list(E... elements)
List.
|
static <T> T |
pick(T target,
java.util.function.Supplier<T> defaultTarget)
如果第一个参数为空(null),返回第二个参数,否则返回第一个参数 .
|
static <T> T |
pick(T target,
T defaultTarget)
如果第一个参数为空(null),返回第二个参数,否则返回第一个参数 .
|
static <T> T |
pickFirst(T... pickedItems)
返回第一个非空的项,!
|
static <T> T |
pickLast(T... pickedItems)
返回最后一个非空的对象,!
|
static <A> A[] |
toArray(java.util.Collection<A> collection)
转换为数组.
|
static <A> A[] |
toArray(java.util.Collection<A> collection,
java.lang.Class<A> type)
转换为数组.
|
static <T extends java.lang.Enum<T>> |
toEnum(java.lang.Class<T> toClass,
java.lang.Object object)
将传入对象转换为枚举 .
|
static <T extends java.lang.Enum<T>> |
toEnum0(java.lang.Class<T> toClass,
java.lang.Object object)
将传入对象转换为枚举 .
|
static <A> java.util.List<A> |
toList(A[] arrays)
转换为列表
.
|
static <A> java.util.Map<java.lang.Integer,A> |
toMap(A[] arrays)
转换为以数组索引为key,数组值为value的map.
|
static <A> java.util.Map<java.lang.String,A> |
toMap2(A[] arrays)
已过时。
use
toMapStringKey(Object...) instead |
static <A> java.util.Map<java.lang.String,A> |
toMapStringKey(A... arrays)
转换为以数组索引为key(string类型),数组值为value的map.
|
static java.lang.String |
toString(java.lang.Object obj)
转换为String,如果不能转换(null)则返回null .
|
static java.lang.String |
toString(java.lang.Object obj,
java.lang.String defaultValue)
转换为String,如果不能转换(null)则使用默认值 .
|
static void |
wrapThrow(java.io.IOException ioException)
Wrap throw.
|
static void |
wrapThrow(java.lang.Throwable throwable)
Wrap throw.
|
static <E extends java.lang.RuntimeException> |
wrapThrow(java.lang.Throwable throwable,
java.lang.Class<E> wrappedRuntimeException)
Wrap throw.
|
public static <T> T pick(T target,
T defaultTarget)
T - 泛型target - 目标参数defaultTarget - 默认值public static <T> T pick(T target,
java.util.function.Supplier<T> defaultTarget)
T - 泛型target - 目标参数defaultTarget - 默认值@SafeVarargs public static <T> T pickFirst(T... pickedItems)
T - 泛型pickedItems - 需要选择的对象@SafeVarargs public static <T> T pickLast(T... pickedItems)
T - 泛型pickedItems - 需要选择的对象public static boolean isEmpty(java.lang.Object object)
object - 传入的对象public static boolean isNotEmpty(java.lang.Object object)
object - 传入的对象public static <R> R ifTrue(boolean bool,
java.util.function.Supplier<R> isTrue,
java.util.function.Supplier<R> isFalse)
R - the generic typebool - boolisTrue - exec when bool is trueisFalse - exec when bool is falsepublic static <R> R ifFalse(boolean bool,
java.util.function.Supplier<R> isFalse,
java.util.function.Supplier<R> isTrue)
R - the generic typebool - boolisFalse - exec when bool is falseisTrue - exec when bool is truepublic static <O,R extends O> R ifEmpty(O object,
java.util.function.Supplier<R> empty,
java.util.function.Supplier<R> notEmpty)
O - the generic typeR - the generic typeobject - 传入的对象empty - exec when emptynotEmpty - exec when not emptypublic static <O,R extends O> R ifEmpty(O object,
java.util.function.Supplier<R> empty,
java.util.function.Function<O,R> notEmpty)
O - the generic typeR - the generic typeobject - 传入的对象empty - exec when emptynotEmpty - exec when not emptypublic static <O> void ifNotEmpty(O object,
java.util.function.Consumer<O> consumer)
O - the generic typeobject - 传入的对象consumer - 需要执行的方法public static <O,R extends O> R ifNotEmpty(O object,
java.util.function.Supplier<R> notEmpty,
java.util.function.Supplier<R> empty)
O - the generic typeR - the generic typeobject - 传入的对象notEmpty - 需要执行的方法empty - the emptypublic static <O,R extends O> R ifNotEmpty(O object,
java.util.function.Function<O,R> notEmpty,
java.util.function.Supplier<R> empty)
O - the generic typeR - the generic typeobject - 传入的对象notEmpty - 需要执行的方法empty - the emptypublic static boolean isEmpty(java.util.Optional<?> optional)
optional - 传入的Optionalpublic static boolean isNotEmpty(java.util.Optional<?> optional)
optional - 传入的Optionalpublic static boolean isEmpty(java.lang.String string)
string - 传入的字符串public static boolean isNotEmpty(java.lang.String string)
string - 传入的字符串public static boolean isEmpty(java.lang.Object[] array)
array - 传入的数组public static boolean isNotEmpty(java.lang.Object[] array)
array - 传入的数组public static boolean isEmpty(java.util.Collection<?> collection)
collection - 传入的集合public static boolean isNotEmpty(java.util.Collection<?> collection)
collection - 传入的集合public static boolean isEmpty(java.util.Map<?,?> map)
map - 传入的mappublic static boolean isNotEmpty(java.util.Map<?,?> map)
map - 传入的mappublic static boolean isExists(java.io.File file)
file - 判断的文件public static boolean isNotExists(java.io.File file)
file - 判断的文件public static void ifExists(java.io.File file,
java.util.function.Consumer<java.io.File> consumer)
file - 判断的文件consumer - 需要执行的方法public static <R> R ifExists(java.io.File file,
java.util.function.Function<java.io.File,R> exists,
java.util.function.Function<java.io.File,R> notExists)
R - the generic typefile - 判断的文件exists - exec when existsnotExists - exec when not existspublic static void ifNotExists(java.io.File file,
java.util.function.Consumer<java.io.File> consumer)
file - 判断的文件consumer - 需要执行的方法public static <R> R ifNotExists(java.io.File file,
java.util.function.Function<java.io.File,R> notExists,
java.util.function.Function<java.io.File,R> exists)
R - the generic typefile - 判断的文件notExists - exec when not existsexists - exec when existspublic static <R> R ifNotExists(java.io.File file,
java.util.function.Supplier<R> supplier)
R - the generic typefile - 判断的文件supplier - 需要执行的方法public static <T extends java.lang.Enum<T>> T toEnum(java.lang.Class<T> toClass,
java.lang.Object object)
T - 泛型toClass - 枚举的类型object - 需要转换的对象public static <T extends java.lang.Enum<T>> T toEnum0(java.lang.Class<T> toClass,
java.lang.Object object)
T - 泛型toClass - 枚举的类型object - 需要转换的对象public static boolean equals(java.lang.Object target,
java.lang.Object otherTarget)
target - 比较对象otherTarget - 另一个比较对象public static int hashCode(java.lang.Object o)
o - 对象Object.hashCode()public static java.lang.String toString(java.lang.Object obj,
java.lang.String defaultValue)
obj - objdefaultValue - defaultValuepublic static java.lang.String toString(java.lang.Object obj)
obj - objpublic static java.lang.StackTraceElement getInvoker()
public static java.lang.StackTraceElement getInvoker(int depth)
depth - the depthpublic static java.util.List<java.lang.StackTraceElement> getInvokers()
public static <A> A[] toArray(java.util.Collection<A> collection)
A - 泛型collection - 集合public static <A> A[] toArray(java.util.Collection<A> collection,
java.lang.Class<A> type)
转换为数组. 如果传入集合为空(null或者size=0),返回长度为0的数组(不会返回null).
A - 泛型collection - 集合type - 类型public static <A> java.util.List<A> toList(A[] arrays)
转换为列表
.A - the generic typearrays - 数组public static <A> java.util.Map<java.lang.Integer,A> toMap(A[] arrays)
A - the generic typearrays - 数组@Deprecated public static <A> java.util.Map<java.lang.String,A> toMap2(A[] arrays)
toMapStringKey(Object...) insteadA - the generic typearrays - 数组public static <A> java.util.Map<java.lang.String,A> toMapStringKey(A... arrays)
A - the generic typearrays - 数组public static void wrapThrow(java.lang.Throwable throwable)
throwable - the throwablepublic static void wrapThrow(java.io.IOException ioException)
ioException - the io exceptionpublic static <E extends java.lang.RuntimeException> void wrapThrow(java.lang.Throwable throwable,
java.lang.Class<E> wrappedRuntimeException)
E - the element typethrowable - the throwablewrappedRuntimeException - the wrapped runtime exceptionpublic static <T> void each(T[] array,
java.util.function.BiConsumer<T,java.lang.Integer> consumer)
T - the generic typearray - the arrayconsumer - the consumerpublic static <T> void each(java.util.function.BiConsumer<T,java.lang.Integer> consumer,
T... array)
T - the generic typeconsumer - the consumerarray - the arraypublic static <T> void each(java.lang.Iterable<T> iterable,
java.util.function.BiConsumer<T,java.lang.Integer> consumer)
T - the generic typeiterable - the iterableconsumer - the consumerpublic static java.lang.Object[] array(java.lang.Object... objs)
objs - the objspublic static <E> java.util.List<E> list(E... elements)
E - the element typeelements - the elements