本文整理汇总了Java中com.mifmif.common.regex.Generex类的典型用法代码示例。如果您正苦于以下问题:Java Generex类的具体用法?Java Generex怎么用?Java Generex使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Generex类属于com.mifmif.common.regex包,在下文中一共展示了Generex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRandomRegex
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@Test
public void testRandomRegex() throws Exception {
for (TokenType t: new TokenType[]{
TokenType.WHITESPACE,
TokenType.JIDENT,
TokenType.ANGLE_OPEN,
TokenType.ANGLE_CLOSE,
TokenType.BACKTICK,
TokenType.DELIM,
TokenType.DOT,
TokenType.ARROW,
TokenType.DARROW
}) {
Generex generex = new Generex(t.getPattern().pattern());
generex.setSeed(3);
String random=generex.random().substring(1);
List<Token> tokens = lexer.lex(random);
assertFalse("should match at least once for input '" + random +"'",tokens.isEmpty());
assertEquals(
t,
tokens.iterator().next().type()
);
}
}
示例2: getQualityRegexKeywords
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
private List<String> getQualityRegexKeywords() {
List<String> keys;
StringBuilder regex = new StringBuilder();
String separator = "|";
if (VideoPatterns.QUALITYREGEXKEYWORDS.length > 0) {
regex.append(VideoPatterns.QUALITYREGEXKEYWORDS[0]);
for (int i = 1; i < VideoPatterns.QUALITYREGEXKEYWORDS.length; i++) {
regex.append(separator);
regex.append(VideoPatterns.QUALITYREGEXKEYWORDS[i]);
}
}
Generex generex = new Generex(regex.toString());
keys = generex.getAllMatchedStrings();
return keys;
}
示例3: next
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@Override
public String next() {
String value;
if (format != null) {
List<String> preLoadedValues = dataService.get(format);
if (preLoadedValues != null && !preLoadedValues.isEmpty()) {
int randomIndex = RandomUtil.nextInt(preLoadedValues.size());
value = preLoadedValues.get(randomIndex);
} else {
value = AppUtil.getValueSupplier(format).get();
}
} else if (hasProperty(pattern)) {
value = new Generex(pattern).random();
} else if (combinationRule != null) {
value = getCombinationValue(() -> RandomUtil.nextString(minLength, maxLength));
} else if (AppUtil.isValidRange(minLength, maxLength)) {
value = RandomUtil.nextString(minLength, maxLength);
} else if (AppUtil.isValidMin(minLength)) {
value = RandomUtil.nextStringWithMinLength(minLength);
} else if (AppUtil.isValidMax(maxLength)) {
value = RandomUtil.nextStringWithMaxLength(maxLength);
} else {
value = RandomUtil.nextStringFromUUID();
}
return value;
}
示例4: RegexPatternPeerIdAlgorithm
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
public RegexPatternPeerIdAlgorithm(
@JsonProperty(value = "pattern", required = true) final String pattern
) {
if (pattern == null) {
throw new TorrentClientConfigIntegrityException("peerId algorithm pattern must not be null.");
}
this.pattern = pattern;
this.generex = new Generex(pattern);
}
示例5: RegexPatternKeyAlgorithm
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
public RegexPatternKeyAlgorithm(
@JsonProperty(value = "pattern", required = true) final String pattern
) {
if (pattern == null) {
throw new TorrentClientConfigIntegrityException("peerId algorithm pattern must not be null.");
}
this.pattern = pattern;
this.generex = new Generex(pattern);
}
示例6: legal
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
/**
* Return as legal value the generated value from the regex pattern supplied.
*/
@Override public Object legal(Metadata<Valid> metadata) {
Valid valid = metadata.getAnnotation();
String defaultLegal = valid.legal();
if (!defaultLegal.isEmpty()) {
return safetyCast.with(defaultLegal,
metadata.getType());
}
String regex = valid.value();
String result = new Generex(regex).random();
result = result.replace("^", "")
.replace("$", "")
.replace("?", "");
if (regex.equals(Valid.Template.ID)) {
if (result.length() > 1 && result.charAt(0) == '0') {
result = result.replaceFirst("0", "");
}
}
if (regex.equals(Valid.Template.INT)
|| regex.equals(Valid.Template.ID) || regex.equals(Valid.Template.NUMBER)) {
if (result.length() > 8) {
result = result.substring(0, 7);
}
}
return safetyCast.with(result, metadata.getType());
}
示例7: generateRegexString
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private String generateRegexString(Schema schema, Object regexProp, LengthBounds lengthBounds) {
if (!generexCache.containsKey(schema)) {
if (!(regexProp instanceof String)) {
throw new RuntimeException(String.format("%s property must be a string", REGEX_PROP));
}
generexCache.put(schema, new Generex((String) regexProp));
}
// Generex.random(low, high) generates in range [low, high]; we want [low, high), so subtract
// 1 from maxLength
return generexCache.get(schema).random(lengthBounds.min(), lengthBounds.max() - 1);
}
示例8: main
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
/**
* Generate utterances from regex file.
*
* @throws Exception
*/
public static void main(String[] args) throws Exception {
final String inFile = "src/main/resources/SampleUtterancesRegex.txt";
final String outFile = "src/main/resources/SampleUtterances.txt";
FileUtils.deleteQuietly(new File(outFile));
final PrintWriter writer = new PrintWriter(Files.newBufferedWriter(Paths.get(outFile)));
//read file into stream, try-with-resources
try (Stream<String> stream = Files.lines(Paths.get(inFile))) {
stream.forEach(line -> new Generex(line).getAllMatchedStrings().forEach(writer::println));
} catch (IOException e) {
e.printStackTrace();
}
writer.close();
}
示例9: collectStringProperty
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
protected DataProvider collectStringProperty(Swagger swagger, StringProperty schema, boolean clean) {
return gen(() -> {
StringProperty.Format uriFormat = StringProperty.Format.fromName(schema.getFormat());
if (uriFormat == StringProperty.Format.URI || uriFormat == StringProperty.Format.URL)
return faker.internet().url();
else if (!isEmpty(schema.getPattern())) {
Generex generex = new Generex(schema.getPattern());
return generex.random();
} else
return faker.lorem().word();
});
}
示例10: generate
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@Override
public String generate(String regex) {
return new Generex(regex).random();
}
示例11: generateStringFromPattern
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
private String generateStringFromPattern(String pattern) {
Generex generex = new Generex(pattern);
return generex.random().replace(" ", "");// it seems there is a bug on the dependency of the dependency with \\S as it generate whitespace some times
}
示例12: generate
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@Override
public List<InputRecord> generate() throws Exception {
List<InputRecord> result = new ArrayList<InputRecord>();
// Generated valid string
Generex generex = new Generex(this.getInput().getValue());
String value = "";
InputRecord testRecord = this.getInput();
for (int i = 0; i < 2; i++) {
value = generex.random(1);
result.add(
new InputRecord(
testRecord.getName(),
testRecord.getType(),
value,
testRecord.getCondition(),
value.matches(testRecord.getValue()))
);
}
// Empty string
value = "";
result.add(
new InputRecord(
testRecord.getName(),
testRecord.getType(),
value,
testRecord.getCondition(),
value.matches(testRecord.getValue()))
);
// Doubled string (repetitive pattern)
value = generex.random(1);
value = value.concat(value);
result.add(
new InputRecord(
testRecord.getName(),
testRecord.getType(),
value,
testRecord.getCondition(),
value.matches(testRecord.getValue()))
);
// Pattern itself
result.add(
new InputRecord(
testRecord.getName(),
testRecord.getType(),
testRecord.getValue(),
testRecord.getCondition(),
testRecord.getValue().matches(testRecord.getValue()))
);
return result;
}
示例13: GenerexGenerator
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
public GenerexGenerator(String regexp) {
generex = new Generex(regexp);
}
示例14: generateRegexp
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
/**
* Generate a string using a specified regular expression.
*
* @param regexp
* - regular expression to be used to generate the string
* @return the randomly generated string
*/
public static String generateRegexp(String regexp) {
Generex generex = new Generex(regexp);
return generex.random();
}
示例15: generatePhone
import com.mifmif.common.regex.Generex; //导入依赖的package包/类
/**
* Generates a random phone number.
*
* @return the randomly generated phone number.
*/
public static String generatePhone() {
Generex generex = new Generex("[0-9]{10}");
return generex.random();
}