All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.islandtime.measures._Centuries.kt Maven / Gradle / Ivy

The newest version!
//
// This file is auto-generated by 'tools:code-generator'
//
@file:JvmMultifileClass
@file:JvmName("CenturiesKt")

package io.islandtime.measures

import dev.erikchristensen.javamath2kmp.minusExact
import dev.erikchristensen.javamath2kmp.negateExact
import dev.erikchristensen.javamath2kmp.plusExact
import dev.erikchristensen.javamath2kmp.timesExact
import dev.erikchristensen.javamath2kmp.toIntExact
import io.islandtime.internal.DECADES_PER_CENTURY
import io.islandtime.internal.MONTHS_PER_CENTURY
import io.islandtime.internal.YEARS_PER_CENTURY
import kotlin.Boolean
import kotlin.Comparable
import kotlin.Int
import kotlin.Long
import kotlin.PublishedApi
import kotlin.String
import kotlin.jvm.JvmMultifileClass
import kotlin.jvm.JvmName
import kotlin.math.absoluteValue

/**
 * A number of centuries.
 */
inline class IntCenturies(
  /**
   * The underlying value.
   */
  val value: Int
) : Comparable {
  /**
   * The absolute value of this duration.
   * @throws ArithmeticException if overflow occurs
   */
  val absoluteValue: IntCenturies
    get() = if (value < 0) -this else this
  /**
   * Converts this duration to months.
   * @throws ArithmeticException if overflow occurs
   */
  val inMonths: IntMonths
    get() = (value timesExact MONTHS_PER_CENTURY).months

  /**
   * Converts this duration to months without checking for overflow.
   */
  internal val inMonthsUnchecked: IntMonths
    get() = (value * MONTHS_PER_CENTURY).months

  /**
   * Converts this duration to years.
   * @throws ArithmeticException if overflow occurs
   */
  val inYears: IntYears
    get() = (value timesExact YEARS_PER_CENTURY).years

  /**
   * Converts this duration to years without checking for overflow.
   */
  internal val inYearsUnchecked: IntYears
    get() = (value * YEARS_PER_CENTURY).years

  /**
   * Converts this duration to decades.
   * @throws ArithmeticException if overflow occurs
   */
  val inDecades: IntDecades
    get() = (value timesExact DECADES_PER_CENTURY).decades

  /**
   * Converts this duration to decades without checking for overflow.
   */
  internal val inDecadesUnchecked: IntDecades
    get() = (value * DECADES_PER_CENTURY).decades

  /**
   * Checks if this duration is zero.
   */
  fun isZero(): Boolean = value == 0

  /**
   * Checks if this duration is negative.
   */
  fun isNegative(): Boolean = value < 0

  /**
   * Checks if this duration is positive.
   */
  fun isPositive(): Boolean = value > 0

  override fun compareTo(other: IntCenturies): Int = value.compareTo(other.value)

  /**
   * Converts this duration to an ISO-8601 time interval representation.
   */
  override fun toString(): String {
     return when (value) {
       0 -> "P0Y"
       Int.MIN_VALUE -> "-P2147483648Y"
       else -> buildString {
         if (value < 0) { append('-') }
         append("P")
         append(value.absoluteValue timesExact 100)
         append('Y')
       }
     }
  }

  /**
   * Negates this duration.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun unaryMinus() = IntCenturies(value.negateExact())

  /**
   * Negates this duration without checking for overflow.
   */
  internal fun negateUnchecked() = IntCenturies(-value)

  /**
   * Multiplies this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun times(scalar: Int) = IntCenturies(value timesExact scalar)

  /**
   * Multiplies this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun times(scalar: Long) = this.toLongCenturies() * scalar

  /**
   * Divides this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs or the scalar is zero
   */
  operator fun div(scalar: Int): IntCenturies {
     return if (scalar == -1) {
       -this
     } else {
       IntCenturies(value / scalar)
     }
  }

  /**
   * Divides this duration by a scalar value.
   * @throws ArithmeticException if the scalar is zero
   */
  operator fun div(scalar: Long): LongCenturies = this.toLongCenturies() / scalar
  operator fun rem(scalar: Int) = IntCenturies(value % scalar)

  operator fun rem(scalar: Long) = this.toLongCenturies() % scalar

  operator fun plus(months: IntMonths) = this.inMonths + months

  operator fun minus(months: IntMonths) = this.inMonths - months

  operator fun plus(months: LongMonths) = this.toLongCenturies().inMonths + months

  operator fun minus(months: LongMonths) = this.toLongCenturies().inMonths - months

  operator fun plus(years: IntYears) = this.inYears + years

  operator fun minus(years: IntYears) = this.inYears - years

  operator fun plus(years: LongYears) = this.toLongCenturies().inYears + years

  operator fun minus(years: LongYears) = this.toLongCenturies().inYears - years

  operator fun plus(decades: IntDecades) = this.inDecades + decades

  operator fun minus(decades: IntDecades) = this.inDecades - decades

  operator fun plus(decades: LongDecades) = this.toLongCenturies().inDecades + decades

  operator fun minus(decades: LongDecades) = this.toLongCenturies().inDecades - decades

  operator fun plus(centuries: IntCenturies) = IntCenturies(value plusExact centuries.value)

  operator fun minus(centuries: IntCenturies) = IntCenturies(value minusExact centuries.value)

  operator fun plus(centuries: LongCenturies) = LongCenturies(value.toLong() plusExact
      centuries.value)

  operator fun minus(centuries: LongCenturies) = LongCenturies(value.toLong() minusExact
      centuries.value)

  /**
   * Converts this duration to [LongCenturies].
   */
  fun toLongCenturies() = LongCenturies(value.toLong())

  /**
   * Converts this duration to a `Long` value.
   */
  fun toLong() = value.toLong()

  companion object {
    /**
     * The smallest supported value.
     */
    val MIN: IntCenturies = IntCenturies(Int.MIN_VALUE)

    /**
     * The largest supported value.
     */
    val MAX: IntCenturies = IntCenturies(Int.MAX_VALUE)
  }
}

