public class Generex extends Object implements Iterable
| Modifier and Type | Field and Description |
|---|---|
private dk.brics.automaton.Automaton |
automaton |
private boolean |
isTransactionNodeBuilt |
private int |
matchedStringCounter |
private List<String> |
matchedStrings |
private static Map<String,String> |
PREDEFINED_CHARACTER_CLASSES
The predefined character classes supported by
Generex. |
private int |
preparedTransactionNode |
private Random |
random |
private dk.brics.automaton.RegExp |
regExp |
private Node |
rootNode |
| Constructor and Description |
|---|
Generex(dk.brics.automaton.Automaton automaton) |
Generex(dk.brics.automaton.Automaton automaton,
Random random) |
Generex(String regex) |
Generex(String regex,
Random random) |
| Modifier and Type | Method and Description |
|---|---|
private void |
buildRootNode()
Prepare the rootNode and it's child nodes so that we can get matchedString by index
|
private String |
buildStringFromNode(Node node,
int indexOrder) |
private static dk.brics.automaton.RegExp |
createRegExp(String regex)
Creates a
RegExp instance from the given regular expression. |
private void |
generate(String strMatch,
dk.brics.automaton.State state,
int limit) |
List<String> |
getAllMatchedStrings()
Generate all Strings that matches the given Regex.
|
String |
getFirstMatch() |
String |
getMatchedString(int indexOrder) |
List<String> |
getMatchedStrings(int limit)
Generate subList with a size of
limit of Strings that matches the given Regex. the Strings are ordered in lexicographical order. |
boolean |
isInfinite()
Tells whether or not the given pattern (or
Automaton) is infinite, that is, generates an infinite number of strings. |
static boolean |
isValidPattern(String regex)
Tells whether or not the given regular expression is a valid pattern (for
Generex). |
Iterator |
iterator() |
long |
matchedStringsSize() |
private String |
prepareRandom(String strMatch,
dk.brics.automaton.State state,
int minLength,
int maxLength) |
private List<Node> |
prepareTransactionNodes(dk.brics.automaton.State state)
Build list of nodes that present possible transactions from the
state. |
String |
random()
Generate and return a random String that match the pattern used in this Generex.
|
String |
random(int minLength)
Generate and return a random String that match the pattern used in this Generex, and the string has a length >=
minLength |
String |
random(int minLength,
int maxLength)
Generate and return a random String that match the pattern used in this Generex, and the string has a length >=
minLength and <=
maxLength |
private static String |
requote(String regex)
Requote a regular expression by escaping some parts of it from generation without need to escape each special character one by one.
|
void |
setSeed(long seed)
initialize the random instance used with a seed value to generate a
pseudo random suite of strings based on the passed seed and matches the used regular expression
instance
|
private static final Map<String,String> PREDEFINED_CHARACTER_CLASSES
Generex.
An immutable map containing as keys the character classes and values the equivalent regular expression syntax.
createRegExp(String)private dk.brics.automaton.RegExp regExp
private dk.brics.automaton.Automaton automaton
private Node rootNode
private boolean isTransactionNodeBuilt
private int matchedStringCounter
private int preparedTransactionNode
private Random random
public Generex(String regex)
public Generex(dk.brics.automaton.Automaton automaton)
public Generex(dk.brics.automaton.Automaton automaton,
Random random)
private static dk.brics.automaton.RegExp createRegExp(String regex)
RegExp instance from the given regular expression.
Predefined character classes are replaced with equivalent regular expression syntax prior creating the instance.
regex - the regular expression used to build the RegExp instanceRegExp instance for the given regular expressionNullPointerException - if the given regular expression is nullIllegalArgumentException - if an error occurred while parsing the given regular expressionStackOverflowError - if the regular expression has to many transitionsPREDEFINED_CHARACTER_CLASSES,
isValidPattern(String)public void setSeed(long seed)
seed - public String getMatchedString(int indexOrder)
indexOrder - ( 1<= indexOrder <=n)indexOrder between 1 and n where n is the number of matched String.StackOverflowErrorpublic boolean isInfinite()
Automaton) is infinite, that is, generates an infinite number of strings.
For example, the pattern "a+" generates an infinite number of strings whether "a{5}" does not.
true if the pattern (or Automaton) generates an infinite number of strings, false otherwisepublic String getFirstMatch()
public long matchedStringsSize()
StackOverflowError - if the given pattern generates a large, possibly infinite, number of strings.private void buildRootNode()
private void generate(String strMatch, dk.brics.automaton.State state, int limit)
private List<Node> prepareTransactionNodes(dk.brics.automaton.State state)
state.state - public List<String> getAllMatchedStrings()
public List<String> getMatchedStrings(int limit)
limit of Strings that matches the given Regex. the Strings are ordered in lexicographical order.limit - public String random()
public String random(int minLength)
minLengthminLength - public String random(int minLength, int maxLength)
minLength and <=
maxLengthminLength - maxLength - private String prepareRandom(String strMatch, dk.brics.automaton.State state, int minLength, int maxLength)
public static boolean isValidPattern(String regex)
Generex).regex - the regular expression that will be validatedtrue if the regular expression is valid, false otherwiseNullPointerException - if the given regular expression is nullprivate static String requote(String regex)
minion_\d{3}\Q@gru.evil\E
minion_\d{3}\@gru\.evil regex - Copyright © 2016. All rights reserved.