package gw.rating.rtm.domain.table uses gw.rating.rtm.domain.RateBookVisitor uses gw.rating.rtm.domain.DatabasePopulator uses java.lang.IllegalStateException class RateBookModel { var _rateBook : RateBook as Book var _rateTableModels : List as readonly RateTableModels //creating model with all the ratebook's rate tables construct(rateBook : RateBook) { this(rateBook, rateBook.RateTables.map(\rt -> newModelFor(rt)).toList()) } //creating model with all the ratebook's rate tables construct(rateBook : RateBook, referenceTable : boolean) { this(rateBook, rateBook.RateTables.map(\rt -> newModelFor(rt)).toList(), referenceTable) } construct(rateBook : RateBook, tableModels : List) { this(rateBook, tableModels, false) } //creating model based off of passed in table models instead of rate tables associated with the ratebook construct(rateBook: RateBook, tableModels : List, referenceTable : boolean) { if (tableModels == null) { throw new IllegalStateException("Rate table model list is null.") } _rateBook = rateBook if (referenceTable) { var missingTables = rateBook.RateTablesMissingInCalcRoutines.map(\mrt -> newModelFor(mrt)) _rateTableModels = tableModels.union(missingTables).toList() } else { _rateTableModels = tableModels } } function accept(visitor : RateBookVisitor) { visitor.visit(this) _rateTableModels.sortBy(\rateTableModel -> rateTableModel.RateTable.Definition.TableCode).each(\rateTableModel -> { rateTableModel.accept(visitor) }) _rateBook.CalcRoutines.sortBy(\ routine -> routine.Code).each(\ routine -> { visitor.visit(routine) }) } static private function newModelFor(table : RateTable) : RateTableModel { var model = new RateTableModel(table) new DatabasePopulator().refresh(model) return model } private function newModelFor(tableCode : String) : RateTableModel { return new RateTableModel(tableCode, _rateBook.PolicyLine) } }