Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jan 25, 2016
1 parent 5bbcf3f commit c1c1624
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ public static void generate(List<HashMap<String, Object>> data,
for (Map<String, Object> objects : data) {
List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 16 additions & 5 deletions src/test/java/cn/binarywang/tools/generator/SomethingTest.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
package cn.binarywang.tools.generator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.google.common.base.Splitter;
import com.google.common.collect.Lists;

public class SomethingTest {

@Test
public void test() {
//(0:未知;1:本人;2:单位;3:配偶;4:子女;5:父母;6:兄弟姐妹;7:其他亲属;8:朋友;9:同事)

List<String> relavtives = Lists.newArrayList("MOTHER", "FATHER",
"SPOUSE", "OTHER");
List<String> 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);
Map<String, String> relativeMap = Splitter.on(",")
.withKeyValueSeparator("=").split("MOTHER=5,FATHER=5,SPOUSE=3");

//[@"其他亲属", @"单位", @"子女", @"兄弟姐妹", @"朋友", @"同事"]
List<String> otherRelations = Lists.newArrayList("2", "4", "6", "7",
"8", "9");
List<String> 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) {
Expand Down

0 comments on commit c1c1624

Please sign in to comment.