/** * @return the number of strings that are matched by the given pattern. * @throws StackOverflowError if the given pattern generates a large, possibly infinite, number of strings. */ public long matchedStringsSize() { buildRootNode(); return rootNode.getNbrMatchedString(); }
@Override public String generate() { return this.generex.random(); }
/** * Prepare the rootNode and it's child nodes so that we can get matchedString by index */ private void buildRootNode() { if (isTransactionNodeBuilt) return; isTransactionNodeBuilt = true; rootNode = new Node(); rootNode.setNbrChar(1); List<Node> nextNodes = prepareTransactionNodes(automaton.getInitialState()); rootNode.setNextNodes(nextNodes); rootNode.updateNbrMatchedString(); }
public Generex(String regex, Random random) { regex=requote(regex); regExp = createRegExp(regex); automaton = regExp.toAutomaton(); this.random = random; }
/** * Generate and return a random String that match the pattern used in this Generex. * * @return */ public String random() { return prepareRandom("", automaton.getInitialState(), 1, Integer.MAX_VALUE); }
public boolean hasNext() { if (found) { return true; } if (steps.isEmpty()) { return false; } nextImpl(); return found; }
/** * Tells whether or not the given regular expression is a valid pattern (for {@code Generex}). * * @param regex the regular expression that will be validated * @return {@code true} if the regular expression is valid, {@code false} otherwise * @throws NullPointerException if the given regular expression is {@code null} */ public static boolean isValidPattern(String regex) { try { createRegExp(regex); return true; } catch (IllegalArgumentException ignore) { // NOPMD - Not valid. } catch (StackOverflowError ignore) { // NOPMD - Possibly valid but stack not big enough to handle it. } return false; }
private void nextImpl() { Step currentStep; while (!steps.isEmpty() && !found) { currentStep = steps.pop(); found = currentStep.build(stringBuilder, steps); } }
@Override public String generate() { return this.generex.random(); }
/** * Prepare the rootNode and it's child nodes so that we can get matchedString by index */ private void buildRootNode() { if (isTransactionNodeBuilt) return; isTransactionNodeBuilt = true; rootNode = new Node(); rootNode.setNbrChar(1); List<Node> nextNodes = prepareTransactionNodes(automaton.getInitialState()); rootNode.setNextNodes(nextNodes); rootNode.updateNbrMatchedString(); }
/** * @return the number of strings that are matched by the given pattern. * @throws StackOverflowError * if the given pattern generates a large, possibly infinite, number of strings. */ public long matchedStringsSize() { buildRootNode(); return rootNode.getNbrMatchedString(); }
/** * Generate and return a random String that match the pattern used in this Generex. * * @return */ public String random() { return prepareRandom("", automaton.getInitialState(), 1, Integer.MAX_VALUE); }
public boolean hasNext() { if (found) { return true; } if (steps.isEmpty()) { return false; } nextImpl(); return found; }
/** * Match a query parameter with a regex. A random query parameter value will be generated from the regex. * * @param parameter Query parameter * @param regex Regular expression to match with */ public PactDslRequestWithPath matchQuery(String parameter, String regex) { return matchQuery(parameter, regex, new Generex(regex).random()); }
/** * Match a response header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regexp Regular expression to match */ public PactDslResponse matchHeader(String header, String regexp) { return matchHeader(header, regexp, new Generex(regexp).random()); }
/** * Match a request header. A random example header value will be generated from the provided regular expression. * * @param header Header to match * @param regex Regular expression to match */ public PactDslRequestWithPath matchHeader(String header, String regex) { return matchHeader(header, regex, new Generex(regex).random()); }