package gw.rating.rtm.domain.table uses entity.RateTableColumn uses gw.rating.rtm.domain.EntityProcessingPersistenceAdapter uses entity.RateTableDefinition uses java.lang.Object uses java.lang.Comparable uses java.lang.NullPointerException uses java.util.List uses java.util.ArrayList uses gw.rating.rtm.domain.RateBookVisitor class RateTableRow implements Comparable { var _rateTableDef : RateTableDefinition as RateTableDefinition var _beanAdapter : EntityProcessingPersistenceAdapter as Row var _parameters : List as Parameters var _factors : List as Factors construct(tableDef : RateTableDefinition, adapter : EntityProcessingPersistenceAdapter) { this(tableDef, adapter, tableDef.SortedParameters, tableDef.SortedFactors) } construct(tableDef : RateTableDefinition, adapter : EntityProcessingPersistenceAdapter, params : entity.RateTableColumn[], factors : entity.RateTableColumn[]) { _rateTableDef = tableDef _beanAdapter = adapter _parameters = getRateTableCells(params) _factors = getRateTableCells(factors) } property get Cells() : List { return this.Parameters.concat(this.Factors) as List } function cellForColumn(col : RateTableColumn) : RateTableCell { return Cells.firstWhere(\ c ->c.ColumnDefinition == col) } private function getRateTableCells(columns : RateTableColumn[]) : List { var cellList = new ArrayList() for (c in columns) { cellList.add(RateTableCell.create(c, _beanAdapter)) } return cellList } override function toString() : String { return Cells.map( \ elt -> elt.ColumnDefinition.ColumnName + "=" + elt.Value).join(";") } override function compareTo(other : RateTableRow) : int { if (other == null) throw new NullPointerException() //compare parameters var otherParameters = other.Parameters for (p in this.Parameters index i) { var result = p.compareTo(otherParameters[i]) if (result != 0) return result } //compare factors var otherFactors = other.Factors for (f in this.Factors index i) { var result = f.compareTo(otherFactors[i]) if (result != 0) return result } return 0 } function accept(visitor : RateBookVisitor) { visitor.visit(this) Cells.each(\ cell -> cell.accept(visitor)) } override function equals(other : Object) : boolean { if (this === other) { return true } return (other typeis RateTableRow) and (this._beanAdapter == other._beanAdapter) } function hasSameParameters(other : RateTableRow) : boolean { return (this.compareTo(other) == 0) } override function hashCode() : int { return this._beanAdapter.hashCode() } function hasNoFactors() : boolean { return this.Factors.allMatch(\factor -> factor.Value == null) } }