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

com.twitter.finatra.validation.ValidationResult.scala Maven / Gradle / Ivy

There is a newer version: 2.1.6
Show newest version
package com.twitter.finatra.validation

sealed trait ValidationResult {
  def isValid: Boolean
}

object ValidationResult {
  case object Valid extends ValidationResult {
    override val isValid = true
  }

  case class Invalid(message: String, code: ErrorCode = ErrorCode.Unknown) extends ValidationResult {
    override val isValid = false
  }

  @deprecated("Use ValidationResult.validate() to test a condition that must be true, validateNot() otherwise", "2015-11-04")
  def apply(isValid: Boolean, message: => String, code: ErrorCode = ErrorCode.Unknown): ValidationResult = {
    validate(isValid, message, code)
  }

  def validate(
    condition: Boolean,
    message: => String,
    code: ErrorCode = ErrorCode.Unknown): ValidationResult = {
    if (condition)
      Valid
    else
      Invalid(message, code)
  }

  def validateNot(
    condition: Boolean,
    message: => String,
    code: ErrorCode = ErrorCode.Unknown): ValidationResult = {
    validate(!condition, message, code)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy