Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
3cbdfb57
Commit
3cbdfb57
authored
May 11, 2024
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
身份证识别
parent
c0ba6e10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
94 additions
and
4 deletions
+94
-4
MapRow.java
...il-base/src/main/java/com/yanzuoguang/util/vo/MapRow.java
+33
-0
TestMapRow.java
yzg-util-base/src/test/java/base/TestMapRow.java
+61
-4
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/MapRow.java
View file @
3cbdfb57
package
com
.
yanzuoguang
.
util
.
vo
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
/**
* 行映射
...
...
@@ -8,4 +12,33 @@ import java.util.LinkedHashMap;
* @author 颜佐光
*/
public
class
MapRow
extends
LinkedHashMap
<
String
,
Object
>
{
/**
* 删除所有的值,当值等于默认值时
*
* @param rows 行信息
* @param columns 列信息
* @param defaultValues 默认值集合,默认包含空值和空字符串
*/
public
static
<
T
>
void
removeRowColumnOrDefaultValue
(
List
<
MapRow
>
rows
,
List
<
String
>
columns
,
List
<
T
>
defaultValues
)
{
List
<
String
>
removeColumns
=
new
ArrayList
<>();
for
(
String
column
:
columns
)
{
boolean
isDefaultValue
=
true
;
for
(
MapRow
row
:
rows
)
{
Object
value
=
row
.
get
(
column
);
if
(
StringHelper
.
isEmpty
(
value
)
||
defaultValues
.
contains
(
value
))
{
}
else
{
isDefaultValue
=
false
;
}
}
if
(
isDefaultValue
)
{
removeColumns
.
add
(
column
);
}
}
for
(
MapRow
row
:
rows
)
{
for
(
String
removeColumn
:
removeColumns
)
{
row
.
remove
(
removeColumn
);
}
}
}
}
yzg-util-base/src/test/java/base/TestMapRow.java
View file @
3cbdfb57
package
base
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.vo.MapRow
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
TestMapRow
{
@Test
...
...
@@ -17,8 +22,9 @@ public class TestMapRow {
mapRow2
.
put
(
"key1"
,
"value1"
);
mapRow2
.
put
(
"key2"
,
"value2"
);
Assert
.
assertEquals
(
mapRow
,
mapRow2
);
Assert
.
assertEquals
(
mapRow
,
mapRow2
);
}
@Test
public
void
testMapRow2
()
{
MapRow
mapRow
=
new
MapRow
();
...
...
@@ -30,8 +36,9 @@ public class TestMapRow {
mapRow2
.
put
(
"key2"
,
"value2"
);
mapRow2
.
put
(
"key1"
,
"value1"
);
Assert
.
assertEquals
(
mapRow
,
mapRow2
);
Assert
.
assertEquals
(
mapRow
,
mapRow2
);
}
@Test
public
void
testMapRow3
()
{
MapRow
mapRow
=
new
MapRow
();
...
...
@@ -44,8 +51,9 @@ public class TestMapRow {
mapRow2
.
put
(
"key2"
,
"value2"
);
mapRow2
.
put
(
"key1"
,
"value1"
);
Assert
.
assertNotEquals
(
mapRow
,
mapRow2
);
Assert
.
assertNotEquals
(
mapRow
,
mapRow2
);
}
@Test
public
void
testMapRow4
()
{
MapRow
mapRow
=
new
MapRow
();
...
...
@@ -58,6 +66,55 @@ public class TestMapRow {
mapRow2
.
put
(
"key1"
,
"value1"
);
mapRow2
.
put
(
"key3"
,
"value3"
);
Assert
.
assertNotEquals
(
mapRow
,
mapRow2
);
Assert
.
assertNotEquals
(
mapRow
,
mapRow2
);
}
@Test
public
void
testMapRowRemove
()
{
List
<
MapRow
>
list
=
new
ArrayList
<>();
MapRow
mapRow
=
new
MapRow
();
mapRow
.
put
(
"key1"
,
"value1"
);
mapRow
.
put
(
"key2"
,
"value2"
);
mapRow
.
put
(
"key4"
,
""
);
mapRow
.
put
(
"key5"
,
null
);
mapRow
.
put
(
"key6"
,
""
);
mapRow
.
put
(
"key7"
,
null
);
mapRow
.
put
(
"key8"
,
0
);
mapRow
.
put
(
"key9"
,
0
D
);
list
.
add
(
mapRow
);
MapRow
mapRow2
=
new
MapRow
();
mapRow2
.
put
(
"key2"
,
"value2"
);
mapRow2
.
put
(
"key1"
,
"value1"
);
mapRow2
.
put
(
"key3"
,
"value3"
);
mapRow2
.
put
(
"key4"
,
""
);
mapRow2
.
put
(
"key5"
,
null
);
mapRow2
.
put
(
"key6"
,
""
);
mapRow2
.
put
(
"key7"
,
null
);
mapRow2
.
put
(
"key8"
,
0
);
mapRow2
.
put
(
"key9"
,
0
D
);
list
.
add
(
mapRow2
);
MapRow
mapRow3
=
new
MapRow
();
mapRow3
.
put
(
"key1"
,
"value1"
);
mapRow3
.
put
(
"key3"
,
"value3"
);
mapRow3
.
put
(
"key4"
,
""
);
mapRow3
.
put
(
"key5"
,
null
);
mapRow3
.
put
(
"key6"
,
""
);
mapRow3
.
put
(
"key7"
,
null
);
mapRow3
.
put
(
"key8"
,
0
);
mapRow3
.
put
(
"key9"
,
0
D
);
list
.
add
(
mapRow3
);
MapRow
.
removeRowColumnOrDefaultValue
(
list
,
Arrays
.
asList
(
"key1"
,
"key2"
,
"key3"
,
"key4"
,
"key5"
,
"key8"
,
"key9"
),
Arrays
.
asList
(
0
,
0
D
)
);
Assert
.
assertEquals
(
"[{\"key1\":\"value1\",\"key2\":\"value2\",\"key6\":\"\"},{\"key2\":\"value2\",\"key1\":\"value1\",\"key3\":\"value3\",\"key6\":\"\"},{\"key1\":\"value1\",\"key3\":\"value3\",\"key6\":\"\"}]"
,
JsonHelper
.
serialize
(
list
));
}
}
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