* @param timed should any date values have times associated with them.
* @param wellFormed should the numeric values all be in the appropriate
* ranges, and other constraints specified in the spec hold?
*/
RRule monkeySeeRRule(boolean timed, boolean wellFormed) {
RRule rrule = new RRule();
rrule.setName(rnd.nextInt(4) < 1 ? "EXRULE" : "RRULE");
// pick a frequency
// This is stretching the definition of well formed, but we don't do
// more frequently than daily.
// TODO: allow more frequently than DAILY. BEFORE SUBMIT
Frequency freq = FREQS[rnd.nextInt(FREQS.length)];
rrule.setFreq(freq);
if (rnd.nextBoolean()) {
// biased towards the beginning of the week
rrule.setWkSt(WDAYS[((int) Math.abs(rnd.nextGaussian() / 3) * 7) % 7]);
}
if (rnd.nextBoolean()) {
if (rnd.nextBoolean()) {
rrule.setCount(1 + ((int) (Math.abs(rnd.nextGaussian() * 10))));
} else {
rrule.setUntil(monkeySeeDateValue(maybeNot(timed)));
}
}
rrule.setInterval(
(int) Math.min(0, Math.abs(rnd.nextGaussian() - .5) * 3) + 1);
int sparsity = 2 + rnd.nextInt(6);
boolean allowsByDay = freq.compareTo(Frequency.WEEKLY) >= 0;
if (0 == rnd.nextInt(sparsity) && maybeNot(allowsByDay)) {
rrule.setByDay(Arrays.asList(monkeySeeWeekdayNumList(freq)));
}
if (0 == rnd.nextInt(sparsity)) {
rrule.setByMonth(monkeySeeIntArray(1, 12, 3, false));
}
if (0 == rnd.nextInt(sparsity)) {
rrule.setByMonthDay(monkeySeeIntArray(-31, 31, 6, false));
}
boolean allowWeekNo = maybeNot(Frequency.MONTHLY.compareTo(freq) <= 0);
if (allowWeekNo && 0 == rnd.nextInt(sparsity)) {
boolean useYearly = Frequency.YEARLY == freq;
if (!wellFormed) { useYearly = maybeNot(useYearly); }
int mag = useYearly ? 52 : 5;
rrule.setByWeekNo(monkeySeeIntArray(-mag, mag, 1, false));
}
if (0 == rnd.nextInt(sparsity)) {
rrule.setByYearDay(monkeySeeIntArray(-366, 366, 6, false));
}
if (0 == rnd.nextInt(sparsity * 2)) {
rrule.setByHour(monkeySeeIntArray(0, 23, 3, true));
}
if (0 == rnd.nextInt(sparsity * 2)) {
rrule.setByMinute(monkeySeeIntArray(0, 60, 3, true));
}
if (0 == rnd.nextInt(sparsity * 2)) {
rrule.setBySecond(monkeySeeIntArray(0, 60, 3, true));
}
boolean largestSetPlural = false;
int setMag = 10;
if (0 != rrule.getByMonth().length) {
largestSetPlural = rrule.getByMonth().length > 1;
} else if (0 != rrule.getByWeekNo().length) {
largestSetPlural = rrule.getByWeekNo().length > 1;
} else if (0 != rrule.getByYearDay().length) {
largestSetPlural = rrule.getByYearDay().length > 1;
} else if (0 != rrule.getByMonthDay().length) {
largestSetPlural = rrule.getByMonthDay().length > 1;
} else if (0 != rrule.getByDay().size()) {
List<WeekdayNum> days = rrule.getByDay();
largestSetPlural = days.size() > 1 || 0 == days.get(0).num;
} else if (0 != rrule.getByHour().length) {
largestSetPlural = rrule.getByHour().length > 1;
} else if (0 != rrule.getByMinute().length) {
largestSetPlural = rrule.getByMinute().length > 1;
} else if (0 != rrule.getBySecond().length) {
largestSetPlural = rrule.getBySecond().length > 1;
}
boolean allowSetPos =
wellFormed ? largestSetPlural : maybeNot(largestSetPlural);
if (allowSetPos && 0 == rnd.nextInt(4)) {
rrule.setBySetPos(monkeySeeIntArray(-setMag, setMag, 3, false));
}
return rrule;
}