Package jsonvalues.gen
Class JsGens
- java.lang.Object
-
- jsonvalues.gen.JsGens
-
public class JsGens extends java.lang.Object
Class with different kind of generators
-
-
Field Summary
Fields Modifier and Type Field Description static JsGen<JsStr>
alphabetic
Generates a alphabetic string where the length is between [0-10]static JsGen<JsStr>
alphanumeric
Generates a alphanumeric string where the length is between [0-10]static JsGen<JsBinary>
binary
Generates an array of 1024 bytesstatic JsGen<JsBool>
bool
Generates a booleanstatic JsGen<JsStr>
character
Generates character from 0-255static JsGen<JsStr>
characterAlpha
Generates character from 65-122static JsGen<JsInstant>
date
Generates an instant betweeny Instant#MAX
static JsGen<JsDouble>
decimal
Generates a decimal numberstatic JsGen<JsStr>
digit
Generates a digit from 0-9static JsGen<JsInt>
integer
Generates an integer numberstatic JsGen<JsStr>
letter
Generates a letter from a-zstatic JsGen<JsLong>
longInteger
Generates a long numberstatic JsGen<JsInt>
natural
Generates a positive integer (zero included)static JsGen<JsStr>
str
Generates a string where the length is between [0-10]
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JsGen<JsStr>
alphabetic(int length)
Generates an alphabetic string of the given lengthstatic JsGen<JsStr>
alphanumeric(int length)
Generates an alphanumeric string of the given lengthstatic JsGen<JsArray>
array(JsGen<?> gen, int size)
Creates an array generator of the given size, whose elements are chosen from the given generatorstatic JsGen<JsArray>
arrayDistinct(JsGen<?> gen, int size)
Generates an array of values from the given generator, with the guarantee that the elements will be distinct.static JsGen<JsArray>
arrayDistinct(JsGen<?> gen, int size, int maxTries)
Generates an array of values from the given generator, with the guarantee that the elements will be distinct.static JsGen<JsBinary>
binary(int length)
Generates an array of bytes of the given lengthstatic JsGen<JsInt>
choose(int min, int max)
Creates a generator that generates integers in the range`min` to `max`, inclusive.static JsGen<JsValue>
cons(JsValue value)
generates a constantstatic JsGen<JsInstant>
dateBetween(long min, long max)
generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two instants converted to the number of seconds from the epoch of 1970-01-01T00:00:00Z.static JsGen<JsInstant>
dateBetween(java.time.ZonedDateTime min, java.time.ZonedDateTime max)
generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two date-time with a time-zone.static JsGen<JsStr>
digits(int length)
Generates a seq of digits of the given lengthstatic JsGen<?>
frequency(io.vavr.Tuple2<java.lang.Integer,JsGen<?>> freq, io.vavr.Tuple2<java.lang.Integer,JsGen<?>>... others)
Creates a generator that chooses a generator from `pairs` based on the provided likelihoods.static <O extends JsValue>
JsGen<O>oneOf(java.util.List<O> list)
Creates a generator that randomly chooses a value from the given liststatic JsGen<?>
oneOf(JsGen<?> gen, JsGen<?>... others)
Creates a generator that randomly chooses a value from the provided generatorsstatic JsGen<JsValue>
oneOf(JsValue a, JsValue... others)
Creates a generator that randomly chooses a value from the given as parametersstatic JsGen<JsValue>
single(JsValue value)
lift a constant value up into a generatorstatic JsGen<JsStr>
str(int length)
Generates an alphabetic string of the given lengthstatic JsGen<JsArray>
tuple(JsGen<?> gen, JsGen<?>... others)
Creates a tuple generator from the given generators.
-
-
-
Method Detail
-
digits
public static JsGen<JsStr> digits(int length)
Generates a seq of digits of the given length- Parameters:
length
- the length of the string- Returns:
- a string generator
-
str
public static JsGen<JsStr> str(int length)
Generates an alphabetic string of the given length- Parameters:
length
- the length of the generated string- Returns:
- a generator
-
binary
public static JsGen<JsBinary> binary(int length)
Generates an array of bytes of the given length- Parameters:
length
- the number of bytes generated- Returns:
- an array of bytes generator
-
alphabetic
public static JsGen<JsStr> alphabetic(int length)
Generates an alphabetic string of the given length- Parameters:
length
- the length of the string- Returns:
- a string generator
-
alphanumeric
public static JsGen<JsStr> alphanumeric(int length)
Generates an alphanumeric string of the given length- Parameters:
length
- the length of the string- Returns:
- a string generator
-
single
public static JsGen<JsValue> single(JsValue value)
lift a constant value up into a generator- Parameters:
value
- the value- Returns:
- a generator that always produce the same value
-
oneOf
public static JsGen<JsValue> oneOf(JsValue a, JsValue... others)
Creates a generator that randomly chooses a value from the given as parameters- Parameters:
a
- a valueothers
- the others values- Returns:
- a generator
-
oneOf
public static JsGen<?> oneOf(JsGen<?> gen, JsGen<?>... others)
Creates a generator that randomly chooses a value from the provided generators- Parameters:
gen
- a generatorothers
- the others generators- Returns:
- a generator
-
oneOf
public static <O extends JsValue> JsGen<O> oneOf(java.util.List<O> list)
Creates a generator that randomly chooses a value from the given list- Type Parameters:
O
- the type of the generated value- Parameters:
list
- the list of values- Returns:
- a generator
-
tuple
public static JsGen<JsArray> tuple(JsGen<?> gen, JsGen<?>... others)
Creates a tuple generator from the given generators. The nth-generator generates the nth-element of the tuple- Parameters:
gen
- the head generatorothers
- the rest of generators- Returns:
- an array generator
-
array
public static JsGen<JsArray> array(JsGen<?> gen, int size)
Creates an array generator of the given size, whose elements are chosen from the given generator- Parameters:
gen
- the generator that elements are chosen fromsize
- the size of the generated array- Returns:
- an array generator
-
arrayDistinct
public static JsGen<JsArray> arrayDistinct(JsGen<?> gen, int size)
Generates an array of values from the given generator, with the guarantee that the elements will be distinct. If the generator cannot or is unlikely to produce enough distinct elements after 100 tries, this generator will fail with a RuntimeException- Parameters:
gen
- the given generatorsize
- the size of the array- Returns:
- a json generator
-
arrayDistinct
public static JsGen<JsArray> arrayDistinct(JsGen<?> gen, int size, int maxTries)
Generates an array of values from the given generator, with the guarantee that the elements will be distinct. If the generator cannot or is unlikely to produce enough distinct elements after the given number of tries, this generator will fail with a RuntimeException- Parameters:
gen
- the given generatorsize
- the size of the arraymaxTries
- the max number of tries to produce distinct values- Returns:
- a json generator
-
frequency
@SafeVarargs public static JsGen<?> frequency(io.vavr.Tuple2<java.lang.Integer,JsGen<?>> freq, io.vavr.Tuple2<java.lang.Integer,JsGen<?>>... others)
Creates a generator that chooses a generator from `pairs` based on the provided likelihoods. The likelihood of a given generator being chosen is its likelihood divided by the sum of all likelihoods. Shrinks toward choosing an earlier generator, as well as shrinking the value generated by the chosen generator.- Parameters:
freq
- a frequency pairothers
- the rests of pairs- Returns:
- a json generator
-
choose
public static JsGen<JsInt> choose(int min, int max)
Creates a generator that generates integers in the range`min` to `max`, inclusive.- Parameters:
min
- the minimum valuemax
- the maximum value- Returns:
- an integer generator
-
dateBetween
public static JsGen<JsInstant> dateBetween(java.time.ZonedDateTime min, java.time.ZonedDateTime max)
generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two date-time with a time-zone.- Parameters:
min
- the origin of the interval (inclusive)max
- the bound of the interval (inclusive)- Returns:
- an instant generator
-
dateBetween
public static JsGen<JsInstant> dateBetween(long min, long max)
generates an instant in UTC formatted with the ISO instant formatter (such as '2011-12-03T10:15:30Z'), between an interval given by two instants converted to the number of seconds from the epoch of 1970-01-01T00:00:00Z.- Parameters:
min
- the origin of the interval (inclusive)max
- the bound of the interval (inclusive)- Returns:
- an instant generator
-
-