Bankroll

model.entities.customers.Bankroll
trait Bankroll[T <: Bankroll[T]]

Defines the contract for an entity that possesses a bankroll (money).

This trait tracks the entity's current financial balance and its initial starting balance, providing methods to update the bankroll and calculate its ratio relative to the start.

Type parameters

T

The concrete type of the entity that extends this trait, enabling F-bounded polymorphism for immutable updates.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Customer

Members list

Value members

Abstract methods

def withBankroll(newBankroll: Double, update: Boolean): T

Returns a new instance of the entity with an updated bankroll value. This method must be implemented by concrete classes to ensure immutability.

Returns a new instance of the entity with an updated bankroll value. This method must be implemented by concrete classes to ensure immutability.

Value parameters

newBankroll

The new bankroll value.

update

A boolean flag, often used to differentiate initial setting from an update, though its specific use depends on the implementing class.

Attributes

Returns

A new instance of the entity with the new bankroll.

Concrete methods

def bankrollRatio: Double

Calculates the ratio of the current bankroll to the starting bankroll. This is useful for tracking profit/loss relative to the initial investment.

Calculates the ratio of the current bankroll to the starting bankroll. This is useful for tracking profit/loss relative to the initial investment.

Attributes

Returns

The bankroll ratio (current bankroll / starting bankroll).

def updateBankroll(netValue: Double): T

Updates the entity's bankroll by adding a netValue. The netValue can be positive (gain) or negative (loss). A requirement ensures the bankroll does not drop below zero.

Updates the entity's bankroll by adding a netValue. The netValue can be positive (gain) or negative (loss). A requirement ensures the bankroll does not drop below zero.

Value parameters

netValue

The amount to add to the current bankroll.

Attributes

Returns

A new instance of the entity with the updated bankroll.

Throws
IllegalArgumentException

if the new bankroll would be negative.

Abstract fields

val bankroll: Double

The current amount of money held by the entity.

The current amount of money held by the entity.

Attributes

val startingBankroll: Double

The initial bankroll amount when the entity started. Used for ratio calculations.

The initial bankroll amount when the entity started. Used for ratio calculations.

Attributes