}
}
// calendar needed for endOfMonth adjustment
final Calendar nullCalendar = new NullCalendar();
int periods = 1;
Date seed, exitDate;
switch (rule_) {
case Zero:
tenor_ = new Period(0, TimeUnit.Days);
dates_.add(effectiveDate);
dates_.add(terminationDate);
isRegular_.add(new Boolean(true));
break;
case Backward:
dates_.add(terminationDate);
seed = terminationDate.clone();
if ( nextToLastDate != null && !nextToLastDate.isNull() ) {
dates_.add(0, nextToLastDate);
final Date temp = nullCalendar.advance(seed, tenor_.mul(periods).negative(), convention, endOfMonth);
if (temp.ne(nextToLastDate)) {
isRegular_.add(0, new Boolean(false));
} else {
isRegular_.add(0, new Boolean(true));
}
seed = nextToLastDate.clone();
}
exitDate = effectiveDate.clone();
if ( firstDate != null && !firstDate.isNull() ) {
exitDate = firstDate.clone();
}
while (true) {
final Date temp = nullCalendar.advance(seed, tenor_.mul(periods).negative(), convention, endOfMonth);
if (temp .lt(exitDate)) {
break;
} else {
dates_.add(0, temp);
isRegular_.add(0, new Boolean(true));
++periods;
}
}
if (endOfMonth && calendar.isEndOfMonth(seed)) {
convention = BusinessDayConvention.Preceding;
}
if (calendar.adjust(dates_.get(0),convention).ne(
calendar.adjust(effectiveDate, convention))) {
dates_.add(0, effectiveDate);
isRegular_.add(0, new Boolean(false));
}
break;
case Twentieth:
case TwentiethIMM:
case ThirdWednesday:
QL.require(!endOfMonth,
"endOfMonth convention incompatible with " + rule_ +
" date generation rule"); // TODO: message
// fall through
case Forward:
dates_.add(effectiveDate);
seed = effectiveDate.clone();
if (firstDate != null && !firstDate.isNull() ) {
dates_.add(firstDate);
final Date temp = nullCalendar.advance(seed, tenor_.mul(periods), convention, endOfMonth);
if (temp.ne(firstDate) ) {
isRegular_.add(new Boolean(false));
} else {
isRegular_.add(new Boolean(true));
}
seed = firstDate.clone();
} else if (rule_ == DateGeneration.Rule.Twentieth ||
rule_ == DateGeneration.Rule.TwentiethIMM) {
final Date next20th = nextTwentieth(effectiveDate, rule_);
if (next20th.ne(effectiveDate)) {
dates_.add(next20th);
isRegular_.add(new Boolean(false));
seed = next20th.clone();
}
}
exitDate = terminationDate.clone();
if ( nextToLastDate != null && !nextToLastDate.isNull() ) {
exitDate = nextToLastDate.clone();
}
while (true) {
final Date temp = nullCalendar.advance(seed, tenor_.mul(periods), convention, endOfMonth);
if ( temp.gt(exitDate) ) {
break;
} else {
dates_.add(temp);
isRegular_.add(new Boolean(true));