001    package fj.test;
002    
003    import fj.F;
004    import fj.F2;
005    import fj.F3;
006    import fj.F4;
007    import fj.F5;
008    import fj.F6;
009    import fj.F7;
010    import fj.F8;
011    import static fj.Function.curry;
012    import static fj.P.p;
013    import fj.P1;
014    import fj.P2;
015    import fj.P3;
016    import fj.P4;
017    import fj.P5;
018    import fj.P6;
019    import fj.P7;
020    import fj.P8;
021    import fj.data.Array;
022    import static fj.data.Array.array;
023    import fj.data.Either;
024    import fj.data.List;
025    import static fj.data.List.fromString;
026    import static fj.data.List.nil;
027    import fj.data.Option;
028    import fj.data.Stream;
029    
030    import static fj.test.Variant.variant;
031    
032    import static java.lang.Double.doubleToRawLongBits;
033    import static java.lang.Float.floatToRawIntBits;
034    import java.math.BigDecimal;
035    import java.math.BigInteger;
036    import java.sql.Time;
037    import java.sql.Timestamp;
038    import java.util.ArrayList;
039    import java.util.BitSet;
040    import java.util.Calendar;
041    import java.util.Date;
042    import java.util.EnumMap;
043    import java.util.EnumSet;
044    import java.util.GregorianCalendar;
045    import java.util.HashMap;
046    import java.util.HashSet;
047    import java.util.Hashtable;
048    import java.util.IdentityHashMap;
049    import java.util.LinkedHashMap;
050    import java.util.LinkedHashSet;
051    import java.util.LinkedList;
052    import java.util.PriorityQueue;
053    import java.util.Properties;
054    import java.util.Stack;
055    import java.util.TreeMap;
056    import java.util.TreeSet;
057    import java.util.Vector;
058    import java.util.WeakHashMap;
059    import java.util.concurrent.ArrayBlockingQueue;
060    import java.util.concurrent.ConcurrentHashMap;
061    import java.util.concurrent.ConcurrentLinkedQueue;
062    import java.util.concurrent.CopyOnWriteArrayList;
063    import java.util.concurrent.CopyOnWriteArraySet;
064    import java.util.concurrent.DelayQueue;
065    import java.util.concurrent.Delayed;
066    import java.util.concurrent.LinkedBlockingQueue;
067    import java.util.concurrent.PriorityBlockingQueue;
068    import java.util.concurrent.SynchronousQueue;
069    
070    /**
071     * Transforms a type and a generator to produce a new generator. This function is used to generate
072     * {@link Arbitrary arbitrary} functions.
073     *
074     * @version %build.number%<br>
075     *          <ul>
076     *          <li>$LastChangedRevision: 122 $</li>
077     *          <li>$LastChangedDate: 2009-04-25 08:24:38 +1000 (Sat, 25 Apr 2009) $</li>
078     *          <li>$LastChangedBy: runarorama $</li>
079     *          </ul>
080     */
081    public abstract class Coarbitrary<A> {
082      /**
083       * Transforms the given value and generator to a new generator with a high probability of being
084       * independent.
085       *
086       * @param a The value to produce the generator from.
087       * @param g The generator to produce the new generator from.
088       * @return A new generator with a high probability of being independent.
089       */
090      public abstract <B> Gen<B> coarbitrary(A a, Gen<B> g);
091    
092      /**
093       * A curried version of {@link #coarbitrary(Object, Gen)}.
094       *
095       * @param a The value to produce the generator from.
096       * @return A curried version of {@link #coarbitrary(Object, Gen)}.
097       */
098      public <B> F<Gen<B>, Gen<B>> coarbitrary(final A a) {
099        return new F<Gen<B>, Gen<B>>() {
100          public Gen<B> f(final Gen<B> g) {
101            return coarbitrary(a, g);
102          }
103        };
104      }
105    
106      /**
107       * Composes the given function with this coarbitrary to produce a new coarbitrary.
108       *
109       * @param f The function to compose.
110       * @return A new coarbitrary composed with the given function.
111       */
112      public <B> Coarbitrary<B> compose(final F<B, A> f) {
113        return new Coarbitrary<B>() {
114          public <X> Gen<X> coarbitrary(final B b, final Gen<X> g) {
115            return Coarbitrary.this.coarbitrary(f.f(b), g);
116          }
117        };
118      }
119    
120      /**
121       * Co-maps this coarbitrary using the given function.
122       *
123       * @param f The function to co-map with.
124       * @return A co-mapped coarbitrary.
125       */
126      public <B> Coarbitrary<B> comap(final F<B, A> f) {
127        return new Coarbitrary<B>() {
128          public <X> Gen<X> coarbitrary(final B b, final Gen<X> g) {
129            return Coarbitrary.this.coarbitrary(f.f(b), g);
130          }
131        };
132      }
133    
134      /**
135       * A coarbitrary for a function.
136       *
137       * @param a An arbitrary for the domain of the function.
138       * @param c A coarbitrary for the codomain of the function.
139       * @return A coarbitrary for a function.
140       */
141      public static <A, B> Coarbitrary<F<A, B>> coarbF(final Arbitrary<A> a, final Coarbitrary<B> c) {
142        return new Coarbitrary<F<A, B>>() {
143          public <X> Gen<X> coarbitrary(final F<A, B> f, final Gen<X> g) {
144            return a.gen.bind(new F<A, Gen<X>>() {
145              public Gen<X> f(final A a) {
146                return c.coarbitrary(f.f(a), g);
147              }
148            });
149          }
150        };
151      }
152    
153      /**
154       * A coarbitrary for a function-2.
155       *
156       * @param aa An arbitrary for part of the domain of the function.
157       * @param ab An arbitrary for part of the domain of the function.
158       * @param c  A coarbitrary for the codomain of the function.
159       * @return A coarbitrary for a function-2.
160       */
161      public static <A, B, C> Coarbitrary<F2<A, B, C>> coarbF2(final Arbitrary<A> aa, final Arbitrary<B> ab,
162                                                               final Coarbitrary<C> c) {
163        return new Coarbitrary<F2<A, B, C>>() {
164          public <X> Gen<X> coarbitrary(final F2<A, B, C> f, final Gen<X> g) {
165            return coarbF(aa, coarbF(ab, c)).coarbitrary(curry(f), g);
166          }
167        };
168      }
169    
170      /**
171       * A coarbitrary for a function-3.
172       *
173       * @param aa An arbitrary for part of the domain of the function.
174       * @param ab An arbitrary for part of the domain of the function.
175       * @param ac An arbitrary for part of the domain of the function.
176       * @param c  A coarbitrary for the codomain of the function.
177       * @return A coarbitrary for a function-3.
178       */
179      public static <A, B, C, D> Coarbitrary<F3<A, B, C, D>> coarbF3(final Arbitrary<A> aa, final Arbitrary<B> ab,
180                                                                     final Arbitrary<C> ac, final Coarbitrary<D> c) {
181        return new Coarbitrary<F3<A, B, C, D>>() {
182          public <X> Gen<X> coarbitrary(final F3<A, B, C, D> f, final Gen<X> g) {
183            return coarbF(aa, coarbF(ab, coarbF(ac, c))).coarbitrary(curry(f), g);
184          }
185        };
186      }
187    
188      /**
189       * A coarbitrary for a function-4.
190       *
191       * @param aa An arbitrary for part of the domain of the function.
192       * @param ab An arbitrary for part of the domain of the function.
193       * @param ac An arbitrary for part of the domain of the function.
194       * @param ad An arbitrary for part of the domain of the function.
195       * @param c  A coarbitrary for the codomain of the function.
196       * @return A coarbitrary for a function-4.
197       */
198      public static <A, B, C, D, E> Coarbitrary<F4<A, B, C, D, E>> coarbF4(final Arbitrary<A> aa, final Arbitrary<B> ab,
199                                                                           final Arbitrary<C> ac, final Arbitrary<D> ad,
200                                                                           final Coarbitrary<E> c) {
201        return new Coarbitrary<F4<A, B, C, D, E>>() {
202          public <X> Gen<X> coarbitrary(final F4<A, B, C, D, E> f, final Gen<X> g) {
203            return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, c)))).coarbitrary(curry(f), g);
204          }
205        };
206      }
207    
208      /**
209       * A coarbitrary for a function-5.
210       *
211       * @param aa An arbitrary for part of the domain of the function.
212       * @param ab An arbitrary for part of the domain of the function.
213       * @param ac An arbitrary for part of the domain of the function.
214       * @param ad An arbitrary for part of the domain of the function.
215       * @param ae An arbitrary for part of the domain of the function.
216       * @param c  A coarbitrary for the codomain of the function.
217       * @return A coarbitrary for a function-5.
218       */
219      public static <A, B, C, D, E, F$> Coarbitrary<F5<A, B, C, D, E, F$>> coarbF5(final Arbitrary<A> aa,
220                                                                                   final Arbitrary<B> ab,
221                                                                                   final Arbitrary<C> ac,
222                                                                                   final Arbitrary<D> ad,
223                                                                                   final Arbitrary<E> ae,
224                                                                                   final Coarbitrary<F$> c) {
225        return new Coarbitrary<F5<A, B, C, D, E, F$>>() {
226          public <X> Gen<X> coarbitrary(final F5<A, B, C, D, E, F$> f, final Gen<X> g) {
227            return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, c))))).coarbitrary(curry(f), g);
228          }
229        };
230      }
231    
232      /**
233       * A coarbitrary for a function-6.
234       *
235       * @param aa An arbitrary for part of the domain of the function.
236       * @param ab An arbitrary for part of the domain of the function.
237       * @param ac An arbitrary for part of the domain of the function.
238       * @param ad An arbitrary for part of the domain of the function.
239       * @param ae An arbitrary for part of the domain of the function.
240       * @param af An arbitrary for part of the domain of the function.
241       * @param c  A coarbitrary for the codomain of the function.
242       * @return A coarbitrary for a function-6.
243       */
244      public static <A, B, C, D, E, F$, G> Coarbitrary<F6<A, B, C, D, E, F$, G>> coarbF6(final Arbitrary<A> aa,
245                                                                                         final Arbitrary<B> ab,
246                                                                                         final Arbitrary<C> ac,
247                                                                                         final Arbitrary<D> ad,
248                                                                                         final Arbitrary<E> ae,
249                                                                                         final Arbitrary<F$> af,
250                                                                                         final Coarbitrary<G> c) {
251        return new Coarbitrary<F6<A, B, C, D, E, F$, G>>() {
252          public <X> Gen<X> coarbitrary(final F6<A, B, C, D, E, F$, G> f, final Gen<X> g) {
253            return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, c)))))).coarbitrary(curry(f), g);
254          }
255        };
256      }
257    
258      /**
259       * A coarbitrary for a function-7.
260       *
261       * @param aa An arbitrary for part of the domain of the function.
262       * @param ab An arbitrary for part of the domain of the function.
263       * @param ac An arbitrary for part of the domain of the function.
264       * @param ad An arbitrary for part of the domain of the function.
265       * @param ae An arbitrary for part of the domain of the function.
266       * @param af An arbitrary for part of the domain of the function.
267       * @param ag An arbitrary for part of the domain of the function.
268       * @param c  A coarbitrary for the codomain of the function.
269       * @return A coarbitrary for a function-7.
270       */
271      public static <A, B, C, D, E, F$, G, H> Coarbitrary<F7<A, B, C, D, E, F$, G, H>> coarbF7(final Arbitrary<A> aa,
272                                                                                               final Arbitrary<B> ab,
273                                                                                               final Arbitrary<C> ac,
274                                                                                               final Arbitrary<D> ad,
275                                                                                               final Arbitrary<E> ae,
276                                                                                               final Arbitrary<F$> af,
277                                                                                               final Arbitrary<G> ag,
278                                                                                               final Coarbitrary<H> c) {
279        return new Coarbitrary<F7<A, B, C, D, E, F$, G, H>>() {
280          public <X> Gen<X> coarbitrary(final F7<A, B, C, D, E, F$, G, H> f, final Gen<X> g) {
281            return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, c)))))))
282                .coarbitrary(curry(f), g);
283          }
284        };
285      }
286    
287      /**
288       * A coarbitrary for a function-8.
289       *
290       * @param aa An arbitrary for part of the domain of the function.
291       * @param ab An arbitrary for part of the domain of the function.
292       * @param ac An arbitrary for part of the domain of the function.
293       * @param ad An arbitrary for part of the domain of the function.
294       * @param ae An arbitrary for part of the domain of the function.
295       * @param af An arbitrary for part of the domain of the function.
296       * @param ag An arbitrary for part of the domain of the function.
297       * @param ah An arbitrary for part of the domain of the function.
298       * @param c  A coarbitrary for the codomain of the function.
299       * @return A coarbitrary for a function-8.
300       */
301      public static <A, B, C, D, E, F$, G, H, I> Coarbitrary<F8<A, B, C, D, E, F$, G, H, I>> coarbF8(final Arbitrary<A> aa,
302                                                                                                     final Arbitrary<B> ab,
303                                                                                                     final Arbitrary<C> ac,
304                                                                                                     final Arbitrary<D> ad,
305                                                                                                     final Arbitrary<E> ae,
306                                                                                                     final Arbitrary<F$> af,
307                                                                                                     final Arbitrary<G> ag,
308                                                                                                     final Arbitrary<H> ah,
309                                                                                                     final Coarbitrary<I> c) {
310        return new Coarbitrary<F8<A, B, C, D, E, F$, G, H, I>>() {
311          public <X> Gen<X> coarbitrary(final F8<A, B, C, D, E, F$, G, H, I> f, final Gen<X> g) {
312            return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, coarbF(ah, c))))))))
313                .coarbitrary(curry(f), g);
314          }
315        };
316      }
317    
318      /**
319       * A coarbitrary for booleans.
320       */
321      public static final Coarbitrary<Boolean> coarbBoolean = new Coarbitrary<Boolean>() {
322        public <B> Gen<B> coarbitrary(final Boolean b, final Gen<B> g) {
323          return variant(b ? 0 : 1, g);
324        }
325      };
326    
327      /**
328       * A coarbitrary for integers.
329       */
330      public static final Coarbitrary<Integer> coarbInteger = new Coarbitrary<Integer>() {
331        public <B> Gen<B> coarbitrary(final Integer i, final Gen<B> g) {
332          return variant(i >= 0 ? 2 * i : -2 * i + 1, g);
333        }
334      };
335    
336      /**
337       * A coarbitrary for bytes.
338       */
339      public static final Coarbitrary<Byte> coarbByte = new Coarbitrary<Byte>() {
340        public <B> Gen<B> coarbitrary(final Byte b, final Gen<B> g) {
341          return variant(b >= 0 ? 2 * b : -2 * b + 1, g);
342        }
343      };
344    
345      /**
346       * A coarbitrary for shorts.
347       */
348      public static final Coarbitrary<Short> coarbShort = new Coarbitrary<Short>() {
349        public <B> Gen<B> coarbitrary(final Short s, final Gen<B> g) {
350          return variant(s >= 0 ? 2 * s : -2 * s + 1, g);
351        }
352      };
353    
354      /**
355       * A coarbitrary for longs.
356       */
357      public static final Coarbitrary<Long> coarbLong = new Coarbitrary<Long>() {
358        public <B> Gen<B> coarbitrary(final Long l, final Gen<B> g) {
359          return variant(l >= 0L ? 2L * l : -2L * l + 1L, g);
360        }
361      };
362    
363      /**
364       * A coarbitrary for characters.
365       */
366      public static final Coarbitrary<Character> coarbCharacter = new Coarbitrary<Character>() {
367        public <B> Gen<B> coarbitrary(final Character c, final Gen<B> g) {
368          return variant(c << 1, g);
369        }
370      };
371    
372      /**
373       * A coarbitrary for floats.
374       */
375      public static final Coarbitrary<Float> coarbFloat = new Coarbitrary<Float>() {
376        public <B> Gen<B> coarbitrary(final Float f, final Gen<B> g) {
377          return coarbInteger.coarbitrary(floatToRawIntBits(f), g);
378        }
379      };
380    
381      /**
382       * A coarbitrary for doubles.
383       */
384      public static final Coarbitrary<Double> coarbDouble = new Coarbitrary<Double>() {
385        public <B> Gen<B> coarbitrary(final Double d, final Gen<B> g) {
386          return coarbLong.coarbitrary(doubleToRawLongBits(d), g);
387        }
388      };
389    
390      /**
391       * A coarbitrary for the optional value.
392       *
393       * @param ca A coarbitrary for the type of the optional value.
394       * @return A coarbitrary for the optional value.
395       */
396      public static <A> Coarbitrary<Option<A>> coarbOption(final Coarbitrary<A> ca) {
397        return new Coarbitrary<Option<A>>() {
398          public <B> Gen<B> coarbitrary(final Option<A> o, final Gen<B> g) {
399            return o.isNone() ? variant(0, g) : variant(1, ca.coarbitrary(o.some(), g));
400          }
401        };
402      }
403    
404      /**
405       * A coarbitrary for the disjoint union.
406       *
407       * @param ca A coarbitrary for one side of the disjoint union.
408       * @param cb A coarbitrary for one side of the disjoint union.
409       * @return A coarbitrary for the disjoint union.
410       */
411      public static <A, B> Coarbitrary<Either<A, B>> coarbEither(final Coarbitrary<A> ca, final Coarbitrary<B> cb) {
412        return new Coarbitrary<Either<A, B>>() {
413          public <X> Gen<X> coarbitrary(final Either<A, B> e, final Gen<X> g) {
414            return e.isLeft() ?
415                variant(0, ca.coarbitrary(e.left().value(), g)) :
416                variant(1, cb.coarbitrary(e.right().value(), g));
417          }
418        };
419      }
420    
421      /**
422       * A coarbitrary for lists.
423       *
424       * @param ca A coarbitrary for the elements of the list.
425       * @return A coarbitrary for lists.
426       */
427      public static <A> Coarbitrary<List<A>> coarbList(final Coarbitrary<A> ca) {
428        return new Coarbitrary<List<A>>() {
429          public <B> Gen<B> coarbitrary(final List<A> as, final Gen<B> g) {
430            return as.isEmpty() ?
431                variant(0, g) :
432                variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail(), g)));
433          }
434        };
435      }
436    
437      /**
438       * A coarbitrary for strings.
439       */
440      public static final Coarbitrary<String> coarbString = new Coarbitrary<String>() {
441        public <B> Gen<B> coarbitrary(final String s, final Gen<B> g) {
442          return coarbList(coarbCharacter).coarbitrary(fromString(s), g);
443        }
444      };
445    
446      /**
447       * A coarbitrary for string buffers.
448       */
449      public static final Coarbitrary<StringBuffer> coarbStringBuffer = new Coarbitrary<StringBuffer>() {
450        public <B> Gen<B> coarbitrary(final StringBuffer s, final Gen<B> g) {
451          return coarbString.coarbitrary(s.toString(), g);
452        }
453      };
454    
455      /**
456       * A coarbitrary for string builders.
457       */
458      public static final Coarbitrary<StringBuilder> coarbStringBuilder = new Coarbitrary<StringBuilder>() {
459        public <B> Gen<B> coarbitrary(final StringBuilder s, final Gen<B> g) {
460          return coarbString.coarbitrary(s.toString(), g);
461        }
462      };
463    
464      /**
465       * A coarbitrary for streams.
466       *
467       * @param ca A coarbitrary for the elements of the stream.
468       * @return A coarbitrary for streams.
469       */
470      public static <A> Coarbitrary<Stream<A>> coarbStream(final Coarbitrary<A> ca) {
471        return new Coarbitrary<Stream<A>>() {
472          public <B> Gen<B> coarbitrary(final Stream<A> as, final Gen<B> g) {
473            return as.isEmpty() ?
474                variant(0, g) :
475                variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail()._1(), g)));
476          }
477        };
478      }
479    
480      /**
481       * A coarbitrary for arrays.
482       *
483       * @param ca A coarbitrary for the elements of the array.
484       * @return A coarbitrary for arrays.
485       */
486      public static <A> Coarbitrary<Array<A>> coarbArray(final Coarbitrary<A> ca) {
487        return new Coarbitrary<Array<A>>() {
488          public <B> Gen<B> coarbitrary(final Array<A> as, final Gen<B> g) {
489            return coarbList(ca).coarbitrary(as.toList(), g);
490          }
491        };
492      }
493    
494      /**
495       * A coarbitrary for throwables.
496       *
497       * @param cs A coarbitrary for the throwable message.
498       * @return A coarbitrary for throwables.
499       */
500      public static Coarbitrary<Throwable> coarbThrowable(final Coarbitrary<String> cs) {
501        return cs.comap(new F<Throwable, String>() {
502          public String f(final Throwable t) {
503            return t.getMessage();
504          }
505        });
506      }
507    
508      /**
509       * A coarbitrary for throwables.
510       */
511      public static final Coarbitrary<Throwable> coarbThrowable =
512          coarbThrowable(coarbString);
513    
514      // BEGIN java.util
515    
516      /**
517       * A coarbitrary for array lists.
518       *
519       * @param ca A coarbitrary for the elements of the array list.
520       * @return A coarbitrary for array lists.
521       */
522      public static <A> Coarbitrary<ArrayList<A>> coarbArrayList(final Coarbitrary<A> ca) {
523        return new Coarbitrary<ArrayList<A>>() {
524          @SuppressWarnings({"unchecked"})
525          public <B> Gen<B> coarbitrary(final ArrayList<A> as, final Gen<B> g) {
526            return coarbArray(ca).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
527          }
528        };
529      }
530    
531      /**
532       * A coarbitrary for bit sets.
533       */
534      public static final Coarbitrary<BitSet> coarbBitSet = new Coarbitrary<BitSet>() {
535        public <B> Gen<B> coarbitrary(final BitSet s, final Gen<B> g) {
536          List<Boolean> x = nil();
537    
538          for (int i = 0; i < s.size(); i++) {
539            x = x.snoc(s.get(i));
540          }
541    
542          return coarbList(coarbBoolean).coarbitrary(x, g);
543        }
544      };
545    
546      /**
547       * A coarbitrary for calendars.
548       */
549      public static final Coarbitrary<Calendar> coarbCalendar = new Coarbitrary<Calendar>() {
550        public <B> Gen<B> coarbitrary(final Calendar c, final Gen<B> g) {
551          return coarbLong.coarbitrary(c.getTime().getTime(), g);
552        }
553      };
554    
555      /**
556       * A coarbitrary for dates.
557       */
558      public static final Coarbitrary<Date> coarbDate = new Coarbitrary<Date>() {
559        public <B> Gen<B> coarbitrary(final Date d, final Gen<B> g) {
560          return coarbLong.coarbitrary(d.getTime(), g);
561        }
562      };
563    
564      /**
565       * A coarbitrary for enum maps.
566       *
567       * @param ck A coarbitrary for the map keys.
568       * @param cv A coarbitrary for the map values.
569       * @return A coarbitrary for enum maps.
570       */
571      public static <K extends Enum<K>, V> Coarbitrary<EnumMap<K, V>> coarbEnumMap(final Coarbitrary<K> ck,
572                                                                                   final Coarbitrary<V> cv) {
573        return new Coarbitrary<EnumMap<K, V>>() {
574          @SuppressWarnings({"UseOfObsoleteCollectionType"})
575          public <B> Gen<B> coarbitrary(final EnumMap<K, V> m, final Gen<B> g) {
576            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
577          }
578        };
579      }
580    
581      /**
582       * A coarbitrary for enum sets.
583       *
584       * @param c A coarbitrary for the elements of the enum set.
585       * @return A coarbitrary for enum sets.
586       */
587      public static <A extends Enum<A>> Coarbitrary<EnumSet<A>> coarbEnumSet(final Coarbitrary<A> c) {
588        return new Coarbitrary<EnumSet<A>>() {
589          @SuppressWarnings({"unchecked"})
590          public <B> Gen<B> coarbitrary(final EnumSet<A> as, final Gen<B> g) {
591            return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
592          }
593        };
594      }
595    
596      /**
597       * A coarbitrary for gregorian calendars.
598       */
599      public static final Coarbitrary<GregorianCalendar> coarbGregorianCalendar = new Coarbitrary<GregorianCalendar>() {
600        public <B> Gen<B> coarbitrary(final GregorianCalendar c, final Gen<B> g) {
601          return coarbLong.coarbitrary(c.getTime().getTime(), g);
602        }
603      };
604    
605      /**
606       * A coarbitrary for hash maps.
607       *
608       * @param ck A coarbitrary for the map keys.
609       * @param cv A coarbitrary for the map values.
610       * @return A coarbitrary for hash maps.
611       */
612      public static <K, V> Coarbitrary<HashMap<K, V>> coarbHashMap(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
613        return new Coarbitrary<HashMap<K, V>>() {
614          @SuppressWarnings({"UseOfObsoleteCollectionType"})
615          public <B> Gen<B> coarbitrary(final HashMap<K, V> m, final Gen<B> g) {
616            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
617          }
618        };
619      }
620    
621      /**
622       * A coarbitrary for hash sets.
623       *
624       * @param c A coarbitrary for the elements of the hash set.
625       * @return A coarbitrary for hash sets.
626       */
627      public static <A> Coarbitrary<HashSet<A>> coarbHashSet(final Coarbitrary<A> c) {
628        return new Coarbitrary<HashSet<A>>() {
629          @SuppressWarnings({"unchecked"})
630          public <B> Gen<B> coarbitrary(final HashSet<A> as, final Gen<B> g) {
631            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
632          }
633        };
634      }
635    
636      /**
637       * A coarbitrary for hash tables.
638       *
639       * @param ck A coarbitrary for the map keys.
640       * @param cv A coarbitrary for the map values.
641       * @return A coarbitrary for hash tables.
642       */
643      public static <K, V> Coarbitrary<Hashtable<K, V>> coarbHashtable(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
644        return new Coarbitrary<Hashtable<K, V>>() {
645          @SuppressWarnings({"UseOfObsoleteCollectionType"})
646          public <B> Gen<B> coarbitrary(final Hashtable<K, V> h, final Gen<B> g) {
647            List<P2<K, V>> x = nil();
648    
649            for (final K k : h.keySet()) {
650              x = x.snoc(p(k, h.get(k)));
651            }
652    
653            return coarbList(coarbP2(ck, cv)).coarbitrary(x, g);
654          }
655        };
656      }
657    
658      /**
659       * A coarbitrary for identity hash maps.
660       *
661       * @param ck A coarbitrary for the map keys.
662       * @param cv A coarbitrary for the map values.
663       * @return A coarbitrary for identity hash maps.
664       */
665      public static <K, V> Coarbitrary<IdentityHashMap<K, V>> coarbIdentityHashMap(final Coarbitrary<K> ck,
666                                                                                   final Coarbitrary<V> cv) {
667        return new Coarbitrary<IdentityHashMap<K, V>>() {
668          @SuppressWarnings({"UseOfObsoleteCollectionType"})
669          public <B> Gen<B> coarbitrary(final IdentityHashMap<K, V> m, final Gen<B> g) {
670            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
671          }
672        };
673      }
674    
675      /**
676       * A coarbitrary for linked hash maps.
677       *
678       * @param ck A coarbitrary for the map keys.
679       * @param cv A coarbitrary for the map values.
680       * @return A coarbitrary for linked hash maps.
681       */
682      public static <K, V> Coarbitrary<LinkedHashMap<K, V>> coarbLinkedHashMap(final Coarbitrary<K> ck,
683                                                                               final Coarbitrary<V> cv) {
684        return new Coarbitrary<LinkedHashMap<K, V>>() {
685          @SuppressWarnings({"UseOfObsoleteCollectionType"})
686          public <B> Gen<B> coarbitrary(final LinkedHashMap<K, V> m, final Gen<B> g) {
687            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
688          }
689        };
690      }
691    
692      /**
693       * A coarbitrary for linked hash sets.
694       *
695       * @param c A coarbitrary for the elements of the linked hash set.
696       * @return A coarbitrary for linked hash sets.
697       */
698      public static <A> Coarbitrary<LinkedHashSet<A>> coarbLinkedHashSet(final Coarbitrary<A> c) {
699        return new Coarbitrary<LinkedHashSet<A>>() {
700          @SuppressWarnings({"unchecked"})
701          public <B> Gen<B> coarbitrary(final LinkedHashSet<A> as, final Gen<B> g) {
702            return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
703          }
704        };
705      }
706    
707      /**
708       * A coarbitrary for linked lists.
709       *
710       * @param c A coarbitrary for the elements of the linked list.
711       * @return A coarbitrary for linked lists.
712       */
713      public static <A> Coarbitrary<LinkedList<A>> coarbLinkedList(final Coarbitrary<A> c) {
714        return new Coarbitrary<LinkedList<A>>() {
715          @SuppressWarnings({"unchecked"})
716          public <B> Gen<B> coarbitrary(final LinkedList<A> as, final Gen<B> g) {
717            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
718          }
719        };
720      }
721    
722      /**
723       * A coarbitrary for priority queues.
724       *
725       * @param c A coarbitrary for the elements of the priority queue.
726       * @return A coarbitrary for priority queues.
727       */
728      public static <A> Coarbitrary<PriorityQueue<A>> coarbPriorityQueue(final Coarbitrary<A> c) {
729        return new Coarbitrary<PriorityQueue<A>>() {
730          @SuppressWarnings({"unchecked"})
731          public <B> Gen<B> coarbitrary(final PriorityQueue<A> as, final Gen<B> g) {
732            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
733          }
734        };
735      }
736    
737      /**
738       * A coarbitrary for properties.
739       */
740      public static final Coarbitrary<Properties> coarbProperties = new Coarbitrary<Properties>() {
741        @SuppressWarnings({"UseOfObsoleteCollectionType"})
742        public <B> Gen<B> coarbitrary(final Properties p, final Gen<B> g) {
743          final Hashtable<String, String> t = new Hashtable<String, String>();
744    
745          for (final Object s : p.keySet()) {
746            t.put((String) s, p.getProperty((String) s));
747          }
748    
749          return coarbHashtable(coarbString, coarbString).coarbitrary(t, g);
750        }
751      };
752    
753      /**
754       * A coarbitrary for stacks.
755       *
756       * @param c A coarbitrary for the elements of the stack.
757       * @return A coarbitrary for stacks.
758       */
759      public static <A> Coarbitrary<Stack<A>> coarbStack(final Coarbitrary<A> c) {
760        return new Coarbitrary<Stack<A>>() {
761          @SuppressWarnings({"unchecked"})
762          public <B> Gen<B> coarbitrary(final Stack<A> as, final Gen<B> g) {
763            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
764          }
765        };
766      }
767    
768      /**
769       * A coarbitrary for tree maps.
770       *
771       * @param ck A coarbitrary for the map keys.
772       * @param cv A coarbitrary for the map values.
773       * @return A coarbitrary for tree maps.
774       */
775      public static <K, V> Coarbitrary<TreeMap<K, V>> coarbTreeMap(final Coarbitrary<K> ck, final Coarbitrary<V> cv) {
776        return new Coarbitrary<TreeMap<K, V>>() {
777          @SuppressWarnings({"UseOfObsoleteCollectionType"})
778          public <B> Gen<B> coarbitrary(final TreeMap<K, V> m, final Gen<B> g) {
779            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
780          }
781        };
782      }
783    
784      /**
785       * A coarbitrary for tree sets.
786       *
787       * @param c A coarbitrary for the elements of the tree set.
788       * @return A coarbitrary for tree sets.
789       */
790      public static <A> Coarbitrary<TreeSet<A>> coarbTreeSet(final Coarbitrary<A> c) {
791        return new Coarbitrary<TreeSet<A>>() {
792          @SuppressWarnings({"unchecked"})
793          public <B> Gen<B> coarbitrary(final TreeSet<A> as, final Gen<B> g) {
794            return coarbHashSet(c).coarbitrary(new HashSet<A>(as), g);
795          }
796        };
797      }
798    
799      /**
800       * A coarbitrary for vectors.
801       *
802       * @param c A coarbitrary for the elements of the vector.
803       * @return A coarbitrary for vectors.
804       */
805      public static <A> Coarbitrary<Vector<A>> coarbVector(final Coarbitrary<A> c) {
806        return new Coarbitrary<Vector<A>>() {
807          @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"})
808          public <B> Gen<B> coarbitrary(final Vector<A> as, final Gen<B> g) {
809            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
810          }
811        };
812      }
813    
814      /**
815       * A coarbitrary for weak hash maps.
816       *
817       * @param ck A coarbitrary for the map keys.
818       * @param cv A coarbitrary for the map values.
819       * @return A coarbitrary for weak hash maps.
820       */
821      public static <K, V> Coarbitrary<WeakHashMap<K, V>> coarbWeakHashMap(final Coarbitrary<K> ck,
822                                                                           final Coarbitrary<V> cv) {
823        return new Coarbitrary<WeakHashMap<K, V>>() {
824          @SuppressWarnings({"UseOfObsoleteCollectionType"})
825          public <B> Gen<B> coarbitrary(final WeakHashMap<K, V> m, final Gen<B> g) {
826            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
827          }
828        };
829      }
830    
831      // END java.util
832    
833      // BEGIN java.util.concurrent
834    
835      /**
836       * A coarbitrary for array blocking queues.
837       *
838       * @param c A coarbitrary for the elements of the array blocking queue.
839       * @return A coarbitrary for array blocking queues.
840       */
841      public static <A> Coarbitrary<ArrayBlockingQueue<A>> coarbArrayBlockingQueue(final Coarbitrary<A> c) {
842        return new Coarbitrary<ArrayBlockingQueue<A>>() {
843          @SuppressWarnings({"unchecked"})
844          public <B> Gen<B> coarbitrary(final ArrayBlockingQueue<A> as, final Gen<B> g) {
845            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
846          }
847        };
848      }
849    
850      /**
851       * A coarbitrary for concurrent hash maps.
852       *
853       * @param ck A coarbitrary for the map keys.
854       * @param cv A coarbitrary for the map values.
855       * @return A coarbitrary for concurrent hash maps.
856       */
857      public static <K, V> Coarbitrary<ConcurrentHashMap<K, V>> coarbConcurrentHashMap(final Coarbitrary<K> ck,
858                                                                                       final Coarbitrary<V> cv) {
859        return new Coarbitrary<ConcurrentHashMap<K, V>>() {
860          @SuppressWarnings({"UseOfObsoleteCollectionType"})
861          public <B> Gen<B> coarbitrary(final ConcurrentHashMap<K, V> m, final Gen<B> g) {
862            return coarbHashtable(ck, cv).coarbitrary(new Hashtable<K, V>(m), g);
863          }
864        };
865      }
866    
867      /**
868       * A coarbitrary for concurrent linked queues.
869       *
870       * @param c A coarbitrary for the elements of the concurrent linked queue.
871       * @return A coarbitrary for concurrent linked queues.
872       */
873      public static <A> Coarbitrary<ConcurrentLinkedQueue<A>> coarbConcurrentLinkedQueue(final Coarbitrary<A> c) {
874        return new Coarbitrary<ConcurrentLinkedQueue<A>>() {
875          @SuppressWarnings({"unchecked"})
876          public <B> Gen<B> coarbitrary(final ConcurrentLinkedQueue<A> as, final Gen<B> g) {
877            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
878          }
879        };
880      }
881    
882      /**
883       * A coarbitrary for copy-on-write array lists.
884       *
885       * @param c A coarbitrary for the elements of the copy-on-write array list.
886       * @return A coarbitrary for copy-on-write array lists.
887       */
888      public static <A> Coarbitrary<CopyOnWriteArrayList<A>> coarbCopyOnWriteArrayList(final Coarbitrary<A> c) {
889        return new Coarbitrary<CopyOnWriteArrayList<A>>() {
890          @SuppressWarnings({"unchecked"})
891          public <B> Gen<B> coarbitrary(final CopyOnWriteArrayList<A> as, final Gen<B> g) {
892            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
893          }
894        };
895      }
896    
897      /**
898       * A coarbitrary for copy-on-write array sets.
899       *
900       * @param c A coarbitrary for the elements of the copy-on-write array set.
901       * @return A coarbitrary for copy-on-write array sets.
902       */
903      public static <A> Coarbitrary<CopyOnWriteArraySet<A>> coarbCopyOnWriteArraySet(final Coarbitrary<A> c) {
904        return new Coarbitrary<CopyOnWriteArraySet<A>>() {
905          @SuppressWarnings({"unchecked"})
906          public <B> Gen<B> coarbitrary(final CopyOnWriteArraySet<A> as, final Gen<B> g) {
907            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
908          }
909        };
910      }
911    
912      /**
913       * A coarbitrary for delay queues.
914       *
915       * @param c A coarbitrary for the elements of the delay queue.
916       * @return A coarbitrary for delay queues.
917       */
918      public static <A extends Delayed> Coarbitrary<DelayQueue<A>> coarbDelayQueue(final Coarbitrary<A> c) {
919        return new Coarbitrary<DelayQueue<A>>() {
920          @SuppressWarnings({"unchecked"})
921          public <B> Gen<B> coarbitrary(final DelayQueue<A> as, final Gen<B> g) {
922            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
923          }
924        };
925      }
926    
927      /**
928       * A coarbitrary for linked blocking queues.
929       *
930       * @param c A coarbitrary for the elements of the linked blocking queue.
931       * @return A coarbitrary for linked blocking queues.
932       */
933      public static <A> Coarbitrary<LinkedBlockingQueue<A>> coarbLinkedBlockingQueue(final Coarbitrary<A> c) {
934        return new Coarbitrary<LinkedBlockingQueue<A>>() {
935          @SuppressWarnings({"unchecked"})
936          public <B> Gen<B> coarbitrary(final LinkedBlockingQueue<A> as, final Gen<B> g) {
937            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
938          }
939        };
940      }
941    
942      /**
943       * A coarbitrary for priority blocking queues.
944       *
945       * @param c A coarbitrary for the elements of the priority blocking queue.
946       * @return A coarbitrary for priority blocking queues.
947       */
948      public static <A> Coarbitrary<PriorityBlockingQueue<A>> coarbPriorityBlockingQueue(final Coarbitrary<A> c) {
949        return new Coarbitrary<PriorityBlockingQueue<A>>() {
950          @SuppressWarnings({"unchecked"})
951          public <B> Gen<B> coarbitrary(final PriorityBlockingQueue<A> as, final Gen<B> g) {
952            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
953          }
954        };
955      }
956    
957      /**
958       * A coarbitrary for synchronous queues.
959       *
960       * @param c A coarbitrary for the elements of the synchronous queue.
961       * @return A coarbitrary for synchronous queues.
962       */
963      public static <A> Coarbitrary<SynchronousQueue<A>> coarbSynchronousQueue(final Coarbitrary<A> c) {
964        return new Coarbitrary<SynchronousQueue<A>>() {
965          @SuppressWarnings({"unchecked"})
966          public <B> Gen<B> coarbitrary(final SynchronousQueue<A> as, final Gen<B> g) {
967            return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g);
968          }
969        };
970      }
971    
972      // END java.util.concurrent
973    
974      // BEGIN java.sql
975    
976      public static final Coarbitrary<java.sql.Date> coarbSQLDate = new Coarbitrary<java.sql.Date>() {
977        public <B> Gen<B> coarbitrary(final java.sql.Date d, final Gen<B> g) {
978          return coarbLong.coarbitrary(d.getTime(), g);
979        }
980      };
981    
982      public static final Coarbitrary<Timestamp> coarbTimestamp = new Coarbitrary<Timestamp>() {
983        public <B> Gen<B> coarbitrary(final Timestamp t, final Gen<B> g) {
984          return coarbLong.coarbitrary(t.getTime(), g);
985        }
986      };
987    
988      public static final Coarbitrary<Time> coarbTime = new Coarbitrary<Time>() {
989        public <B> Gen<B> coarbitrary(final Time t, final Gen<B> g) {
990          return coarbLong.coarbitrary(t.getTime(), g);
991        }
992      };
993    
994      // END java.sql
995    
996      // BEGIN java.math
997    
998      public static final Coarbitrary<BigInteger> coarbBigInteger = new Coarbitrary<BigInteger>() {
999        public <B> Gen<B> coarbitrary(final BigInteger i, final Gen<B> g) {
1000          return variant((i.compareTo(BigInteger.ZERO) >= 0 ?
1001              i.multiply(BigInteger.valueOf(2L)) :
1002              i.multiply(BigInteger.valueOf(-2L).add(BigInteger.ONE))).longValue(), g);
1003        }
1004      };
1005    
1006      public static final Coarbitrary<BigDecimal> coarbBigDecimal = new Coarbitrary<BigDecimal>() {
1007        public <B> Gen<B> coarbitrary(final BigDecimal d, final Gen<B> g) {
1008          return variant((d.compareTo(BigDecimal.ZERO) >= 0 ?
1009              d.multiply(BigDecimal.valueOf(2L)) :
1010              d.multiply(BigDecimal.valueOf(-2L).add(BigDecimal.ONE))).longValue(), g);
1011        }
1012      };
1013    
1014      // END java.math
1015    
1016      /**
1017       * A coarbitrary for product-1 values.
1018       *
1019       * @param ca A coarbitrary for one of the types over which the product-1 is defined.
1020       * @return A coarbitrary for product-1 values.
1021       */
1022      public static <A> Coarbitrary<P1<A>> coarbP1(final Coarbitrary<A> ca) {
1023        return new Coarbitrary<P1<A>>() {
1024          public <B> Gen<B> coarbitrary(final P1<A> p, final Gen<B> g) {
1025            return ca.coarbitrary(p._1(), g);
1026          }
1027        };
1028      }
1029    
1030      /**
1031       * A coarbitrary for product-2 values.
1032       *
1033       * @param ca A coarbitrary for one of the types over which the product-2 is defined.
1034       * @param cb A coarbitrary for one of the types over which the product-2 is defined.
1035       * @return A coarbitrary for product-2 values.
1036       */
1037      public static <A, B> Coarbitrary<P2<A, B>> coarbP2(final Coarbitrary<A> ca, final Coarbitrary<B> cb) {
1038        return new Coarbitrary<P2<A, B>>() {
1039          public <X> Gen<X> coarbitrary(final P2<A, B> p, final Gen<X> g) {
1040            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), g));
1041          }
1042        };
1043      }
1044    
1045      /**
1046       * A coarbitrary for product-3 values.
1047       *
1048       * @param ca A coarbitrary for one of the types over which the product-3 is defined.
1049       * @param cb A coarbitrary for one of the types over which the product-3 is defined.
1050       * @param cc A coarbitrary for one of the types over which the product-3 is defined.
1051       * @return A coarbitrary for product-3 values.
1052       */
1053      public static <A, B, C> Coarbitrary<P3<A, B, C>> coarbP3(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
1054                                                               final Coarbitrary<C> cc) {
1055        return new Coarbitrary<P3<A, B, C>>() {
1056          public <X> Gen<X> coarbitrary(final P3<A, B, C> p, final Gen<X> g) {
1057            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), g)));
1058          }
1059        };
1060      }
1061    
1062      /**
1063       * A coarbitrary for product-4 values.
1064       *
1065       * @param ca A coarbitrary for one of the types over which the product-4 is defined.
1066       * @param cb A coarbitrary for one of the types over which the product-4 is defined.
1067       * @param cc A coarbitrary for one of the types over which the product-4 is defined.
1068       * @param cd A coarbitrary for one of the types over which the product-4 is defined.
1069       * @return A coarbitrary for product-4 values.
1070       */
1071      public static <A, B, C, D> Coarbitrary<P4<A, B, C, D>> coarbP4(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
1072                                                                     final Coarbitrary<C> cc, final Coarbitrary<D> cd) {
1073        return new Coarbitrary<P4<A, B, C, D>>() {
1074          public <X> Gen<X> coarbitrary(final P4<A, B, C, D> p, final Gen<X> g) {
1075            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), g))));
1076          }
1077        };
1078      }
1079    
1080      /**
1081       * A coarbitrary for product-5 values.
1082       *
1083       * @param ca A coarbitrary for one of the types over which the product-5 is defined.
1084       * @param cb A coarbitrary for one of the types over which the product-5 is defined.
1085       * @param cc A coarbitrary for one of the types over which the product-5 is defined.
1086       * @param cd A coarbitrary for one of the types over which the product-5 is defined.
1087       * @param ce A coarbitrary for one of the types over which the product-5 is defined.
1088       * @return A coarbitrary for product-5 values.
1089       */
1090      public static <A, B, C, D, E> Coarbitrary<P5<A, B, C, D, E>> coarbP5(final Coarbitrary<A> ca, final Coarbitrary<B> cb,
1091                                                                           final Coarbitrary<C> cc, final Coarbitrary<D> cd,
1092                                                                           final Coarbitrary<E> ce) {
1093        return new Coarbitrary<P5<A, B, C, D, E>>() {
1094          public <X> Gen<X> coarbitrary(final P5<A, B, C, D, E> p, final Gen<X> g) {
1095            return ca.coarbitrary(p._1(),
1096                cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), g)))));
1097          }
1098        };
1099      }
1100    
1101      /**
1102       * A coarbitrary for product-6 values.
1103       *
1104       * @param ca A coarbitrary for one of the types over which the product-6 is defined.
1105       * @param cb A coarbitrary for one of the types over which the product-6 is defined.
1106       * @param cc A coarbitrary for one of the types over which the product-6 is defined.
1107       * @param cd A coarbitrary for one of the types over which the product-6 is defined.
1108       * @param ce A coarbitrary for one of the types over which the product-6 is defined.
1109       * @param cf A coarbitrary for one of the types over which the product-6 is defined.
1110       * @return A coarbitrary for product-6 values.
1111       */
1112      public static <A, B, C, D, E, F$> Coarbitrary<P6<A, B, C, D, E, F$>> coarbP6(final Coarbitrary<A> ca,
1113                                                                                   final Coarbitrary<B> cb,
1114                                                                                   final Coarbitrary<C> cc,
1115                                                                                   final Coarbitrary<D> cd,
1116                                                                                   final Coarbitrary<E> ce,
1117                                                                                   final Coarbitrary<F$> cf) {
1118        return new Coarbitrary<P6<A, B, C, D, E, F$>>() {
1119          public <X> Gen<X> coarbitrary(final P6<A, B, C, D, E, F$> p, final Gen<X> g) {
1120            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(),
1121                cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), g))))));
1122          }
1123        };
1124      }
1125    
1126      /**
1127       * A coarbitrary for product-7 values.
1128       *
1129       * @param ca A coarbitrary for one of the types over which the product-7 is defined.
1130       * @param cb A coarbitrary for one of the types over which the product-7 is defined.
1131       * @param cc A coarbitrary for one of the types over which the product-7 is defined.
1132       * @param cd A coarbitrary for one of the types over which the product-7 is defined.
1133       * @param ce A coarbitrary for one of the types over which the product-7 is defined.
1134       * @param cf A coarbitrary for one of the types over which the product-7 is defined.
1135       * @param cg A coarbitrary for one of the types over which the product-7 is defined.
1136       * @return A coarbitrary for product-7 values.
1137       */
1138      public static <A, B, C, D, E, F$, G> Coarbitrary<P7<A, B, C, D, E, F$, G>> coarbP7(final Coarbitrary<A> ca,
1139                                                                                         final Coarbitrary<B> cb,
1140                                                                                         final Coarbitrary<C> cc,
1141                                                                                         final Coarbitrary<D> cd,
1142                                                                                         final Coarbitrary<E> ce,
1143                                                                                         final Coarbitrary<F$> cf,
1144                                                                                         final Coarbitrary<G> cg) {
1145        return new Coarbitrary<P7<A, B, C, D, E, F$, G>>() {
1146          public <X> Gen<X> coarbitrary(final P7<A, B, C, D, E, F$, G> p, final Gen<X> g) {
1147            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(),
1148                cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), g)))))));
1149          }
1150        };
1151      }
1152    
1153      /**
1154       * A coarbitrary for product-8 values.
1155       *
1156       * @param ca A coarbitrary for one of the types over which the product-8 is defined.
1157       * @param cb A coarbitrary for one of the types over which the product-8 is defined.
1158       * @param cc A coarbitrary for one of the types over which the product-8 is defined.
1159       * @param cd A coarbitrary for one of the types over which the product-8 is defined.
1160       * @param ce A coarbitrary for one of the types over which the product-8 is defined.
1161       * @param cf A coarbitrary for one of the types over which the product-8 is defined.
1162       * @param cg A coarbitrary for one of the types over which the product-8 is defined.
1163       * @param ch A coarbitrary for one of the types over which the product-8 is defined.
1164       * @return A coarbitrary for product-8 values.
1165       */
1166      public static <A, B, C, D, E, F$, G, H> Coarbitrary<P8<A, B, C, D, E, F$, G, H>> coarbP8(final Coarbitrary<A> ca,
1167                                                                                               final Coarbitrary<B> cb,
1168                                                                                               final Coarbitrary<C> cc,
1169                                                                                               final Coarbitrary<D> cd,
1170                                                                                               final Coarbitrary<E> ce,
1171                                                                                               final Coarbitrary<F$> cf,
1172                                                                                               final Coarbitrary<G> cg,
1173                                                                                               final Coarbitrary<H> ch) {
1174        return new Coarbitrary<P8<A, B, C, D, E, F$, G, H>>() {
1175          public <X> Gen<X> coarbitrary(final P8<A, B, C, D, E, F$, G, H> p, final Gen<X> g) {
1176            return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(),
1177                ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), ch.coarbitrary(p._8(), g))))))));
1178          }
1179        };
1180      }
1181    }