Skip to content

Commit 359c4ef

Browse files
author
yindz
authored
Merge pull request #73 from yindz/v1.0.21
V1.0.21
2 parents 34f0c6d + 843ace1 commit 359c4ef

File tree

8 files changed

+1220
-976
lines changed

8 files changed

+1220
-976
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.apifan.common</groupId>
88
<artifactId>common-random</artifactId>
9-
<version>1.0.20</version>
9+
<version>1.0.21</version>
1010
<packaging>jar</packaging>
1111
<name>common-random</name>
1212
<description>An easy-to-use random data generator.</description>

src/main/java/com/apifan/common/random/source/AreaSource.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.apifan.common.random.entity.Area;
55
import com.apifan.common.random.entity.CountryOrRegionCode;
66
import com.apifan.common.random.util.ResourceUtils;
7+
import com.google.common.base.Joiner;
78
import com.google.common.base.Preconditions;
89
import com.google.common.base.Splitter;
910
import com.google.common.collect.Lists;
@@ -251,7 +252,7 @@ public String randomPhoneNumber(String province, String delimiter) {
251252
* @return 随机的国家或地区编码信息
252253
*/
253254
public CountryOrRegionCode randomCountryOrRegionCode(String startsWith) {
254-
Preconditions.checkArgument(ALPHA_1.matcher(startsWith).matches(), "startsWith 必须为单个字母");
255+
Preconditions.checkArgument(ALPHA_1.matcher(startsWith).matches(), "首字母必须为单个字母");
255256
List<CountryOrRegionCode> filteredList = countryOrRegionCodeList.stream()
256257
.filter(i -> i.getAlpha2().startsWith(startsWith.toUpperCase()) || i.getAlpha3().startsWith(startsWith.toUpperCase())).collect(Collectors.toList());
257258
return randomCountryOrRegionCode(filteredList);
@@ -266,6 +267,34 @@ public CountryOrRegionCode randomCountryOrRegionCode() {
266267
return randomCountryOrRegionCode(countryOrRegionCodeList);
267268
}
268269

270+
/**
271+
* 随机虚构省份名称
272+
*
273+
* @return 虚构省份名称
274+
*/
275+
public String randomFictionalProvince() {
276+
return Joiner.on("").join(ResourceUtils.getRandomElement(addressWordList, 2)) + "省";
277+
}
278+
279+
/**
280+
* 随机虚构城市名称
281+
*
282+
* @return 虚构城市名称
283+
*/
284+
public String randomFictionalCity() {
285+
return Joiner.on("").join(ResourceUtils.getRandomElement(addressWordList, 2)) + "市";
286+
}
287+
288+
/**
289+
* 随机虚构地址
290+
*
291+
* @return 虚构地址
292+
*/
293+
public String randomFictionalAddress() {
294+
String road = ResourceUtils.getRandomString(addressWordList, 2) + ResourceUtils.getRandomElement(directionList);
295+
return randomFictionalProvince() + randomFictionalCity() + road + "路" + RandomUtils.nextInt(1, 1000) + "号";
296+
}
297+
269298
/**
270299
* 返回随机的国家或地区编码信息
271300
*

src/main/java/com/apifan/common/random/source/OtherSource.java

+49-11
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public class OtherSource {
9898
private static final List<String> socialCreditCharactersList = Lists.newArrayList(
9999
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "T", "U", "W", "X", "Y");
100100

101+
/**
102+
* 文件后缀
103+
*/
104+
private static final List<String> fileSuffixList = Lists.newArrayList("txt", "pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "wps", "et", "zip", "rar", "7z", "png", "jpg", "tar");
105+
101106
private static final OtherSource instance = new OtherSource();
102107

103108
private OtherSource() {
@@ -179,9 +184,42 @@ public String randomChinese(int count) {
179184
* @return 随机的中国大陆车牌号
180185
*/
181186
public String randomPlateNumber(boolean isNewEnergyVehicle) {
187+
String prefix = ResourceUtils.getRandomElement(provincePrefixList);
188+
return randomPlateNumber(prefix, isNewEnergyVehicle);
189+
}
190+
191+
/**
192+
* 生成随机的中国大陆车牌号(非新能源车型)
193+
*
194+
* @return 随机的中国大陆车牌号
195+
*/
196+
public String randomPlateNumber() {
197+
return randomPlateNumber(false);
198+
}
199+
200+
/**
201+
* 生成随机的中国大陆车牌号
202+
*
203+
* @param province 省/直辖市/自治区(不含港澳台地区)
204+
* @param isNewEnergyVehicle 是否为新能源车型
205+
* @return 随机的中国大陆车牌号
206+
*/
207+
public String randomPlateNumber(Province province, boolean isNewEnergyVehicle) {
208+
Preconditions.checkNotNull(province);
209+
Preconditions.checkArgument(!province.equals(Province.HK) && !province.equals(Province.TW) && !province.equals(Province.MO));
210+
return randomPlateNumber(province.getPrefix(), isNewEnergyVehicle);
211+
}
212+
213+
/**
214+
* 生成随机的中国大陆车牌号
215+
*
216+
* @param provinceNamePrefix 省/直辖市/自治区(不含港澳台地区)简称
217+
* @param isNewEnergyVehicle 是否为新能源车型
218+
* @return 随机的中国大陆车牌号
219+
*/
220+
public String randomPlateNumber(String provinceNamePrefix, boolean isNewEnergyVehicle) {
182221
int length = 5;
183222
List<String> plateNumbers = new ArrayList<>(length);
184-
String prefix = ResourceUtils.getRandomElement(provincePrefixList);
185223
//最多2个字母
186224
int alphaCnt = RandomUtils.nextInt(0, 3);
187225
if (alphaCnt > 0) {
@@ -203,19 +241,10 @@ public String randomPlateNumber(boolean isNewEnergyVehicle) {
203241
//新能源车牌前缀为D或F
204242
newEnergyVehicleTag = (j == 0 ? "D" : "F");
205243
}
206-
return prefix + ResourceUtils.getRandomElement(plateNumbersList)
244+
return provinceNamePrefix + ResourceUtils.getRandomElement(plateNumbersList)
207245
+ newEnergyVehicleTag + Joiner.on("").join(plateNumbers);
208246
}
209247

210-
/**
211-
* 生成随机的中国大陆车牌号(非新能源车型)
212-
*
213-
* @return 随机的中国大陆车牌号
214-
*/
215-
public String randomPlateNumber() {
216-
return randomPlateNumber(false);
217-
}
218-
219248
/**
220249
* 随机公司名称
221250
*
@@ -433,6 +462,15 @@ public String randomSocialCreditCode() {
433462
return prefix + area.getZipCode() + Joiner.on("").join(ResourceUtils.getRandomElement(socialCreditCharactersList, 9)) + checkCode;
434463
}
435464

465+
/**
466+
* 随机文件后缀
467+
*
468+
* @return 文件后缀(小写)
469+
*/
470+
public String randomFileSuffix() {
471+
return ResourceUtils.getRandomElement(fileSuffixList);
472+
}
473+
436474
/**
437475
* 计算校验码
438476
*

src/main/java/com/apifan/common/random/source/PersonInfoSource.java

-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929
public class PersonInfoSource {
3030
private static final Logger logger = LoggerFactory.getLogger(PersonInfoSource.class);
3131

32-
/**
33-
* 姓名图片可选颜色
34-
*/
35-
private static final List<String> namePictureColorsList = Lists.newArrayList(
36-
"255,111,97", "107,91,149", "136,176,75", "146,168,209", "149,82,81"
37-
, "181,101,167", "0,155,119", "221,65,36", "214,80,118", "68,184,172"
38-
, "239,192,80", "91,94,166", "155,35,53", "223,207,190", "85,180,176"
39-
, "225,93,68", "127,205,205", "188,36,60", "195,68,122", "152,180,212");
40-
4132
/**
4233
* 身份证加权因子
4334
*/

src/main/resources/address-word-cn.txt

+30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
2+
23
4+
35
46
57
@@ -9,80 +11,102 @@
911
1012
1113
14+
1215
16+
1317
1418
19+
1520
1621
1722
23+
1824
25+
1926
2027
28+
2129
2230
2331
2432
2533
34+
2635
2736
2837
2938
39+
3040
3141
42+
3243
3344
3445
西
3546
47+
3648
3749
3850
3951
4052
4153
4254
55+
4356
4457
4558
4659
60+
61+
4762
4863
4964
5065
5166
5267
5368
69+
5470
5571
5672
5773
5874
5975
76+
6077
6178
79+
6280
6381
6482
83+
6584
6685
6786
6887
6988
89+
7090
7191
7292
93+
7394
95+
7496
7597
7698
7799
78100
79101
80102
103+
81104
82105
83106
84107
85108
109+
86110
87111
88112
@@ -91,20 +115,26 @@
91115
92116
93117
118+
94119
95120
96121
97122
123+
98124
99125
100126
127+
101128
102129
103130
104131
105132
106133
134+
107135
136+
108137
138+
109139
110140

0 commit comments

Comments
 (0)