• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.onboarding.contracts
2 
3 import com.google.errorprone.annotations.CanIgnoreReturnValue
4 import kotlin.jvm.Throws
5 
6 /** Implementing entities provide means to validate the correctness of [A] */
7 interface ArgumentValidator<A : Any> {
8   /**
9    * Validates given object or throws an exception
10    *
11    * @receiver the object to validate
12    */
validatenull13   @Throws(IllegalArgumentException::class) fun A.validate()
14 }
15 
16 /**
17  * Chaining-enabled validation condition that throws an error if it's not met
18  *
19  * @param message to pass when throwing an error
20  * @param condition lambda describing correct state
21  * @receiver the value to validate
22  */
23 @Throws(IllegalArgumentException::class)
24 @CanIgnoreReturnValue
25 inline fun <V> V.require(message: String, condition: (V) -> Boolean): V = also {
26   require(condition(this)) { message }
27 }
28