checkpoint-core-abstraction / com.natigbabayev.checkpoint.core / Rule

Rule

abstract class Rule<INPUT, OUTPUT>

Rules are main part of checkpoint. Rule.canPass function can be invoked directly or used by child classes. When new rule is needed, this class can be extended with the desired input and output type.

Parameters

INPUT - value which will be validated

OUTPUT - result of Rule.isValid. This can be Boolean or any other desired return value (i.e. Observable).

Types

Callback

interface Callback<INPUT>

Constructors

<init>

Rules are main part of checkpoint. Rule.canPass function can be invoked directly or used by child classes. When new rule is needed, this class can be extended with the desired input and output type.

Rule()

Properties

callback

Callback which is used by Rule.invokeCallback when Rule.isValid returns false

abstract val callback: Callback<INPUT>?

Functions

canPass

Main entry point of class. This function should invoke Rule.isValid with given input and pass result to Rule.invokeCallback.

abstract fun canPass(input: INPUT): OUTPUT

invokeCallback

When isValid is false, this function will invoke Callback.whenInvalid. Typically, this function should be invoked from Rule.canPass, after result of Rule.isValid is ready.

fun invokeCallback(input: INPUT, isValid: Boolean): Unit

isValid

Function used to define whether a condition is satisfied with given input. Typically, this function should be invoked from Rule.canPass.

abstract fun isValid(input: INPUT): OUTPUT

Inheritors

DefaultRule

Child of Rule with Boolean output.

abstract class DefaultRule<INPUT> : Rule<INPUT, Boolean>