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

com.autonomousapps.extension.Behavior.kt Maven / Gradle / Ivy

There is a newer version: 2.0.2
Show newest version
package com.autonomousapps.extension

import java.io.Serializable

sealed class Behavior(val filter: Set = setOf()) : Serializable, Comparable {
  /**
   * [Fail] > [Ignore] > [Warn] > [Undefined].
   */
  override fun compareTo(other: Behavior): Int {
    return when (other) {
      is Undefined -> {
        if (this is Undefined) 0 else 1
      }

      is Fail -> {
        if (this is Fail) 0 else -1
      }

      is Ignore -> {
        when (this) {
          is Fail -> 1
          is Ignore -> 0
          is Warn -> -1
          is Undefined -> -1
        }
      }

      is Warn -> {
        when (this) {
          is Fail, Ignore -> 1
          is Warn -> 0
          is Undefined -> -1
        }
      }
    }
  }
}

class Fail(filter: Set = mutableSetOf()) : Behavior(filter)
class Warn(filter: Set = mutableSetOf()) : Behavior(filter)
object Ignore : Behavior()
class Undefined(filter: Set = mutableSetOf()) : Behavior(filter)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy