Skip to content

Commit

Permalink
Merge pull request #73 from yindz/v1.0.21
Browse files Browse the repository at this point in the history
V1.0.21
  • Loading branch information
yindz authored May 20, 2023
2 parents 34f0c6d + 843ace1 commit 359c4ef
Show file tree
Hide file tree
Showing 8 changed files with 1,220 additions and 976 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.apifan.common</groupId>
<artifactId>common-random</artifactId>
<version>1.0.20</version>
<version>1.0.21</version>
<packaging>jar</packaging>
<name>common-random</name>
<description>An easy-to-use random data generator.</description>
Expand Down
31 changes: 30 additions & 1 deletion src/main/java/com/apifan/common/random/source/AreaSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.apifan.common.random.entity.Area;
import com.apifan.common.random.entity.CountryOrRegionCode;
import com.apifan.common.random.util.ResourceUtils;
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.collect.Lists;
Expand Down Expand Up @@ -251,7 +252,7 @@ public String randomPhoneNumber(String province, String delimiter) {
* @return 随机的国家或地区编码信息
*/
public CountryOrRegionCode randomCountryOrRegionCode(String startsWith) {
Preconditions.checkArgument(ALPHA_1.matcher(startsWith).matches(), "startsWith 必须为单个字母");
Preconditions.checkArgument(ALPHA_1.matcher(startsWith).matches(), "首字母必须为单个字母");
List<CountryOrRegionCode> filteredList = countryOrRegionCodeList.stream()
.filter(i -> i.getAlpha2().startsWith(startsWith.toUpperCase()) || i.getAlpha3().startsWith(startsWith.toUpperCase())).collect(Collectors.toList());
return randomCountryOrRegionCode(filteredList);
Expand All @@ -266,6 +267,34 @@ public CountryOrRegionCode randomCountryOrRegionCode() {
return randomCountryOrRegionCode(countryOrRegionCodeList);
}

/**
* 随机虚构省份名称
*
* @return 虚构省份名称
*/
public String randomFictionalProvince() {
return Joiner.on("").join(ResourceUtils.getRandomElement(addressWordList, 2)) + "省";
}

/**
* 随机虚构城市名称
*
* @return 虚构城市名称
*/
public String randomFictionalCity() {
return Joiner.on("").join(ResourceUtils.getRandomElement(addressWordList, 2)) + "市";
}

/**
* 随机虚构地址
*
* @return 虚构地址
*/
public String randomFictionalAddress() {
String road = ResourceUtils.getRandomString(addressWordList, 2) + ResourceUtils.getRandomElement(directionList);
return randomFictionalProvince() + randomFictionalCity() + road + "路" + RandomUtils.nextInt(1, 1000) + "号";
}

/**
* 返回随机的国家或地区编码信息
*
Expand Down
60 changes: 49 additions & 11 deletions src/main/java/com/apifan/common/random/source/OtherSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ public class OtherSource {
private static final List<String> socialCreditCharactersList = Lists.newArrayList(
"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");

/**
* 文件后缀
*/
private static final List<String> fileSuffixList = Lists.newArrayList("txt", "pdf", "doc", "docx", "xls", "xlsx", "ppt", "pptx", "wps", "et", "zip", "rar", "7z", "png", "jpg", "tar");

private static final OtherSource instance = new OtherSource();

private OtherSource() {
Expand Down Expand Up @@ -179,9 +184,42 @@ public String randomChinese(int count) {
* @return 随机的中国大陆车牌号
*/
public String randomPlateNumber(boolean isNewEnergyVehicle) {
String prefix = ResourceUtils.getRandomElement(provincePrefixList);
return randomPlateNumber(prefix, isNewEnergyVehicle);
}

/**
* 生成随机的中国大陆车牌号(非新能源车型)
*
* @return 随机的中国大陆车牌号
*/
public String randomPlateNumber() {
return randomPlateNumber(false);
}

/**
* 生成随机的中国大陆车牌号
*
* @param province 省/直辖市/自治区(不含港澳台地区)
* @param isNewEnergyVehicle 是否为新能源车型
* @return 随机的中国大陆车牌号
*/
public String randomPlateNumber(Province province, boolean isNewEnergyVehicle) {
Preconditions.checkNotNull(province);
Preconditions.checkArgument(!province.equals(Province.HK) && !province.equals(Province.TW) && !province.equals(Province.MO));
return randomPlateNumber(province.getPrefix(), isNewEnergyVehicle);
}

/**
* 生成随机的中国大陆车牌号
*
* @param provinceNamePrefix 省/直辖市/自治区(不含港澳台地区)简称
* @param isNewEnergyVehicle 是否为新能源车型
* @return 随机的中国大陆车牌号
*/
public String randomPlateNumber(String provinceNamePrefix, boolean isNewEnergyVehicle) {
int length = 5;
List<String> plateNumbers = new ArrayList<>(length);
String prefix = ResourceUtils.getRandomElement(provincePrefixList);
//最多2个字母
int alphaCnt = RandomUtils.nextInt(0, 3);
if (alphaCnt > 0) {
Expand All @@ -203,19 +241,10 @@ public String randomPlateNumber(boolean isNewEnergyVehicle) {
//新能源车牌前缀为D或F
newEnergyVehicleTag = (j == 0 ? "D" : "F");
}
return prefix + ResourceUtils.getRandomElement(plateNumbersList)
return provinceNamePrefix + ResourceUtils.getRandomElement(plateNumbersList)
+ newEnergyVehicleTag + Joiner.on("").join(plateNumbers);
}

/**
* 生成随机的中国大陆车牌号(非新能源车型)
*
* @return 随机的中国大陆车牌号
*/
public String randomPlateNumber() {
return randomPlateNumber(false);
}

/**
* 随机公司名称
*
Expand Down Expand Up @@ -433,6 +462,15 @@ public String randomSocialCreditCode() {
return prefix + area.getZipCode() + Joiner.on("").join(ResourceUtils.getRandomElement(socialCreditCharactersList, 9)) + checkCode;
}

/**
* 随机文件后缀
*
* @return 文件后缀(小写)
*/
public String randomFileSuffix() {
return ResourceUtils.getRandomElement(fileSuffixList);
}

/**
* 计算校验码
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
public class PersonInfoSource {
private static final Logger logger = LoggerFactory.getLogger(PersonInfoSource.class);

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

/**
* 身份证加权因子
*/
Expand Down
30 changes: 30 additions & 0 deletions src/main/resources/address-word-cn.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Expand All @@ -9,80 +11,102 @@
西
Expand All @@ -91,20 +115,26 @@
Loading

0 comments on commit 359c4ef

Please sign in to comment.