-
Notifications
You must be signed in to change notification settings - Fork 14
/
CollectionUtils.kt
72 lines (68 loc) · 1.6 KB
/
CollectionUtils.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.excellence.basetoolslibrary.utils
/**
* <pre>
* author : VeiZhang
* blog : http://tiimor.cn
* time : 2022/4/6
* desc :
* </pre>
*/
object CollectionUtils {
/**
* 清空集合里的空元素
*/
@JvmStatic
fun removeEmptyElement(collection: MutableCollection<*>) {
collection.remove(null)
}
/**
* 比较两个列表元素对象是否一致
*
* @param list1
* @param list2
* @return
*/
@JvmStatic
fun listEquals(list1: List<*>?, list2: List<*>?): Boolean {
if (list1 == null && list2 == null) {
return true
} else if (list1 == null || list2 == null) {
return false
}
if (list1.size != list2.size) {
return false
} else {
for (i in list1.indices) {
if (list1[i] !== list2[i]) {
return false
}
}
}
return true
}
/**
* 比较两个列表元素内容是否一致
*
* @param list1
* @param list2
* @return
*/
@JvmStatic
fun listContentEquals(list1: List<*>?, list2: List<*>?): Boolean {
if (list1 == null && list2 == null) {
return true
} else if (list1 == null || list2 == null) {
return false
}
if (list1.size != list2.size) {
return false
} else {
for (i in list1.indices) {
if (list1[i] != list2[i]) {
return false
}
}
}
return true
}
}