当前位置: 首页>>代码示例>>Java>>正文


Java Generex类代码示例

本文整理汇总了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()
        );
    }
}
 
开发者ID:dzuvic,项目名称:jtsgen,代码行数:26,代码来源:TSMapLexerTest.java

示例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;
}
 
开发者ID:phdelodder,项目名称:SubTools,代码行数:20,代码来源:VideoPatterns.java

示例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;
}
 
开发者ID:zezutom,项目名称:schematic,代码行数:28,代码来源:StringGenerator.java

示例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);
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:10,代码来源:RegexPatternPeerIdAlgorithm.java

示例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);
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:10,代码来源:RegexPatternKeyAlgorithm.java

示例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());
}
 
开发者ID:VictorAlbertos,项目名称:Mockery,代码行数:35,代码来源:ValidMockery.java

示例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);
}
 
开发者ID:C0urante,项目名称:avro-random-generator,代码行数:13,代码来源:Generator.java

示例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();
}
 
开发者ID:pikaia,项目名称:gutter,代码行数:20,代码来源:Generate.java

示例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();
    });
}
 
开发者ID:tminglei,项目名称:binder-swagger-java,代码行数:13,代码来源:DataProviders.java

示例10: generate

import com.mifmif.common.regex.Generex; //导入依赖的package包/类
@Override
public String generate(String regex) {
    return new Generex(regex).random();
}
 
开发者ID:lucassaldanha,项目名称:playdoh,代码行数:5,代码来源:GenerexResolver.java

示例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
}
 
开发者ID:lightblue-platform,项目名称:lightblue-rest,代码行数:5,代码来源:LightblueAuditServletFilterTest.java

示例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;
}
 
开发者ID:mkolisnyk,项目名称:aerial,代码行数:51,代码来源:StringRegexpValueExpression.java

示例13: GenerexGenerator

import com.mifmif.common.regex.Generex; //导入依赖的package包/类
public GenerexGenerator(String regexp) {
	generex = new Generex(regexp);
}
 
开发者ID:Narmnevis,项目名称:range,代码行数:4,代码来源:GenerexGenerator.java

示例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();
}
 
开发者ID:FINRAOS,项目名称:JTAF-XCore,代码行数:12,代码来源:RandomGenerator.java

示例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();
}
 
开发者ID:FINRAOS,项目名称:JTAF-XCore,代码行数:10,代码来源:RandomGenerator.java


注:本文中的com.mifmif.common.regex.Generex类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。