package Ġcom . and deg . dis counter . discount Ċ Ċ import Ġcom . and deg . dis counter . order . Order Ċ import Ġcom . and deg . dis counter . order . Order able Ċ import Ġcom . and deg . dis counter . shipment . Carrier Code Ċ import Ġcom . and deg . dis counter . shipment . Shipment Size Ċ import Ġcom . and deg . dis counter . transaction . Transaction Ċ import Ġjava . time . Month Ċ Ċ class ĠLarge Shipment Discount Decorator ( private Ġval Ġsource : ĠDiscount Decorator ): ĠDiscount Decorator () Ġ{ ĊĊĠĠĠ Ġoverride Ġfun Ġdiscount ( transactions : ĠList < Transaction >): ĠList < Transaction > Ġ{ ĊĊĠĠĠĠĠĠĠ Ġval Ġz ipped Transactions Ġ= Ġzip With Index ( source . discount ( transactions )) ĊĊĠĠĠĠĠĠĠ Ġval Ġdiscount able Transactions Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Monthly Indexed Transactions ( z ipped Transactions ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġ(_, Ġindexed Transactions ) Ġ-> Ġcontains Third Discount able Shipment ( indexed Transactions ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġ(_, Ġindexed Transactions ) Ġ-> Ġget Third Discount able Shipment ( indexed Transactions ) Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġz ipped Transactions . to Mutable List (). to Discount ed ( discount able Transactions , Ġz ipped Transactions ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Monthly Indexed Transactions ( z ipped Transactions : ĠList < Z ipped Transaction >) ĊĠĠĠĠĠĠĠ Ġ: ĠList < Monthly Z ipped Transactions > Ġ= ĊĠĠĠĠĠĠĠ Ġz ipped Transactions ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġ(_, Ġtransaction ) Ġ-> Ġis Large La Post e ( transaction . order ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. groupBy Ġ{ Ġ(_, Ġtransaction ) Ġ-> Ġ( transaction . order Ġas ĠOrder ). date . month Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. toList () ĊĊĠĠĠ Ġprivate Ġfun Ġis Large La Post e ( o : ĠOrder able ) Ġ= ĊĠĠĠĠĠĠĠ Ġo Ġis ĠOrder Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġo . shipment Size Ġ== ĠShip ment Size . L Ġ&& ĊĠĠĠĠĠĠĠĠĠĠĠ Ġo . carrier Code Ġ== ĠCar rier Code . LP ĊĊĠĠĠ Ġprivate Ġfun Ġcontains Third Discount able Shipment ( transactions : ĠList < Z ipped Transaction >) Ġ= ĊĠĠĠĠĠĠĠ Ġtransactions . size Ġ>= Ġ 3 ĊĊĠĠĠ Ġprivate Ġfun Ġget Third Discount able Shipment ( indexed Transactions : ĠList < Z ipped Transaction >) Ġ= ĊĠĠĠĠĠĠĠ Ġzip With Index ( indexed Transactions )[ 2 ]. second ĊĊĠĠĠ Ġprivate Ġfun Ġ< T > Ġzip With Index ( transactions : ĠList < T >) Ġ= ĊĠĠĠĠĠĠĠ Ġgenerate Sequence ( 0 ) Ġ{ Ġit Ġ+ Ġ 1 Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. take ( transactions . size ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. toList () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. zip ( transactions ) ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Z ipped Transaction >. to Discount ed ( ĊĠĠĠĠĠĠĠ Ġdiscount able Transactions : ĠList < Z ipped Transaction >, ĊĠĠĠĠĠĠĠ Ġz ipped Transactions : ĠList < Z ipped Transaction > ĊĠĠĠ Ġ): ĠList < Transaction > Ġ{ ĊĊĠĠĠĠĠĠĠ Ġthis . replaceAll Ġ{ Ġ( index , Ġtransaction ) Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( index . matches Discount able ( discount able Transactions )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPair ( index , Ġfind Discount ed Transaction ( z ipped Transactions , Ġindex )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPair ( index , Ġtransaction ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġreturn Ġthis . map Ġ{ Ġ(_, Ġtransaction ) Ġ-> Ġtransaction Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠInt . matches Discount able ( discount able Transactions : ĠList < Z ipped Transaction >) Ġ= ĊĠĠĠĠĠĠĠ Ġdiscount able Transactions . map Ġ{ Ġ( index , Ġ_) Ġ-> Ġindex Ġ}. contains ( this ) ĊĊĠĠĠ Ġprivate Ġfun Ġfind Discount ed Transaction ( z ipped Transactions : ĠList < Z ipped Transaction >, Ġindex : ĠInt ) Ġ= ĊĠĠĠĠĠĠĠ ĠTransaction ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġz ipped Transactions [ index ]. second . order , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġz ipped Transactions [ index ]. second . price , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġz ipped Transactions [ index ]. second . price ĊĠĠĠĠĠĠĠ Ġ) Ċ Ċ } Ċ Ċ type alias ĠMonth ly Z ipped Transactions Ġ= ĠPair < Month , ĠList < Z ipped Transaction >> Ċ Ċ type alias ĠZ ipped Transaction Ġ= ĠPair < Int , ĠTransaction > Ċ