/**
 * Converts this value to a duration of centuries.
 */
val Int.centuries: IntCenturies
  get() = IntCenturies(this)

/**
 * Multiplies this value by a duration of centuries.
 * @throws ArithmeticException if overflow occurs
 */
operator fun Int.times(centuries: IntCenturies) = centuries * this

/**
 * Multiplies this value by a duration of centuries.
 * @throws ArithmeticException if overflow occurs
 */
operator fun Long.times(centuries: IntCenturies) = centuries * this

/**
 * A number of centuries.
 */
inline class LongCenturies(
  /**
   * The underlying value.
   */
  val value: Long
) : Comparable {
  /**
   * The absolute value of this duration.
   * @throws ArithmeticException if overflow occurs
   */
  val absoluteValue: LongCenturies
    get() = if (value < 0) -this else this
  /**
   * Converts this duration to months.
   * @throws ArithmeticException if overflow occurs
   */
  val inMonths: LongMonths
    get() = (value timesExact MONTHS_PER_CENTURY).months

  /**
   * Converts this duration to months without checking for overflow.
   */
  internal val inMonthsUnchecked: LongMonths
    get() = (value * MONTHS_PER_CENTURY).months

  /**
   * Converts this duration to years.
   * @throws ArithmeticException if overflow occurs
   */
  val inYears: LongYears
    get() = (value timesExact YEARS_PER_CENTURY).years

  /**
   * Converts this duration to years without checking for overflow.
   */
  internal val inYearsUnchecked: LongYears
    get() = (value * YEARS_PER_CENTURY).years

  /**
   * Converts this duration to decades.
   * @throws ArithmeticException if overflow occurs
   */
  val inDecades: LongDecades
    get() = (value timesExact DECADES_PER_CENTURY).decades

  /**
   * Converts this duration to decades without checking for overflow.
   */
  internal val inDecadesUnchecked: LongDecades
    get() = (value * DECADES_PER_CENTURY).decades

  /**
   * Checks if this duration is zero.
   */
  fun isZero(): Boolean = value == 0L

  /**
   * Checks if this duration is negative.
   */
  fun isNegative(): Boolean = value < 0L

  /**
   * Checks if this duration is positive.
   */
  fun isPositive(): Boolean = value > 0L

  override fun compareTo(other: LongCenturies): Int = value.compareTo(other.value)

  /**
   * Converts this duration to an ISO-8601 time interval representation.
   */
  override fun toString(): String {
     return when (value) {
       0L -> "P0Y"
       Long.MIN_VALUE -> "-P9223372036854775808Y"
       else -> buildString {
         if (value < 0) { append('-') }
         append("P")
         append(value.absoluteValue timesExact 100)
         append('Y')
       }
     }
  }

  /**
   * Negates this duration.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun unaryMinus() = LongCenturies(value.negateExact())

  /**
   * Negates this duration without checking for overflow.
   */
  internal fun negateUnchecked() = LongCenturies(-value)

  /**
   * Multiplies this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun times(scalar: Int) = LongCenturies(value timesExact scalar)

  /**
   * Multiplies this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs
   */
  operator fun times(scalar: Long) = LongCenturies(value timesExact scalar)

  /**
   * Divides this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs or the scalar is zero
   */
  operator fun div(scalar: Int): LongCenturies {
     return if (scalar == -1) {
       -this
     } else {
       LongCenturies(value / scalar)
     }
  }

  /**
   * Divides this duration by a scalar value.
   * @throws ArithmeticException if overflow occurs or the scalar is zero
   */
  operator fun div(scalar: Long): LongCenturies {
     return if (scalar == -1L) {
       -this
     } else {
       LongCenturies(value / scalar)
     }
  }

  operator fun rem(scalar: Int) = LongCenturies(value % scalar)

  operator fun rem(scalar: Long) = LongCenturies(value % scalar)

  operator fun plus(months: IntMonths) = this.inMonths + months

  operator fun minus(months: IntMonths) = this.inMonths - months

  operator fun plus(months: LongMonths) = this.inMonths + months

  operator fun minus(months: LongMonths) = this.inMonths - months

  operator fun plus(years: IntYears) = this.inYears + years

  operator fun minus(years: IntYears) = this.inYears - years

  operator fun plus(years: LongYears) = this.inYears + years

  operator fun minus(years: LongYears) = this.inYears - years

  operator fun plus(decades: IntDecades) = this.inDecades + decades

  operator fun minus(decades: IntDecades) = this.inDecades - decades

  operator fun plus(decades: LongDecades) = this.inDecades + decades

  operator fun minus(decades: LongDecades) = this.inDecades - decades

  operator fun plus(centuries: IntCenturies) = LongCenturies(value plusExact centuries.value)

  operator fun minus(centuries: IntCenturies) = LongCenturies(value minusExact centuries.value)

  operator fun plus(centuries: LongCenturies) = LongCenturies(value plusExact centuries.value)

  operator fun minus(centuries: LongCenturies) = LongCenturies(value minusExact centuries.value)

  /**
   * Converts this duration to [IntCenturies].
   * @throws ArithmeticException if overflow occurs
   */
  fun toIntCenturies() = IntCenturies(value.toIntExact())

  /**
   * Converts this duration to [IntCenturies] without checking for overflow.
   */
  @PublishedApi
  internal fun toIntCenturiesUnchecked() = IntCenturies(value.toInt())

  /**
   * Converts this duration to an `Int` value.
   * @throws ArithmeticException if overflow occurs
   */
  fun toInt() = value.toIntExact()

  /**
   * Converts this duration to an `Int` value without checking for overflow.
   */
  internal fun toIntUnchecked() = value.toInt()

  companion object {
    /**
     * The smallest supported value.
     */
    val MIN: LongCenturies = LongCenturies(Long.MIN_VALUE)

    /**
     * The largest supported value.
     */
    val MAX: LongCenturies = LongCenturies(Long.MAX_VALUE)
  }
}

/**
 * Converts this value to a duration of centuries.
 */
val Long.centuries: LongCenturies
  get() = LongCenturies(this)

/**
 * Multiplies this value by a duration of centuries.
 * @throws ArithmeticException if overflow occurs
 */
operator fun Int.times(centuries: LongCenturies) = centuries * this

/**
 * Multiplies this value by a duration of centuries.
 * @throws ArithmeticException if overflow occurs
 */
operator fun Long.times(centuries: LongCenturies) = centuries * this




© 2015 - 2025 Weber Informatics LLC | Privacy Policy