package gw.financials uses java.util.Date uses java.lang.UnsupportedOperationException uses java.lang.Integer uses gw.pl.currency.MonetaryAmount uses java.lang.IllegalStateException abstract class WrappedProratable { private var _start : Date as readonly Start private var _end : Date as readonly End private var _amount : MonetaryAmount as readonly Amount private var _ref : T as readonly Reference private var _orig : boolean as readonly Original private var _periodStart : Date as readonly PeriodStart construct(__start : Date, __end : Date, __amount : MonetaryAmount, __orig : boolean, __ref : T, __periodStart : Date) { _start = __start _end = __end _amount = __amount _orig = __orig _ref = __ref _periodStart = __periodStart } function getProrater(defaultProrater : Prorater) : Prorater { var level = this.RoundingLevel var mode = this.RoundingMode.ModeValue var method = this.ProrationMethod if (level != null or mode != null) { return Prorater.forRounding(level ?: defaultProrater.RoundingLevel, mode ?: defaultProrater.RoundingMode, method ?: TC_PRORATABYDAYS) } return defaultProrater } abstract property get RoundingLevel(): Integer abstract property get RoundingMode(): RoundingModeType abstract property get ProrationMethod(): ProrationMethod abstract property get DaysInTerm(): Integer abstract property get TermAmount(): MonetaryAmount property get TermEnd() : Date { if (DaysInTerm == null) { throw new IllegalStateException("Cannot calculate TermEnd because DaysInTerm is null") } var p = getProrater(Prorater.forRounding(0, HALF_UP, TC_PRORATABYDAYS)) return p.findEndOfRatedTerm(_periodStart, DaysInTerm) } /** * True when underlying Costs have same basis and rate. */ function haveEquivalentCosts(that : WrappedProratable) : boolean { throw new UnsupportedOperationException("\"haveEquivalentCosts\" not defined for this proratable.") } /** * Returns an Object which (via its equals and hashCode methods) can * be used to partition a collection of WrappedProratables such that * two WrappedProratables with equal partitioners are guaranteed to * have (or be) the same original WrappedProratable. By this, a * WrapperedProratable which is Original is partially cancelled by * one with the same partitioner where !Original. */ function sameOriginalTransactionPartitioner() : Object { throw new UnsupportedOperationException("\"sameOriginalTransactionPartitioner\" not defined for this proratable.") } /** * Construct a new WrappedProratable based on this one, * but with different start and end dates, and a different amount. */ function subPeriod(__start : Date, __end : Date, __amount : MonetaryAmount) : WrappedProratable { return subPeriod(__start, __end, __amount, this.Original) } /** * Construct a new WrappedProratable based on this one, * but with different start and end dates, and a different amount. */ abstract function subPeriod(__start : Date, __end : Date, __amount : MonetaryAmount, __orig : boolean) : WrappedProratable override function equals(o : Object) : boolean { if (this === o) { return true } if (!(o typeis WrappedProratable)) { return false } var that = o as WrappedProratable return Start == that.Start and End == that.End and Amount == that.Amount and Reference == that.Reference } override function toString() : String { return _amount.toString() + " " + (_start as String) + " to " + (_end as String) + "(" + toString(_ref) + ")" } private static function toString(o : Object) : String { return o != null ? o.toString() : "" } public override function hashCode() : int { return 17*Start.hashCode() + 31*End.hashCode() + 11*Amount.hashCode() + Reference.hashCode() } }