Package-level declarations

Allocation features for Money.

Types

Link copied to clipboard
sealed interface Allocation<T : AllocationBy>

Defines the Money allocation interface.

Link copied to clipboard
sealed interface AllocationBy

Defines the allocation parameter types.

Link copied to clipboard
sealed class Allocator<T : AllocationBy> : Allocation<T>

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

Link copied to clipboard

Allocates a Money amount in even parts.

Link copied to clipboard

Allocates a Money in equal parts. Example:

Link copied to clipboard
class EvenParts(val parts: Int) : AllocationBy

Parameter type for even allocation.

Link copied to clipboard

Allocates a Money in ratios.

Link copied to clipboard

Allocates a Money in ratios. Example:

Link copied to clipboard
class Ratios(val ratios: List<Percentage>) : AllocationBy

Parameter type for proportional allocation.

Link copied to clipboard
class Result

Represents the result of the allocation operation.

Functions

Link copied to clipboard
fun List<Percentage>.adjustForAllocate(tolerance: Double = TOLERANCE): List<Percentage>

Adjust a list of Percentage to sum up to 100% if the difference is within the given tolerance. Useful when working with a list of Percentage calculated using floating-point arithmetic.

Link copied to clipboard

Allocates a Money according to the by parameter:

fun Money.allocate(vararg ratios: Percentage): Result
infix fun Money.allocate(ratios: List<Percentage>): Result

Allocates a Money in ratios. Example:

infix fun Money.allocate(parts: Int): Result

Allocates a Money in equal parts. Example: