001/*
002 * Copyright © 2025 CUI-OpenSource-Software (info@cuioss.de)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package de.cuioss.test.generator.internal.net.java.quickcheck.generator;
017
018import de.cuioss.test.generator.internal.net.java.quickcheck.ExtendibleGenerator;
019import de.cuioss.test.generator.internal.net.java.quickcheck.FrequencyGenerator;
020import de.cuioss.test.generator.internal.net.java.quickcheck.Generator;
021import de.cuioss.test.generator.internal.net.java.quickcheck.GeneratorException;
022import de.cuioss.test.generator.internal.net.java.quickcheck.ObjectGenerator;
023import de.cuioss.test.generator.internal.net.java.quickcheck.QuickCheck;
024import de.cuioss.test.generator.internal.net.java.quickcheck.StatefulGenerator;
025import de.cuioss.test.generator.internal.net.java.quickcheck.collection.Pair;
026import de.cuioss.test.generator.internal.net.java.quickcheck.collection.Triple;
027import de.cuioss.test.generator.internal.net.java.quickcheck.generator.distribution.Distribution;
028import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.AbstractTransformerGenerator;
029import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ArrayGenerator;
030import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ByteArrayGenerator;
031import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ByteGenerator;
032import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.CharacterGenerator;
033import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.CloningGenerator;
034import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.DateGenerator;
035import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.DefaultFrequencyGenerator;
036import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.DoubleGenerator;
037import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.DuplicateGenerator;
038import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.EnsuredValuesGenerator;
039import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ExcludingGenerator;
040import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.FixedValuesGenerator;
041import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.IntegerArrayGenerator;
042import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.IntegerGenerator;
043import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.IteratorGenerator;
044import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ListGenerator;
045import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.LongGenerator;
046import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.MapGenerator;
047import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ObjectDefaultMappingGenerator;
048import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ObjectGeneratorImpl;
049import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.SetGenerator;
050import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.SortedListGenerator;
051import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.StrictlyOrderedGenerator;
052import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.StringGenerator;
053import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.SubmapGenerator;
054import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.SubsetGenerator;
055import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.SubstringGenerator;
056import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.TupleGenerator;
057import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.UniqueComparableValuesGenerator;
058import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.UniqueValuesGenerator;
059import de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.VetoableGenerator;
060
061import java.util.Collections;
062import java.util.Comparator;
063import java.util.Date;
064import java.util.EnumSet;
065import java.util.Iterator;
066import java.util.List;
067import java.util.Map;
068import java.util.NoSuchElementException;
069import java.util.Objects;
070import java.util.Set;
071import java.util.concurrent.TimeUnit;
072
073import static de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.CharacterGenerator.BASIC_LATIN;
074import static de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.CharacterGenerator.LATIN_1_SUPPLEMENT;
075import static de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ListGenerator.MAX_SIZE;
076import static java.util.Arrays.asList;
077import static java.util.concurrent.TimeUnit.MILLISECONDS;
078
079@SuppressWarnings({"WeakerAccess"})
080public class Generators {
081
082    public static final int DEFAULT_STRING_MAX_LENGTH = StringGenerator.MAX_LENGTH;
083    public static final int DEFAULT_COLLECTION_MAX_SIZE = ListGenerator.MAX_SIZE;
084    // TODO this could be a bit high
085    // for runs = 200 this means 20000 tries for the worst case
086    public static final int DEFAULT_MAX_TRIES = VetoableGenerator.DEFAULT_MAX_TRIES;
087
088    private Generators() {
089    }
090
091    /**
092     * Cast a generator to a super type generator.
093     * <p>
094     * This method can be used to cast a generator of type Generator&lt;A&gt; to a
095     * generator of type Generator&lt;B&gt; given that A extends B. This operator is
096     * valid as all Generator instances are covariant (are pure producers).
097     * </p>
098     */
099    @SuppressWarnings("unchecked")
100    public static <T> Generator<T> cast(Generator<? extends T> generator) {
101        return (Generator<T>) generator;
102    }
103
104    /**
105     * Convert a generator into a {@link Iterable iterable}.<br>
106     *
107     * The generator will be run {@link QuickCheck#MAX_NUMBER_OF_RUNS} times.
108     */
109    public static <T> Iterable<T> toIterable(final Generator<T> generator) {
110        return toIterable(generator, QuickCheck.MAX_NUMBER_OF_RUNS);
111    }
112
113    /**
114     * Convert a generator into an {@link Iterable iterable}.
115     *
116     * @param numberOfRuns to execute the runner
117     */
118    public static <T> Iterable<T> toIterable(final Generator<T> generator, final int numberOfRuns) {
119        Objects.requireNonNull(generator, "generator");
120        if (0.0 > numberOfRuns) {
121            throw new IllegalArgumentException("number of runs");
122        }
123        return () -> new Iterator<>() {
124
125            private int runs;
126
127            @Override
128            public boolean hasNext() {
129                return runs < numberOfRuns;
130            }
131
132            @Override
133            public T next() {
134                if (!hasNext()) {
135                    throw new NoSuchElementException();
136                }
137                runs++;
138                return generator.next();
139            }
140
141            @Override
142            public void remove() {
143                throw new UnsupportedOperationException();
144            }
145        };
146    }
147
148    /**
149     * Create a new string generator.<br>
150     *
151     * The characters are from the Basic Latin and Latin-1 Supplement unicode
152     * blocks.
153     */
154    public static ExtendibleGenerator<Character, String> strings() {
155        return new StringGenerator();
156    }
157
158    /**
159     * Create a new string generator which generates strings of characters ranging
160     * from lo to hi.
161     *
162     * @param lo lower boundary character
163     * @param hi upper boundary character
164     */
165    public static ExtendibleGenerator<Character, String> strings(char lo, char hi) {
166        return new StringGenerator(lo, hi);
167    }
168
169    /**
170     * Create a new string generator which generates strings of characters from the
171     * given string.
172     */
173    public static ExtendibleGenerator<Character, String> strings(String allowedCharacters) {
174        return new StringGenerator(characters(allowedCharacters));
175    }
176
177    /**
178     * Create a new string generator which generates strings of characters from the
179     * given string with a length between min and max.
180     */
181    public static ExtendibleGenerator<Character, String> strings(String allowedCharacters, int min, int max) {
182        return new StringGenerator(new IntegerGenerator(min, max), characters(allowedCharacters));
183    }
184
185    /**
186     * Creates a new String genearator which generates strings whose length ranges
187     * from zero to given length.
188     */
189    public static ExtendibleGenerator<Character, String> strings(int max) {
190        return strings(0, max);
191    }
192
193    /**
194     * Create a new string generator which generates strings of sizes ranging from
195     * loLength to hiLength.
196     *
197     * @param min lower size boundary
198     * @param max upper size boundary
199     */
200    public static ExtendibleGenerator<Character, String> strings(int min, int max) {
201        return new StringGenerator(new IntegerGenerator(min, max), new CharacterGenerator());
202    }
203
204    /**
205     * Create a new string generator which creates strings of characters generated
206     * by the given character generator with a length generated by the length
207     * generator.
208     *
209     */
210    public static ExtendibleGenerator<Character, String> strings(Generator<Integer> length,
211            Generator<Character> characters) {
212        return new StringGenerator(length, characters);
213    }
214
215    /**
216     * Create a new string generator which creates strings of characters generated
217     * by the given character generator.
218     *
219     */
220    public static ExtendibleGenerator<Character, String> strings(Generator<Character> characterGenerator) {
221        return new StringGenerator(characterGenerator);
222    }
223
224    /**
225     * Create a new string generator which creates strings of characters from a-z
226     * and A-Z.
227     */
228    public static ExtendibleGenerator<Character, String> letterStrings() {
229        return new StringGenerator(characters('a', 'z')).add(characters('A', 'Z'));
230    }
231
232    /**
233     * Create a new string generator which creates strings with sizes ranging from
234     * loLengh to hiLength of characters from a-z and A-Z.
235     */
236    public static ExtendibleGenerator<Character, String> letterStrings(int min, int max) {
237        var generator = new StringGenerator(new IntegerGenerator(min, max), characters('a', 'z'));
238        return generator.add(characters('A', 'Z'));
239    }
240
241    /**
242     * Create a new string generator which creates strings of characters generated
243     * by {@link Generators#basicLatinCharacters()} and
244     * {@link Generators#latin1SupplementCharacters()}.
245     */
246    public static ExtendibleGenerator<Character, String> printableStrings() {
247        return new StringGenerator(basicLatinCharacters()).add(latin1SupplementCharacters());
248    }
249
250    /**
251     * Create a new string generator for strings that are not empty.
252     */
253    public static ExtendibleGenerator<Character, String> nonEmptyStrings() {
254        return strings(1, StringGenerator.MAX_LENGTH);
255    }
256
257    /**
258     * Create a new string generator for substrings of a base string.
259     *
260     * <p>
261     * base.contains(generated string) will always be true.
262     * </p>
263     */
264    public static Generator<String> substrings(String base) {
265        return substrings(base, 0, base.length());
266    }
267
268    /**
269     * Create a new string generator for substrings of a base string.
270     *
271     * <p>
272     * base.contains(generated string) will always be true.
273     * </p>
274     *
275     * @param size of the generated string
276     */
277    public static Generator<String> substrings(String base, int size) {
278        return substrings(base, size, size);
279    }
280
281    /**
282     * Create a new string generator for substrings of a base string.
283     *
284     * <p>
285     * base.contains(generated string) will always be true.
286     * </p>
287     *
288     * @param minSize is the minimum size of the generated string
289     * @param maxSize is the maximum size of the generated string
290     */
291    public static Generator<String> substrings(String base, int minSize, int maxSize) {
292        return new SubstringGenerator(base, minSize, maxSize);
293    }
294
295    /**
296     * Create a new character generator which generates characters ranging from lo
297     * to hi.
298     */
299    public static Generator<Character> characters(char lo, char hi) {
300        return new CharacterGenerator(lo, hi);
301    }
302
303    /**
304     * Create a new character generator.<br>
305     *
306     * The characters are from the Basic Latin and Latin-1 Supplement unicode
307     * blocks.
308     */
309    public static Generator<Character> characters() {
310        return new CharacterGenerator();
311    }
312
313    /**
314     * Create a new character generator which generates characters from the given
315     * character array.
316     */
317    public static Generator<Character> characters(Character... chars) {
318        return characters(asList(chars));
319    }
320
321    /**
322     * Create a new character generator which generates characters from the given
323     * string.
324     */
325    public static Generator<Character> characters(String string) {
326        var chars = new Character[string.length()];
327        for (var i = 0; i < chars.length; i++) {
328            chars[i] = string.charAt(i);
329        }
330        return characters(chars);
331    }
332
333    /**
334     * Create a new character generator which generates characters from the given
335     * characters.
336     */
337    public static Generator<Character> characters(Iterable<Character> chars) {
338        return new FixedValuesGenerator<>(chars);
339    }
340
341    /**
342     * Create a new character generator which generates latin-1 supplement
343     * characters.
344     */
345    public static Generator<Character> latin1SupplementCharacters() {
346        return characters(LATIN_1_SUPPLEMENT.getFirst(), LATIN_1_SUPPLEMENT.getSecond());
347    }
348
349    /**
350     * Create a new character generator which generates latin characters.
351     */
352    public static Generator<Character> basicLatinCharacters() {
353        return characters(BASIC_LATIN.getFirst(), BASIC_LATIN.getSecond());
354    }
355
356    /**
357     * Create a new integer generator which creates integers ranging from
358     * {@link Integer#MIN_VALUE} to {@link Integer#MAX_VALUE}.
359     *
360     */
361    public static Generator<Integer> integers() {
362        return new IntegerGenerator();
363    }
364
365    /**
366     * Create a new integer generator which creates integers that are at equal or
367     * greater than low.
368     */
369    public static Generator<Integer> integers(int low) {
370        return new IntegerGenerator(low, Integer.MAX_VALUE);
371    }
372
373    /**
374     * Create a new integer generator which creates integers ranging from lo to hi.
375     */
376    public static Generator<Integer> integers(int lo, int hi) {
377        return new IntegerGenerator(lo, hi);
378    }
379
380    /**
381     * Create a new integer generator which creates integers ranging from {@code lo}
382     * to {@code hi} based on the given {@link Distribution}.
383     */
384    public static Generator<Integer> integers(int lo, int hi, Distribution distribution) {
385        return new IntegerGenerator(lo, hi, distribution);
386    }
387
388    /**
389     * Create a new integer generator which creates integers ranging from {@code 1}
390     * to {@link Integer#MAX_VALUE}.
391     */
392    public static Generator<Integer> positiveIntegers() {
393        return positiveIntegers(Integer.MAX_VALUE);
394    }
395
396    /**
397     * Create a new integer generator which creates integers ranging from {@code 1}
398     * to {@code max} (which must be at least 1).
399     */
400    public static Generator<Integer> positiveIntegers(int hi) {
401        return new IntegerGenerator(1, hi);
402    }
403
404    /**
405     * Create a new byte generator which creates byte values ranging from
406     * {@link Byte#MIN_VALUE} to {@link Byte#MAX_VALUE}.
407     */
408    public static Generator<Byte> bytes() {
409        return new ByteGenerator();
410    }
411
412    /**
413     * Create a new byte generator which creates byte values ranging from lo to hi.
414     */
415    public static Generator<Byte> bytes(byte lo, byte hi) {
416        return new ByteGenerator(lo, hi);
417    }
418
419    /**
420     * Create a new integer generator which creates integers ranging from lo to hi
421     * based on the given {@link Distribution}.
422     */
423    public static Generator<Byte> bytes(byte lo, byte hi, Distribution distribution) {
424        return new ByteGenerator(lo, hi, distribution);
425    }
426
427    /**
428     * Create a new long generator which creates longs ranging from
429     * {@link Long#MIN_VALUE} to {@link Long#MAX_VALUE}.
430     */
431    public static Generator<Long> longs() {
432        return new LongGenerator();
433    }
434
435    /**
436     * Create a new long generator which creates longs ranging from lo to hi.
437     */
438    public static Generator<Long> longs(long lo, long hi) {
439        return new LongGenerator(lo, hi, Distribution.UNIFORM);
440    }
441
442    /**
443     * Create a new long generator which creates longs ranging from lo to hi based
444     * on the given {@link Distribution}.
445     */
446    public static Generator<Long> longs(long lo, long hi, Distribution distribution) {
447        return new LongGenerator(lo, hi, distribution);
448    }
449
450    /**
451     * Create a new long generator which creates long values ranging from 1 to
452     * {@link Long#MAX_VALUE}.
453     */
454    public static Generator<Long> positiveLongs() {
455        return positiveLongs(Long.MAX_VALUE);
456    }
457
458    /**
459     * Create a new long generator which creates long values ranging from 1 to hi.
460     */
461    public static Generator<Long> positiveLongs(long hi) {
462        return longs(1, hi);
463    }
464
465    /**
466     * Create a new double generator which creates doubles ranging from
467     * {@link Double#MIN_VALUE} to {@link Double#MAX_VALUE}.
468     */
469    public static Generator<Double> doubles() {
470        return new DoubleGenerator();
471    }
472
473    /**
474     * Create a new double generator which creates doubles ranging from lo to hi.
475     */
476    public static Generator<Double> doubles(double lo, double hi) {
477        return new DoubleGenerator(lo, hi);
478    }
479
480    /**
481     * Create a new double generator which creates doubles ranging from lo to hi
482     * based on the given {@link Distribution}.
483     */
484    public static Generator<Double> doubles(double lo, double hi, Distribution distribution) {
485        return new DoubleGenerator(lo, hi, distribution);
486    }
487
488    /**
489     * Create a generator for boolean values.
490     */
491    public static Generator<Boolean> booleans() {
492        return new FixedValuesGenerator<>(asList(Boolean.TRUE, Boolean.FALSE));
493    }
494
495    /**
496     * Create a generator for null values.
497     */
498    public static <T> Generator<T> nulls() {
499        return new FixedValuesGenerator<>();
500    }
501
502    /**
503     * Create a generator for date values.
504     */
505    public static Generator<Date> dates() {
506        return dates(MILLISECONDS);
507    }
508
509    /**
510     * Create a generator for date values with the given precision.
511     */
512    public static Generator<Date> dates(TimeUnit precision) {
513        return dates(Long.MIN_VALUE, Long.MAX_VALUE, precision);
514    }
515
516    /**
517     * Create a generator for date values from low to high.
518     */
519    public static Generator<Date> dates(Date low, Date high) {
520        return dates(low.getTime(), high.getTime());
521    }
522
523    /**
524     * Create a generator for date values from low to high.
525     */
526    public static Generator<Date> dates(long low, long high) {
527        return dates(low, high, MILLISECONDS);
528    }
529
530    /**
531     * Create a generator for date values from low to high with the given precision.
532     */
533    public static Generator<Date> dates(Long low, Long high, TimeUnit precision) {
534        return new DateGenerator(precision, low, high, DEFAULT_MAX_TRIES);
535    }
536
537    /**
538     * Create a generator for fixed value generator.
539     */
540    public static <T> Generator<T> fixedValues(T value) {
541        return new FixedValuesGenerator<>(value);
542    }
543
544    /**
545     * Create a fixed value generator returning one of the values from the values
546     * array.
547     */
548    @SafeVarargs
549    public static <T> Generator<T> fixedValues(T... values) {
550        return fixedValues(asList(values));
551    }
552
553    /**
554     * Create a fixed value generator returning one of the values from the values.
555     */
556    public static <T> Generator<T> fixedValues(Iterable<T> values) {
557        return new FixedValuesGenerator<>(values);
558    }
559
560    /**
561     * A cloning generator which uses object serialization to create clones of the
562     * prototype object. For each call a new copy of the prototype will be
563     * generated.
564     */
565    public static <T> Generator<T> clonedValues(T prototype) {
566        return new CloningGenerator<>(prototype);
567    }
568
569    /**
570     * Create a generator of enumeration values.
571     *
572     * @param <T>       Type of enumerations
573     * @param enumClass class of enumeration
574     * @return generator of enum values
575     */
576    public static <T extends Enum<T>> Generator<T> enumValues(Class<T> enumClass) {
577        return enumValues(enumClass, Collections.emptyList());
578    }
579
580    /**
581     * Create a generator of enumeration values.
582     *
583     * @param <T>       Type of enumerations
584     * @param enumClass class of enumeration
585     * @param excluded  excluded values of enumeration
586     * @return generator of enum values
587     */
588    @SafeVarargs
589    public static <T extends Enum<T>> Generator<T> enumValues(Class<T> enumClass, T... excluded) {
590        return enumValues(enumClass, asList(excluded));
591    }
592
593    /**
594     * Create a generator of enumeration values.
595     *
596     * @param <T>            Type of enumerations
597     * @param enumClass      class of enumeration
598     * @param excludedValues excluded values of enumeration
599     * @return generator of enum values
600     */
601    public static <T extends Enum<T>> Generator<T> enumValues(Class<T> enumClass, Iterable<T> excludedValues) {
602        EnumSet<T> excluded = EnumSet.noneOf(enumClass);
603        for (T e : excludedValues) {
604            excluded.add(e);
605        }
606        return new FixedValuesGenerator<>(EnumSet.complementOf(excluded));
607    }
608
609    /**
610     * Create a generator for {@link Object java.lang.Object} instances.
611     * <p>
612     * Note: every invocation of {@link Generator#next()} creates a new instance.
613     * </p>
614     */
615    public static Generator<Object> objects() {
616        return new de.cuioss.test.generator.internal.net.java.quickcheck.generator.support.ObjectGenerator();
617    }
618
619    /**
620     * Create a generator from a {@link ObjectGenerator declarative object generator
621     * definition}.
622     */
623    public static <T> ObjectGenerator<T> objects(Class<T> objectType) {
624        return new ObjectGeneratorImpl<>(objectType);
625    }
626
627    /**
628     * Create a generator from a {@link ObjectGenerator declarative object generator
629     * definition}.
630     * <p>
631     * Default values will be used for all {@link ObjectGenerator#on(Object)
632     * undefined methods}.
633     * </p>
634     */
635    public static <T> ObjectGenerator<T> defaultObjects(Class<T> objectType) {
636        return new ObjectDefaultMappingGenerator<>(objectType);
637    }
638
639    /**
640     * <p>
641     * Create a frequency generator. The frequency of {@link Generator} usage
642     * depends on the generator weight.
643     * </p>
644     *
645     * @param generator pairs of generators and their weights used to created the
646     *                  values
647     * @param <T>       type of values generated by the generators.
648     */
649    public static <T> FrequencyGenerator<T> frequency(Generator<T> generator, int weight) {
650        return new DefaultFrequencyGenerator<>(generator, weight);
651    }
652
653    /**
654     * OneOf is a convenience method for
655     * {@link Generators#frequency(Generator, int)} when all generator share the
656     * same weight.
657     */
658    public static <T> ExtendibleGenerator<T, T> oneOf(Generator<T> generator) {
659        return frequency(generator, 1);
660    }
661
662    /**
663     * Create a generator which will create vectors (here lists) of type T.
664     *
665     * @param <T>  Type of the list values.
666     * @param size Number of element in the vector.
667     */
668    public static <T> Generator<List<T>> vectors(Generator<T> content, int size) {
669        return new ListGenerator<>(content, new FixedValuesGenerator<>(size));
670    }
671
672    /**
673     * Create a generator of pairs of type A for the left value and type B for the
674     * right value.
675     *
676     * @param <A>    Type of left value.
677     * @param <B>    Type of right value.
678     * @param first  Generator for left values.
679     * @param second Generator for right values.
680     */
681    @SuppressWarnings("unchecked")
682    public static <A, B> Generator<Pair<A, B>> pairs(Generator<A> first, Generator<B> second) {
683        final var generator = new TupleGenerator(first, second);
684        return () -> {
685            var next = generator.next();
686            return new Pair<>((A) next[0], (B) next[1]);
687        };
688    }
689
690    /**
691     * Create a generator of pairs where first value &lt;= second value.
692     *
693     * @param <T>     Type of the pair values.
694     * @param content Generator for content of the pair values.
695     */
696    public static <T extends Comparable<T>> Generator<Pair<T, T>> sortedPairs(Generator<T> content) {
697        return new AbstractTransformerGenerator<>(sortedLists(content, 2, 2)) {
698
699            @Override
700            protected Pair<T, T> transform(Generator<List<T>> inputGenerator) {
701                var next = inputGenerator.next();
702                return new Pair<>(next.getFirst(), next.get(1));
703            }
704        };
705    }
706
707    /**
708     * Create a generator of triples of the types A, B and C for first, second and
709     * third value.
710     *
711     * @param <A>    Type of first value.
712     * @param <B>    Type of second value.
713     * @param <C>    Type of third value.
714     * @param first  Generator for first values.
715     * @param second Generator for second values.
716     * @param third  Generator for third values.
717     */
718    @SuppressWarnings("unchecked")
719    public static <A, B, C> Generator<Triple<A, B, C>> triples(Generator<A> first, Generator<B> second,
720            Generator<C> third) {
721        final var generator = new TupleGenerator(first, second, third);
722        return () -> {
723            var next = generator.next();
724            return new Triple<>((A) next[0], (B) next[1], (C) next[2]);
725        };
726    }
727
728    /**
729     * Create a generator returning a combination of a null values and the given
730     * values.
731     *
732     * @param <T> Type of the values generated.
733     */
734    @SafeVarargs
735    public static <T> Generator<T> nullsAnd(T... values) {
736        return nullsAnd(new FixedValuesGenerator<>(asList(values)));
737    }
738
739    /**
740     * Create a generator of triples where first value &lt;= second value &lt;=
741     * third value.
742     *
743     * @param <T>     Type of the triple values.
744     * @param content Generator for content of the triple values.
745     */
746    public static <T extends Comparable<T>> Generator<Triple<T, T, T>> sortedTriple(Generator<T> content) {
747        return new AbstractTransformerGenerator<>(sortedLists(content, 3, 3)) {
748
749            @Override
750            protected Triple<T, T, T> transform(Generator<List<T>> inputGenerator) {
751                var next = inputGenerator.next();
752                return new Triple<>(next.getFirst(), next.get(1), next.get(2));
753            }
754        };
755    }
756
757    /**
758     * Create a generator as a combination of a null value generator and generator
759     * of type T.
760     *
761     * @param <T> Type of the values generated.
762     */
763    public static <T> Generator<T> nullsAnd(Generator<T> generator) {
764        return nullsAnd(generator, 5);
765    }
766
767    /**
768     * Create a generator as a combination of a null value generator and generator
769     * of type T.
770     *
771     * @param <T>    Type of the values generated.
772     * @param weight weight of the provided generator
773     */
774    public static <T> Generator<T> nullsAnd(Generator<T> generator, int weight) {
775        return new DefaultFrequencyGenerator<>(Generators.<T>nulls(), 1).add(generator, weight);
776    }
777
778    /**
779     * Create a generator of sets with values from the content generator.
780     *
781     * @param <T>     type of set elements generated
782     * @param content generator providing the content of sets generated
783     */
784    public static <T> Generator<Set<T>> sets(Generator<? extends T> content) {
785        return new SetGenerator<>(content);
786    }
787
788    /**
789     * Create a generator of sets with values from the content generator.
790     *
791     * @param <T>     type of set elements generated
792     * @param content generator providing the content of sets generated
793     * @param size    size of the sets generated
794     */
795    public static <T> Generator<Set<T>> sets(Generator<? extends T> content, Generator<Integer> size) {
796        return new SetGenerator<>(content, size, DEFAULT_MAX_TRIES);
797    }
798
799    /**
800     * Create a generator of sets with values from the content generator. Length is
801     * between high and low.
802     *
803     * @param <T>     type of set elements generated
804     * @param content generator providing the content of sets generated
805     * @param low     minimal size
806     * @param high    max size
807     */
808    public static <T> Generator<Set<T>> sets(Generator<? extends T> content, int low, int high) {
809        return new SetGenerator<>(content, integers(low, high), DEFAULT_MAX_TRIES);
810    }
811
812    /**
813     * Create a generator of sets that are not empty.
814     *
815     * @param <T>     type of set elements generated
816     * @param content generator providing the content of sets generated
817     */
818    public static <T> Generator<Set<T>> nonEmptySets(Generator<? extends T> content) {
819        return sets(content, 1, SetGenerator.MAX_SIZE);
820    }
821
822    @SafeVarargs
823    public static <T> Generator<Set<T>> sets(T... superset) {
824        return sets(asList(superset));
825    }
826
827    /**
828     * Create a generator of subsets from a given set.
829     *
830     * @param <T>      type of set elements generated
831     * @param superset of the generated set
832     */
833    public static <T> Generator<Set<T>> sets(Iterable<T> superset) {
834        return new SubsetGenerator<>(superset);
835    }
836
837    /**
838     * Create a generator of subsets from a given set.
839     *
840     * @param <T>      type of set elements generated
841     * @param superset of the generated set
842     * @param size     of the generated set
843     */
844    public static <T> Generator<Set<T>> sets(Iterable<T> superset, Generator<Integer> size) {
845        return new SubsetGenerator<>(superset, size);
846    }
847
848    /**
849     * Create a generator that produces lists of duplicates.
850     *
851     * @return a list derived from the input values. At least one input value is
852     *         more than once in the resulting list.
853     */
854    @SafeVarargs
855    public static <T> Generator<List<T>> duplicates(T... input) {
856        return new DuplicateGenerator<>(asList(input));
857    }
858
859    /**
860     * Create a generator that produces lists of duplicates.
861     *
862     * @return a list derived from the input values. At least one input value is
863     *         more than once in the resulting list.
864     */
865    public static <T> Generator<List<T>> duplicates(Iterable<T> input) {
866        return new DuplicateGenerator<>(input);
867    }
868
869    /**
870     * Create a generator of iterators.
871     *
872     * <p>
873     * Values of the elements will be taken from the content generator.
874     * </p>
875     *
876     * @param <T>     type of iterator elements generated
877     * @param content generator providing the content of iterators generated
878     */
879    public static <T> Generator<Iterator<T>> iterators(Generator<? extends T> content) {
880        return new IteratorGenerator<>(content);
881    }
882
883    /**
884     * Create a generator of iterators.
885     *
886     * <p>
887     * Values of the elements will be taken from the content generator. The
888     * generated iterator will have at least one element.
889     * </p>
890     *
891     * @param <T>     type of iterator elements generated
892     * @param content generator providing the content of iterators generated
893     */
894    public static <T> Generator<Iterator<T>> nonEmptyIterators(Generator<T> content) {
895        return new IteratorGenerator<>(content, 1, IteratorGenerator.MAX_SIZE);
896    }
897
898    /**
899     * Create a generator of iterators.
900     *
901     * <p>
902     * Values of the elements will be taken from the content generator. The length
903     * of the iterators will be determined with the size generator.
904     * </p>
905     *
906     * @param <T>     type of iterator elements generated
907     * @param content generator providing the content of iterators generated
908     * @param size    used to determine the number of elements of the iterator
909     */
910    public static <T> Generator<Iterator<T>> iterators(Generator<? extends T> content, Generator<Integer> size) {
911        return new IteratorGenerator<>(content, size);
912    }
913
914    /**
915     * Create a generator of lists with values from the content generator. Length
916     * values of lists generated will be created with {@link Distribution#UNIFORM}.
917     *
918     * @param <T>     type of list elements generated
919     * @param content generator providing the content of lists generated
920     */
921    public static <T> Generator<List<T>> lists(Generator<? extends T> content) {
922        return new ListGenerator<>(content);
923    }
924
925    /**
926     * Create a generator of non-empty lists with values from the content generator.
927     * Length values of lists generated will be created with
928     * {@link Distribution#UNIFORM}.
929     *
930     * @param <T>     type of list elements generated
931     * @param content generator providing the content of lists generated
932     */
933    public static <T> Generator<List<T>> nonEmptyLists(Generator<? extends T> content) {
934        return lists(content, positiveIntegers(MAX_SIZE));
935    }
936
937    /**
938     * Create a generator of lists with values from the content generator. Length
939     * values of lists generated will be created with size generator.
940     *
941     * @param <T>     type of list elements generated
942     * @param content generator providing the content of lists generated
943     * @param size    integer used to determine the list size
944     */
945    public static <T> Generator<List<T>> lists(Generator<? extends T> content, Generator<Integer> size) {
946        return new ListGenerator<>(content, size);
947    }
948
949    /**
950     * Create a generator of lists with values from the content generator. Length is
951     * between high and low.
952     *
953     * @param <T>     type of list elements generated
954     * @param content generator providing the content of lists generated
955     * @param low     minimal size
956     * @param high    max size
957     */
958    public static <T> Generator<List<T>> lists(Generator<? extends T> content, int low, int high) {
959        return lists(content, new IntegerGenerator(low, high));
960    }
961
962    /**
963     * Create a generator of lists with values from the content generator. Length is
964     * at least low.
965     *
966     * @param <T>     type of list elements generated
967     * @param content generator providing the content of lists generated
968     * @param low     minimal size. If low is larger than
969     *                {@link Generators#DEFAULT_COLLECTION_MAX_SIZE} then it is the
970     *                upper size bound as well.
971     */
972    public static <T> Generator<List<T>> lists(Generator<? extends T> content, int low) {
973        return lists(content, low, Math.max(low, ListGenerator.MAX_SIZE));
974    }
975
976    /**
977     * Create a generator of sorted lists with values from the content generator.
978     *
979     * @param <T>     type of list elements generated
980     * @param content generator providing the content of lists generated
981     */
982    public static <T extends Comparable<T>> Generator<List<T>> sortedLists(Generator<T> content) {
983        return new SortedListGenerator<>(content);
984
985    }
986
987    /**
988     * Create a generator of sorted lists with values from the content generator.
989     * Length is between high and low.
990     *
991     * @param <T>     type of list elements generated
992     * @param content generator providing the content of lists generated
993     * @param low     minimal size
994     * @param high    max size
995     */
996    public static <T extends Comparable<T>> Generator<List<T>> sortedLists(Generator<T> content, int low, int high) {
997        return sortedLists(content, integers(low, high));
998
999    }
1000
1001    /**
1002     * Create a generator of sorted lists with values from the content generator.
1003     * Length is between high and low.
1004     *
1005     * @param <T>     type of list elements generated
1006     * @param content generator providing the content of lists generated
1007     * @param size    integer used to determine the list size
1008     */
1009    public static <T extends Comparable<T>> Generator<List<T>> sortedLists(Generator<T> content,
1010            Generator<Integer> size) {
1011        return new SortedListGenerator<>(content, size);
1012    }
1013
1014    /**
1015     * Create a generator of arrays with values from the content generator. Length
1016     * values of array generated will be created with {@link Distribution#UNIFORM}.
1017     *
1018     * @param <T>     type of arrays elements generated
1019     * @param content generator providing the content of arrays generated
1020     * @param type    type of arrays generated
1021     */
1022    public static <T> Generator<T[]> arrays(Generator<? extends T> content, Class<T> type) {
1023        return new ArrayGenerator<>(content, type);
1024    }
1025
1026    /**
1027     * Create a generator of arrays that are not empty.
1028     *
1029     * @param <T>     type of arrays elements generated
1030     * @param content generator providing the content of arrays generated
1031     * @param type    type of arrays generated
1032     */
1033    public static <T> Generator<T[]> nonEmptyArrays(Generator<? extends T> content, Class<T> type) {
1034        return arrays(content, positiveIntegers(MAX_SIZE), type);
1035    }
1036
1037    /**
1038     * Create a generator of arrays with values from the content generator. Length
1039     * values of arrays generated will be created with size generator.
1040     *
1041     * @param <T>     type of arrays elements generated
1042     * @param content generator providing the content of arrays generated
1043     * @param size    integer used to determine the array size
1044     * @param type    type of arrays generated
1045     */
1046    public static <T> Generator<T[]> arrays(Generator<? extends T> content, Generator<Integer> size, Class<T> type) {
1047        return new ArrayGenerator<>(content, size, type);
1048    }
1049
1050    /**
1051     * Create a generator of byte arrays. The length of arrays generated will be
1052     * determined by the {@link ByteArrayGenerator#MIN_SIZE} and
1053     * {@link ByteArrayGenerator#MAX_SIZE} constants.
1054     *
1055     */
1056    public static Generator<byte[]> byteArrays() {
1057        return new ByteArrayGenerator();
1058    }
1059
1060    /**
1061     * Create a generator of byte arrays. Length values of arrays generated will be
1062     * created with size generator.
1063     *
1064     * @param size integer used to determine the array size
1065     */
1066    public static Generator<byte[]> byteArrays(Generator<Integer> size) {
1067        return new ByteArrayGenerator(size);
1068    }
1069
1070    /**
1071     * Create a generator of byte arrays. Length values of arrays generated will be
1072     * created with size generator.
1073     *
1074     * @param size    integer used to determine the array size
1075     * @param content generator for the byte array content
1076     */
1077    public static Generator<byte[]> byteArrays(Generator<Byte> content, Generator<Integer> size) {
1078        return new ByteArrayGenerator(content, size);
1079    }
1080
1081    /**
1082     * Create a generator of integer arrays.
1083     *
1084     */
1085    public static Generator<int[]> intArrays() {
1086        return new IntegerArrayGenerator();
1087    }
1088
1089    /**
1090     * Create a generator of integer arrays. Length values of arrays generated will
1091     * be created with size generator.
1092     *
1093     * @param size integer used to determine the array size
1094     */
1095    public static Generator<int[]> intArrays(Generator<Integer> size) {
1096        return new IntegerArrayGenerator(size);
1097    }
1098
1099    /**
1100     * Create a generator of integer arrays. Length values of arrays generated will
1101     * be created with size generator.
1102     *
1103     * @param size    integer used to determine the array size
1104     * @param content generator for the integer array content
1105     */
1106    public static Generator<int[]> intArrays(Generator<Integer> content, Generator<Integer> size) {
1107        return new IntegerArrayGenerator(content, size);
1108    }
1109
1110    /**
1111     * Create a generator of {@link Map maps}.
1112     *
1113     * <p>
1114     * This is a generator for simple maps where the values are not related to the
1115     * keys.
1116     * </p>
1117     *
1118     * @param keys   {@link Generator} for the keys of the map
1119     * @param values {@link Generator} for the values of the map
1120     */
1121    public static <K, V> Generator<Map<K, V>> maps(Generator<K> keys, Generator<V> values) {
1122        return new MapGenerator<>(keys, values);
1123    }
1124
1125    /**
1126     * Create a generator of {@link Map maps}.
1127     *
1128     * <p>
1129     * This is a generator for simple maps where the values are not related to the
1130     * keys.
1131     * </p>
1132     *
1133     * @param keys   {@link Generator} for the keys of the map
1134     * @param values {@link Generator} for the values of the map
1135     * @param size   integer used to determine the size of the generated map
1136     */
1137    public static <K, V> Generator<Map<K, V>> maps(Generator<K> keys, Generator<V> values, Generator<Integer> size) {
1138        return new MapGenerator<>(keys, values, size);
1139    }
1140
1141    /**
1142     * Create a generator of maps from a given map.
1143     *
1144     * <p>
1145     * The entry set of the generated maps are subsets of the given map's entry set.
1146     * </p>
1147     * 
1148     * @param supermap of the generated maps
1149     */
1150    public static <K, V> Generator<Map<K, V>> maps(Map<K, V> supermap) {
1151        return new SubmapGenerator<>(supermap);
1152    }
1153
1154    /**
1155     * Create a generator of maps from a given map.
1156     * <p>
1157     * The entry set of the generated maps are subsets of the given map's entry set.
1158     * </p>
1159     *
1160     * @param supermap of the generated maps
1161     * @param sizes    of the generated maps
1162     */
1163    public static <K, V> Generator<Map<K, V>> maps(Map<K, V> supermap, Generator<Integer> sizes) {
1164        return new SubmapGenerator<>(supermap, sizes);
1165    }
1166
1167    /**
1168     * Create a deterministic generator which guarantees that all values from the
1169     * ensuredValues collection will be returned if enough calls to
1170     * {@link Generator#next()} are issued (i.e. ensuredValues.size() &lt;= # of
1171     * runs). The order of values is undefined.
1172     *
1173     * @param <T> type of values return by the generator
1174     */
1175    public static <T> StatefulGenerator<T> ensureValues(Iterable<T> ensuredValues) {
1176        return new EnsuredValuesGenerator<>(ensuredValues);
1177    }
1178
1179    /**
1180     * Create a deterministic generator which guarantees that all values from the
1181     * ensuredValues array will be returned if enough calls to
1182     * {@link Generator#next()} are issued (i.e. ensuredValues.size() &lt;= # of
1183     * runs). The order of values is undefined.
1184     *
1185     * @param <T> type of values return by the generator
1186     */
1187    @SafeVarargs
1188    public static <T> StatefulGenerator<T> ensureValues(T... content) {
1189        return ensureValues(asList(content));
1190    }
1191
1192    /**
1193     * <p>
1194     * Create a deterministic generator which guarantees that all values from the
1195     * ensuredValues collection will be returned if enough calls to
1196     * {@link Generator#next()} are issued (i.e. ensuredValues.size() &lt;= # of
1197     * runs). The order of values is undefined.
1198     * </p>
1199     * <p>
1200     * If all values of ensuredValues are generated calls to
1201     * {@link Generator#next()} will return values from the otherValues generator.
1202     * </p>
1203     *
1204     * @param <T> type of values return by the generator
1205     */
1206    public static <T> StatefulGenerator<T> ensureValues(Iterable<T> ensuredValues, Generator<T> otherValues) {
1207        return new EnsuredValuesGenerator<>(ensuredValues, otherValues);
1208    }
1209
1210    /**
1211     * <p>
1212     * Create a generator which guarantees that all values from the ensuredValues
1213     * will be returned in a defined window when enough calls to
1214     * {@link Generator#next()} are issued.
1215     * </p>
1216     * <p>
1217     * The order of values is undefined. All other values in the window and after
1218     * the window are taken from the {@link Generator generator otherValues}.
1219     * </p>
1220     *
1221     * @param <T>    type of values return by the generator
1222     * @param window After window number of calls to {@link Generator#next()} it is
1223     *               guaranteed that all ensured values were returned.
1224     */
1225    public static <T> StatefulGenerator<T> ensureValues(Iterable<T> ensuredValues, int window,
1226            Generator<T> otherValues) {
1227        return new EnsuredValuesGenerator<>(ensuredValues, window, otherValues);
1228    }
1229
1230    /**
1231     * <p>
1232     * Create a generator that ensures unique values.
1233     * </p>
1234     * <p>
1235     * The actual values are created with an arbitrary generator.
1236     * </p>
1237     * <p>
1238     * Note: unique generator depends on valid implementation of equals and hashCode
1239     * method of the content type generated.
1240     * </p>
1241     *
1242     * @param <T>       type of values return by the generator
1243     * @param generator used to create the raw values. This generator can create
1244     *                  duplicate values
1245     * @param tries     Number of tries to create a new unique value. After this
1246     *                  number of tries is exceeded the generation aborts with a
1247     *                  {@link GeneratorException}.
1248     * @return unique generator instance
1249     */
1250    public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator, int tries) {
1251        return new UniqueValuesGenerator<>(generator, tries);
1252    }
1253
1254    /**
1255     * <p>
1256     * Create a generator that ensures unique values.
1257     * </p>
1258     * <p>
1259     * The actual values are created with an arbitrary generator.
1260     * </p>
1261     * <p>
1262     * Unique generator depends on the {@link Comparator} implementation to decide
1263     * if two instances are the same (i.e. when the comparator returns 0 for
1264     * {@link Comparator#compare(Object, Object)}).
1265     * </p>
1266     *
1267     * @param <T>        type of values returned by the generator
1268     * @param generator  used to create the raw values. This generator can create
1269     *                   duplicate values
1270     * @param comparator that decides if two values are of the same equivalence
1271     *                   class.
1272     * @param tries      Number of tries to create a new unique value. After this
1273     *                   number of tries is exceeded the generation aborts with a
1274     *                   {@link GeneratorException}.
1275     * @return unique generator instance
1276     */
1277    public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator, Comparator<? super T> comparator,
1278            int tries) {
1279        return new UniqueComparableValuesGenerator<>(generator, comparator, tries);
1280    }
1281
1282    /**
1283     * <p>
1284     * Create a generator that ensures unique values.
1285     * </p>
1286     * <p>
1287     * The actual values are created with an arbitrary generator.
1288     * </p>
1289     * <p>
1290     * Unique generator depends on the {@link Comparator} implementation to decide
1291     * if two instances are the same (i.e. when the comparator returns 0 for
1292     * {@link Comparator#compare(Object, Object)}).
1293     * </p>
1294     *
1295     * @param <T>        type of values returned by the generator
1296     * @param generator  used to create the raw values. This generator can create
1297     *                   duplicate values
1298     * @param comparator that decides if two values are of the same equivalence
1299     *                   class.
1300     * @return unique generator instance
1301     */
1302    public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator, Comparator<? super T> comparator) {
1303        return uniqueValues(generator, comparator, DEFAULT_MAX_TRIES);
1304    }
1305
1306    /**
1307     * <p>
1308     * Create a generator that ensures unique values
1309     * </p>
1310     * <p>
1311     * The actual values are created with an arbitrary generator.
1312     * </p>
1313     * <p>
1314     * Note: unique generator depends on valid implementation of equals and hashCode
1315     * method of the content type generated.
1316     * </p>
1317     *
1318     * @param <T>       type of values return by the generator
1319     * @param generator used to create the raw values. This generator can create
1320     *                  duplicate values
1321     * @return unique generator instance
1322     */
1323    public static <T> StatefulGenerator<T> uniqueValues(Generator<T> generator) {
1324        return new UniqueValuesGenerator<>(generator, DEFAULT_MAX_TRIES);
1325    }
1326
1327    /**
1328     * Create a generator that omits a given value.
1329     *
1330     * @param generator used to create the raw values.
1331     * @param excluded  value. This value will not be returned.
1332     */
1333    public static <T> Generator<T> excludeValues(Generator<T> generator, T excluded) {
1334        return excludeValues(generator, List.of(excluded));
1335    }
1336
1337    /**
1338     * Create a generator that omits a given set of values.
1339     *
1340     * @param generator used to create the raw values.
1341     * @param excluded  values. These values will not be returned.
1342     */
1343    @SafeVarargs
1344    public static <T> Generator<T> excludeValues(Generator<T> generator, T... excluded) {
1345        return excludeValues(generator, asList(excluded));
1346    }
1347
1348    /**
1349     * Create a generator that omits a given set of values.
1350     *
1351     * @param values   of generator
1352     * @param excluded values. These values will not be returned.
1353     */
1354    @SafeVarargs
1355    public static <T> Generator<T> excludeValues(Iterable<T> values, T... excluded) {
1356        return excludeValues(values, asList(excluded));
1357    }
1358
1359    /**
1360     * Create a generator that omits a given set of values.
1361     *
1362     * @param values   of generator
1363     * @param excluded values. These values will not be returned.
1364     */
1365    public static <T> Generator<T> excludeValues(Iterable<T> values, Iterable<T> excluded) {
1366        return excludeValues(fixedValues(values), excluded);
1367    }
1368
1369    /**
1370     * Create a generator that omits a given set of values.
1371     *
1372     * @param generator used to create the raw values.
1373     * @param excluded  values. These values will not be returned.
1374     */
1375    public static <T> Generator<T> excludeValues(Generator<T> generator, Iterable<T> excluded) {
1376        return new ExcludingGenerator<>(generator, excluded, DEFAULT_MAX_TRIES);
1377    }
1378
1379    /**
1380     * A generator for a lists. The values in the lists are strictly increasing.
1381     *
1382     * <p>
1383     * For every element x in the list: x(n) &lt; x(n+1).
1384     * </p>
1385     *
1386     * @param input values generator
1387     */
1388    public static <T extends Comparable<T>> Generator<List<T>> strictlyOrdered(Generator<T> input) {
1389        return strictlyOrdered(input, 0, DEFAULT_COLLECTION_MAX_SIZE);
1390    }
1391
1392    /**
1393     * A generator for a lists. The values in the lists are strictly increasing.
1394     *
1395     * <p>
1396     * For every element x in the list: x(n) &lt; x(n+1).
1397     * </p>
1398     *
1399     * @param input values generator
1400     * @param low   minimum size of the lists
1401     * @param high  maximum size of the lists
1402     */
1403    public static <T extends Comparable<T>> Generator<List<T>> strictlyOrdered(Generator<T> input, int low, int high) {
1404        Comparator<T> natural = Comparable::compareTo;
1405        return strictlyOrdered(input, natural, new IntegerGenerator(low, high));
1406    }
1407
1408    /**
1409     * A generator for a lists. The values in the lists are strictly increasing.
1410     *
1411     * <p>
1412     * For every element x in the list: x(n) &lt; x(n+1).
1413     * </p>
1414     *
1415     * <p>
1416     * This {@link Generator} can be used to generate a list of strictly decreasing
1417     * values:
1418     * {@code Generators.strictlyOrdered(ts, Collections.<T> reverseOrder());}
1419     * </p>
1420     *
1421     *
1422     * @param input      values generator
1423     * @param comparator that orders the values
1424     */
1425    public static <T> Generator<List<T>> strictlyOrdered(Generator<T> input, Comparator<T> comparator) {
1426        return strictlyOrdered(input, comparator, new IntegerGenerator(0, DEFAULT_COLLECTION_MAX_SIZE));
1427    }
1428
1429    /**
1430     * A generator for a lists. The values in the lists are strictly increasing.
1431     * <p>
1432     * For every element x in the list: x(n) &lt; x(n+1).
1433     * </p>
1434     *
1435     * @param input      values generator
1436     * @param comparator that orders the values
1437     * @param size       of the resulting lists
1438     */
1439    public static <T> Generator<List<T>> strictlyOrdered(Generator<T> input, Comparator<T> comparator,
1440            Generator<Integer> size) {
1441        return new StrictlyOrderedGenerator<>(input, comparator, size);
1442    }
1443}