public final class DataUtil extends Object
集合元素处理工具
该工具的主要目标是在不发生NPE的前提下对集合以及集合里的元素进行操作,其具备以下的几项功能该工具是一个线程安全类的工具
Constructor and Description |
---|
DataUtil() |
Modifier and Type | Method and Description |
---|---|
static <T> List<T> |
asList(T... a)
将指定的数据转换成list
|
static <T> Set<T> |
asSet(T... a)
将指定的数据转换成Set
|
static <T> T |
first(Collection<T> data)
取出集合里的第一个元素,若集合为空则返回为null
|
static <T> T |
first(Collection<T> data,
String errorMsg)
取出集合的第一个元素,若集合为空则抛出异常
|
static <T> T |
first(Collection<T> data,
T defaultValue)
取出集合的第一个元素, 若集合为空则返回给定的缺省值
|
static <T> T |
first(List<T> data)
取出List中的第一个非空元素,如果Stream为空则返回null
|
static <T> T |
first(List<T> data,
String errorMsg)
取出链表的第一个元素,若链表为空则抛出异常
|
static <T> T |
first(List<T> data,
T defaultValue)
取出链表的第一个元素, 若链表为空则返回给定的缺省值
|
static <T> T |
first(Set<T> data)
取出Set中的第一个非空元素,如果Stream为空则返回null
|
static <T> T |
first(Set<T> data,
String errorMsg)
取出Set的第一个元素,若Set为空则抛出异常
|
static <T> T |
first(Set<T> data,
T defaultValue)
取出Set的第一个元素, 若Set为空则返回给定的缺省值
|
static <T> T |
first(Stream<T> data)
取出Stream中的第一个非空元素,如果Stream为空则返回null
|
static <T> T |
first(T[] data)
取出数组的第一个元素, 若数组为空则返回null
|
static <T> T |
first(T[] data,
String errorMsg)
取出数组的第一个元素,若数组为空则抛出异常
|
static <T> T |
first(T[] data,
T defaultValue)
取出数组的第一个元素, 若数组为空则返回给定的缺省值
|
static <T> Stream<T> |
parallelStream(List<T> list)
将数据安全地转换成并行流Stream
|
static <T> Stream<T> |
parallelStream(List<T> list,
String msg)
将数据安全地转换成并行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> Stream<T> |
parallelStream(Set<T> set)
将数据安全地转换成并行流Stream
|
static <T> Stream<T> |
parallelStream(Set<T> set,
String msg)
将数据安全地转换成并行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> Stream<T> |
parallelStream(T[] data)
将数据安全地转换成并行流Stream
|
static <T> Stream<T> |
parallelStream(T[] data,
String msg)
将数据安全地转换成并行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> Stream<T> |
stream(List<T> list)
将数据安全地转换成串行流Stream
|
static <T> Stream<T> |
stream(List<T> list,
String msg)
将数据安全地转换成串行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> Stream<T> |
stream(Set<T> set)
将数据安全地转换成串行流Stream
|
static <T> Stream<T> |
stream(Set<T> set,
String msg)
将数据安全地转换成串行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> Stream<T> |
stream(T[] data)
将数据安全地转换成串行流Stream
|
static <T> Stream<T> |
stream(T[] data,
String msg)
将数据安全地转换成串行流Stream,并检查输入的数据,若输入的数据源为空就抛出异常
|
static <T> List<T> |
toList(T[] objs)
将数组转换成List
|
static <T> Set<T> |
toSet(T[] objs)
将数组转换成Set
|
public static <T> Stream<T> stream(List<T> list)
T
- 集合里数据的类型list
- 需要转换的集合数据public static <T> Stream<T> stream(List<T> list, String msg) throws ValidateException
T
- 集合里数据的类型list
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> Stream<T> stream(Set<T> set)
T
- 集合里数据的类型set
- 需要转换的集合数据public static <T> Stream<T> stream(Set<T> set, String msg) throws ValidateException
T
- 集合里数据的类型set
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> Stream<T> stream(T[] data)
T
- 集合里数据的类型data
- 需要转换的集合数据public static <T> Stream<T> stream(T[] data, String msg) throws ValidateException
T
- 集合里数据的类型data
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> Stream<T> parallelStream(List<T> list)
T
- 集合里数据的类型list
- 需要转换的集合数据public static <T> Stream<T> parallelStream(List<T> list, String msg) throws ValidateException
T
- 集合里数据的类型list
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> Stream<T> parallelStream(Set<T> set)
T
- 集合里数据的类型set
- 需要转换的集合数据public static <T> Stream<T> parallelStream(Set<T> set, String msg) throws ValidateException
T
- 集合里数据的类型set
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> Stream<T> parallelStream(T[] data)
T
- 集合里数据的类型data
- 需要转换的集合数据public static <T> Stream<T> parallelStream(T[] data, String msg) throws ValidateException
T
- 集合里数据的类型data
- 需要转换的集合数据msg
- 异常提示信息ValidateException
- 输入的数据源为空public static <T> List<T> toList(T[] objs)
T
- 数组里元素的类型objs
- 需要转换的数据public static <T> Set<T> toSet(T[] objs)
T
- 数组里元素的类型objs
- 需要转换的数据public static <T> T first(Stream<T> data)
T
- 数据流里的数据的类型data
- 数据流public static <T> T first(List<T> data)
T
- List里的数据的类型data
- 链表public static <T> T first(List<T> data, T defaultValue)
T
- List里的数据的类型data
- 链表defaultValue
- 缺省值public static <T> T first(List<T> data, String errorMsg) throws DataException
T
- List里的数据的类型data
- 链表数据errorMsg
- 异常提示信息DataException
- 链表为空public static <T> T first(Set<T> data)
T
- Set里的数据的类型data
- 输入的数据public static <T> T first(Set<T> data, T defaultValue)
T
- List里的数据的类型data
- 数据源defaultValue
- 缺省值public static <T> T first(Set<T> data, String errorMsg) throws DataException
T
- Set里的数据的类型data
- 数据源errorMsg
- 异常提示信息DataException
- Set为空public static <T> T first(T[] data)
T
- 数组里数据的类型data
- 数据源public static <T> T first(T[] data, T defaultValue)
T
- 数组里的数据的类型data
- 数据源defaultValue
- 缺省值public static <T> T first(T[] data, String errorMsg) throws DataException
T
- 数组里的数据的类型data
- 数据源errorMsg
- 异常提示信息DataException
- 数组为空public static <T> T first(Collection<T> data)
T
- 集合里元素的类型data
- 数据源public static <T> T first(Collection<T> data, T defaultValue)
T
- 集合里的数据的类型data
- 数据源defaultValue
- 缺省值public static <T> T first(Collection<T> data, String errorMsg) throws DataException
T
- 集合里的数据的类型data
- 数据源errorMsg
- 异常提示信息DataException
- 集合为空@SafeVarargs public static <T> List<T> asList(T... a)
T
- 数据类型a
- 需要转换的数据@SafeVarargs public static <T> Set<T> asSet(T... a)
T
- 数据类型a
- 需要转换的数据Copyright © 2021. All rights reserved.