Energy

Represents an energy value.

This value class provides a type-safe way to handle energy, primarily in watt-hours (Wh) and kilowatt-hours (kWh). It supports basic arithmetic operations and comparisons.

Instances of Energy are created using the extension properties on Number, such as 100.wattHours or 2.5.kiloWattHours.

Example usage:

val batteryCapacity = 100.kiloWattHours
val energyConsumed = 25000.wattHours
val remainingEnergy = batteryCapacity - energyConsumed
println("Remaining energy: ${remainingEnergy.inKiloWattHours} kWh")

The internal representation is in watt-hours as a Double to maintain precision for calculations, but exposed values like inWattHours are rounded to the nearest integer.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns this energy in kilowatt-hours.

Link copied to clipboard

Energy in watt-hours rounded to integer value.

Functions

Link copied to clipboard
open operator override fun compareTo(other: Energy): Int

Compares this energy with the specified energy for order.

Link copied to clipboard
operator fun div(other: Energy): Double

Returns the ratio of this Energy to the other.

operator fun div(scale: Number): Energy

Divides this Energy value by the given scale value.

Link copied to clipboard
operator fun minus(other: Energy): Energy

Subtracts another Energy instance from this one.

Link copied to clipboard
operator fun plus(other: Energy): Energy

Adds two Energy values.

Link copied to clipboard
operator fun times(scale: Number): Energy

Scales this Energy by the specified scale factor.