Commit 3cbdfb57 authored by yanzg's avatar yanzg

身份证识别

parent c0ba6e10
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);
}
}
}
}
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", 0D);
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", 0D);
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", 0D);
list.add(mapRow3);
MapRow.removeRowColumnOrDefaultValue(list,
Arrays.asList("key1", "key2", "key3", "key4", "key5", "key8", "key9"),
Arrays.asList(0, 0D)
);
Assert.assertEquals("[{\"key1\":\"value1\",\"key2\":\"value2\",\"key6\":\"\"},{\"key2\":\"value2\",\"key1\":\"value1\",\"key3\":\"value3\",\"key6\":\"\"},{\"key1\":\"value1\",\"key3\":\"value3\",\"key6\":\"\"}]",
JsonHelper.serialize(list));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment