diff --git a/src/main/java/cn/binarywang/tools/generator/CSVFileGenerator.java b/src/main/java/cn/binarywang/tools/generator/CSVFileGenerator.java index 219ea47..88631b7 100644 --- a/src/main/java/cn/binarywang/tools/generator/CSVFileGenerator.java +++ b/src/main/java/cn/binarywang/tools/generator/CSVFileGenerator.java @@ -29,7 +29,11 @@ public static void generate(List> data, for (Map objects : data) { List result = Lists.newArrayList(); for (String column : columns) { - result.add(objects.get(column).toString()); + if (objects.get(column) != null) { + result.add(objects.get(column).toString()); + } else { + result.add(""); + } } String lineData = Joiner.on(",").skipNulls().join(result); diff --git a/src/main/java/cn/binarywang/tools/generator/ChineseNameGenerator.java b/src/main/java/cn/binarywang/tools/generator/ChineseNameGenerator.java index 3e963e3..779ad37 100644 --- a/src/main/java/cn/binarywang/tools/generator/ChineseNameGenerator.java +++ b/src/main/java/cn/binarywang/tools/generator/ChineseNameGenerator.java @@ -5,18 +5,25 @@ public class ChineseNameGenerator { private static final String[] FIRST_NAMES = new String[] { "李", "王", "张", - "刘", "陈", "杨", "黄", "赵", - "周", "吴", "徐", "孙", "朱", "马", "胡", "郭", "林", "何", "高", "梁", "郑", "罗", - "宋", "谢", "唐", "韩", "曹", "许", "邓", "萧", "冯", "曾", "程", "蔡", "彭", "潘", - "袁", "於", "董", "余", "苏", "叶", "吕", "魏", "蒋", "田", "杜", "丁", "沈", "姜", - "范", "江", "傅", "钟", "卢", "汪", "戴", "崔", "任", "陆", "廖", "姚", "方", "金", - "邱", "夏", "谭", "韦", "贾", "邹", "石", "熊", "孟", "秦", "阎", "薛", "侯", "雷", - "白", "龙", "段", "郝", "孔", "邵", "史", "毛", "常", "万", "顾", "赖", "武", "康", - "贺", "严", "尹", "钱", "施", "牛", "洪", "龚" }; + "刘", "陈", "杨", "黄", "赵", "周", "吴", "徐", "孙", "朱", "马", "胡", "郭", "林", + "何", "高", "梁", "郑", "罗", "宋", "谢", "唐", "韩", "曹", "许", "邓", "萧", "冯", + "曾", "程", "蔡", "彭", "潘", "袁", "於", "董", "余", "苏", "叶", "吕", "魏", "蒋", + "田", "杜", "丁", "沈", "姜", "范", "江", "傅", "钟", "卢", "汪", "戴", "崔", "任", + "陆", "廖", "姚", "方", "金", "邱", "夏", "谭", "韦", "贾", "邹", "石", "熊", "孟", + "秦", "阎", "薛", "侯", "雷", "白", "龙", "段", "郝", "孔", "邵", "史", "毛", "常", + "万", "顾", "赖", "武", "康", "贺", "严", "尹", "钱", "施", "牛", "洪", "龚", "欧阳", + "太史", "端木", "上官", "司马", "东方", "独孤", "南宫", "万俟", "闻人", "夏侯", "诸葛", "尉迟", + "公羊", "赫连", "澹台", "皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容", "仲孙", + "钟离", "长孙", "宇文", "司徒", "鲜于", "司空", "闾丘", "子车", "亓官", "司寇", "巫马", "公西", + "颛孙", "壤驷", "公良", "漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐", "段干", + "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户", "公玉", "公仪", "梁丘", "公仲", "公上", + "公门", "公山", "公坚", "左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙", "南荣", + "东里", "东宫", "仲长", "子书", "子桑", "即墨", "达奚", "褚师", "吴铭" }; public static String generate() { + //姓名暂时还是两到三字,比较常见些 return genFirstName() - + ChineseCharUtils.genRandomLengthChineseChars(1, 14); + + ChineseCharUtils.genRandomLengthChineseChars(1, 2); } private static String genFirstName() { diff --git a/src/test/java/cn/binarywang/tools/generator/SomethingTest.java b/src/test/java/cn/binarywang/tools/generator/SomethingTest.java index d2b1f83..37cfee7 100644 --- a/src/test/java/cn/binarywang/tools/generator/SomethingTest.java +++ b/src/test/java/cn/binarywang/tools/generator/SomethingTest.java @@ -1,5 +1,6 @@ package cn.binarywang.tools.generator; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; @@ -7,7 +8,6 @@ import org.junit.Test; import com.google.common.base.Splitter; -import com.google.common.collect.Lists; public class SomethingTest { @@ -15,8 +15,13 @@ public class SomethingTest { public void test() { //(0:未知;1:本人;2:单位;3:配偶;4:子女;5:父母;6:兄弟姐妹;7:其他亲属;8:朋友;9:同事) - List relavtives = Lists.newArrayList("MOTHER", "FATHER", - "SPOUSE", "OTHER"); + List relavtives = new ArrayList<>(); + relavtives.add("MOTHER"); + relavtives.add("FATHER"); + relavtives.add("SPOUSE"); + relavtives.add("OTHER"); + + //Arrays.asList("MOTHER", "FATHER", "SPOUSE", "OTHER"); Collections.shuffle(relavtives); System.err.println(relavtives); @@ -24,8 +29,14 @@ public void test() { .withKeyValueSeparator("=").split("MOTHER=5,FATHER=5,SPOUSE=3"); //[@"其他亲属", @"单位", @"子女", @"兄弟姐妹", @"朋友", @"同事"] - List otherRelations = Lists.newArrayList("2", "4", "6", "7", - "8", "9"); + List otherRelations = new ArrayList<>(); + //Arrays.asList("2", "4", "6", "7", "8","9"); + otherRelations.add("2"); + otherRelations.add("4"); + otherRelations.add("6"); + otherRelations.add("7"); + otherRelations.add("8"); + otherRelations.add("9"); Collections.shuffle(otherRelations); for (String string : relavtives) {