Allocator

sealed class Allocator<T : AllocationBy> : Allocation<T> (source)

Base class for Allocation implementations. This class implements the Template Method pattern. Subclasses need to override the following members:

  • differenceAllocator: an DifferenceAllocation strategy used to allocate the difference between the original Money amount and its resulting allocations

  • calculate: calculates the allocations for a Money amount

  • calculateReverse: calculates the reverse result for sanity check purposes

With these methods implemented, the allocate method does the allocation and applies the DifferenceAllocation strategy to fix any difference generated by calculate. Also, the method handles the allocation of negative Money amounts.

See EvenAllocator and ProportionalAllocator for example implementations.

See also

Inheritors

Functions

Link copied to clipboard
open override fun allocate(money: Money, by: T): Result

Allocates a Money.