Skip to content

Commit

Permalink
[improve][plugin][datareader] Add support for generating email address (
Browse files Browse the repository at this point in the history
  • Loading branch information
wgzhao authored Dec 12, 2023
1 parent 97e4c0b commit d165f76
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/reader/datareader.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
| `company` | 随机生成一个公司的名称 | `万迅电脑科技有限公司` | string | |
| `creditCard` | 随机生成一个信用卡卡号 | `430405198908214042` | string | 16 位 |
| `debitCard` | 随机生成一个储蓄卡卡号 | `6227894836568607` | string | 19 位 |
| `email` | 随机生成一个电子邮件地址 | `[email protected]` | string | |
| `idCard` | 随机生成一个国内身份证号码 | `350600198508222018` | string | 18 位,负责校验规则,头 6 位编码满足行政区划要求 |
| `lat` | 随机生成维度数据 | `48.6648764` | double | 固定 7 位小数 ,也可以用`latitude` 表示 |
| `lng` | 随机生成经度数据 | `120.6018163` | double | 固定 7 位小数,也可以使用`longitude` 表示 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.wgzhao.addax.plugin.reader.datareader.util.AddressUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.BankUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.CompanyUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.EmailUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.GeoUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.IdCardUtil;
import com.wgzhao.addax.plugin.reader.datareader.util.JobUtil;
Expand Down Expand Up @@ -551,6 +552,8 @@ else if (columnType == Type.DATE) {
return new StringColumn(BankUtil.nextCreditCard());
case COMPANY:
return new StringColumn(CompanyUtil.nextCompany());
case EMAIL:
return new StringColumn(EmailUtil.nextEmail());
case ID_CARD:
return new StringColumn(IdCardUtil.nextIdCard());
case LAT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public enum Rule
CONSTANT,
CREDIT_CARD,
DEBIT_CARD,
EMAIL,
ID_CARD,
INCR,
JOB,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* * Licensed to the Apache Software Foundation (ASF) under one
* * or more contributor license agreements. See the NOTICE file
* * distributed with this work for additional information
* * regarding copyright ownership. The ASF licenses this file
* * to you under the Apache License, Version 2.0 (the
* * "License"); you may not use this file except in compliance
* * with the License. You may obtain a copy of the License at
* *
* * http://www.apache.org/licenses/LICENSE-2.0
* *
* * Unless required by applicable law or agreed to in writing,
* * software distributed under the License is distributed on an
* * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* * KIND, either express or implied. See the License for the
* * specific language governing permissions and limitations
* * under the License.
*
*/

package com.wgzhao.addax.plugin.reader.datareader.util;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.rng.UniformRandomProvider;
import org.apache.commons.rng.simple.RandomSource;

public class EmailUtil {

private static final String[] EMAIL_DOMAIN = {"gmail.com", "yahoo.com","aol.com","qq.com","163.com","sina.com",
"sina.com.cn","proton.me","outlook.com","hotmail.com","icloud.com"};

private static final UniformRandomProvider rng = RandomSource.XO_RO_SHI_RO_128_PP.create();
private static final int userLength = 10;

public static String nextEmail() {
return RandomStringUtils.randomAlphanumeric(
rng.nextInt(3, userLength)) + "@" + CommonUtil.randChoose(EMAIL_DOMAIN);

}
}

0 comments on commit d165f76

Please sign in to comment.