Repository: square/okhttp
File: okhttp/src/main/kotlin/okhttp3/CacheControl.kt (Kotlin)

Code before:
    fun noCache() = commonNoCache()

    /** Don't store the server's response in any cache. */
    fun noStore() = commonNoStore()

    /**
     * Only accept the response if it is in the cache. If the response isn't cached, a `504
     * Unsatisfiable Request` response will be returned.
     */
    fun onlyIfCached() = commonOnlyIfCached()

    /** Don't accept a transformed response. */
    fun noTransform() = commonNoTransform()

    fun immutable() = commonImmutable()

    /**
     * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it
     * will not be used and a network request will be made.
     *
     * @param maxAge a non-negative duration. This is stored and transmitted with [TimeUnit.SECONDS]
     *     precision; finer precision will be lost.
     */
    @JvmSynthetic // Don't expose @JvmInline types in the Java API.
    fun maxAge(maxAge: Duration) = apply {
      require(maxAge.inWholeSeconds >= 0) { "maxAge < 0: ${maxAge.inWholeSeconds}" }
      maxAgeSeconds = maxAge.inWholeSeconds.commonClampToInt()
    }

    @JvmSynthetic // Don't expose @JvmInline types in the Java API.
    fun maxStale(maxStale: Duration) = apply {
      require(maxStale.inWholeSeconds >= 0) { "maxStale < 0: ${maxStale.inWholeSeconds}" }
      maxStaleSeconds = maxStale.inWholeSeconds.commonClampToInt()
    }

    @JvmSynthetic // Don't expose @JvmInline types in the Java API.
    fun minFresh(minFresh: Duration) = apply {
      require(minFresh.inWholeSeconds >= 0) { "minFresh < 0: ${minFresh.inWholeSeconds}" }
      minFreshSeconds = minFresh.inWholeSeconds.commonClampToInt()
    }

    /**
     * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it
     * will not be used and a network request will be made.
     *
     * @param maxAge a non-negative integer. This is stored and transmitted with [TimeUnit.SECONDS]
     *     precision; finer precision will be lost.
     */
    fun maxAge(
      maxAge: Int,
      timeUnit: TimeUnit,

Review comment (suggestion):
If you do
```suggestion
      require(!maxAge.isNegative()) { "maxAge < 0: ${maxAge.inWholeSeconds}" }
```
you avoid having to do an internal conversion solely to perform the check

Code after:
    fun noCache() = commonNoCache()

    /** Don't store the server's response in any cache. */
    fun noStore() = commonNoStore()

    /**
     * Only accept the response if it is in the cache. If the response isn't cached, a `504
     * Unsatisfiable Request` response will be returned.
     */
    fun onlyIfCached() = commonOnlyIfCached()

    /** Don't accept a transformed response. */
    fun noTransform() = commonNoTransform()

    fun immutable() = commonImmutable()

    /**
     * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it
     * will not be used and a network request will be made.
     *
     * @param maxAge a non-negative duration. This is stored and transmitted with [TimeUnit.SECONDS]
     *     precision; finer precision will be lost.
     */
    fun maxAge(maxAge: Duration) =
      apply {
        val maxAgeSeconds = maxAge.inWholeSeconds
        require(maxAgeSeconds >= 0) { "maxAge < 0: $maxAgeSeconds" }
        this.maxAgeSeconds = maxAgeSeconds.commonClampToInt()
      }

    fun maxStale(maxStale: Duration) =
      apply {
        val maxStaleSeconds = maxStale.inWholeSeconds
        require(maxStaleSeconds >= 0) { "maxStale < 0: $maxStaleSeconds" }
        this.maxStaleSeconds = maxStaleSeconds.commonClampToInt()
      }

    fun minFresh(minFresh: Duration) =
      apply {
        val minFreshSeconds = minFresh.inWholeSeconds
        require(minFreshSeconds >= 0) { "minFresh < 0: $minFreshSeconds" }
        this.minFreshSeconds = minFreshSeconds.commonClampToInt()
      }

    /**
     * Sets the maximum age of a cached response. If the cache response's age exceeds [maxAge], it
     * will not be used and a network request will be made.
     *
     * @param maxAge a non-negative integer. This is stored and transmitted with [TimeUnit.SECONDS]
     *     precision; finer precision will be lost.
     */