Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
8
8timerapiv200
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
8timerv2
8timerapiv200
Commits
bfa2bc85
Commit
bfa2bc85
authored
May 22, 2020
by
邓实川
Committed by
chenzg
Jul 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工具类,检查对象是否有空字段,list交集 差集 并集
parent
7bd19d22
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
0 deletions
+65
-0
src/main/java/cn/timer/api/utils/CheckUtil.java
+65
-0
No files found.
src/main/java/cn/timer/api/utils/CheckUtil.java
View file @
bfa2bc85
...
...
@@ -8,6 +8,8 @@
package
cn
.
timer
.
api
.
utils
;
import
java.lang.reflect.Field
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
* <p>
...
...
@@ -23,6 +25,12 @@ import java.lang.reflect.Field;
*/
public
class
CheckUtil
{
/**
* 检查对象是否有空字段
*
* @param obj 实体对象
* @return 有则返回true
*/
public
static
boolean
checkObjFieldIsNull
(
Object
obj
)
{
boolean
flag
=
false
;
for
(
Field
f
:
obj
.
getClass
().
getDeclaredFields
())
{
...
...
@@ -39,4 +47,61 @@ public class CheckUtil {
return
flag
;
}
/**
* 交集
*
* @param <T>
* @param list1
* @param list2
* @return list1与list2中相同的字段list
*/
public
static
<
T
>
List
<
T
>
intersection
(
List
<
T
>
list1
,
List
<
T
>
list2
)
{
return
list1
.
stream
().
filter
(
item
->
list2
.
contains
(
item
)).
collect
(
Collectors
.
toList
());
}
/**
* 列表取差集
*
* @param <T>
* @param list1
* @param list2
* @return list2中未包含list1的参数list
*/
public
static
<
T
>
List
<
T
>
reduce
(
List
<
T
>
list1
,
List
<
T
>
list2
)
{
return
list1
.
stream
().
filter
(
item
->
!
list2
.
contains
(
item
)).
collect
(
Collectors
.
toList
());
}
/**
* 并集
*
* @param <T>
* @param list1
* @param list2
* @param isDistinct 是否去重
* @return
*/
public
static
<
T
>
List
<
T
>
distinct
(
List
<
T
>
list1
,
List
<
T
>
list2
,
boolean
isDistinct
)
{
list1
.
addAll
(
list2
);
if
(!
isDistinct
)
return
list1
;
return
list1
.
stream
().
distinct
().
collect
(
Collectors
.
toList
());
}
// public static void main(String[] args) {
// List<String> list1 = new ArrayList<String>();
// list1.add("a");
// list1.add("b");
// list1.add("c");
// list1.add("d");
// list1.add("3");
// List<String> list2 = new ArrayList<String>();
// list2.add("a");
// list2.add("b");
// list2.add("e");
// list2.add("3");
// System.err.println(intersection(list1, list2));
// System.err.println(reduce(list1, list2));
// System.err.println(distinct(list1, list2, false));
// }
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment