Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Change number assertion value type from Int to Long, resolves #7
Browse files Browse the repository at this point in the history
  • Loading branch information
cooppor authored and afollestad committed Jul 3, 2019
1 parent 03887f8 commit 23dd31f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,49 +89,49 @@ sealed class InputAssertions {

/** @author Aidan Follestad (@afollestad) */
class NumberAssertion internal constructor() : Assertion<EditText, NumberAssertion>() {
private var exactly: Int? = null
private var lessThan: Int? = null
private var atMost: Int? = null
private var atLeast: Int? = null
private var greaterThan: Int? = null
private var exactly: Long? = null
private var lessThan: Long? = null
private var atMost: Long? = null
private var atLeast: Long? = null
private var greaterThan: Long? = null

/** Asserts the number is an exact (=) value. */
fun exactly(length: Int): NumberAssertion {
fun exactly(length: Long): NumberAssertion {
exactly = length
return this
}

/** Asserts the number is less than (<) a value. */
fun lessThan(length: Int): NumberAssertion {
fun lessThan(length: Long): NumberAssertion {
lessThan = length
return this
}

/** Asserts the number is at most (<=) a value. */
fun atMost(length: Int): NumberAssertion {
fun atMost(length: Long): NumberAssertion {
atMost = length
return this
}

/** Asserts the number is at least (>=) a value. */
fun atLeast(length: Int): NumberAssertion {
fun atLeast(length: Long): NumberAssertion {
atLeast = length
return this
}

/** Asserts the number is greater (>) than a value. */
fun greaterThan(length: Int): NumberAssertion {
fun greaterThan(length: Long): NumberAssertion {
greaterThan = length
return this
}

override fun isValid(view: EditText): Boolean {
val intValue = view.text().toIntOrNull() ?: return false
if (exactly != null && intValue != exactly!!) return false
if (lessThan != null && intValue >= lessThan!!) return false
if (atMost != null && intValue > atMost!!) return false
if (atLeast != null && intValue < atLeast!!) return false
if (greaterThan != null && intValue <= greaterThan!!) return false
val longValue = view.text().toLongOrNull() ?: return false
if (exactly != null && longValue != exactly!!) return false
if (lessThan != null && longValue >= lessThan!!) return false
if (atMost != null && longValue > atMost!!) return false
if (atLeast != null && longValue < atLeast!!) return false
if (greaterThan != null && longValue <= greaterThan!!) return false
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,50 +90,50 @@ sealed class InputLayoutAssertions {

/** @author Aidan Follestad (@afollestad) */
class NumberAssertion internal constructor() : Assertion<TextInputLayout, NumberAssertion>() {
private var exactly: Int? = null
private var lessThan: Int? = null
private var atMost: Int? = null
private var atLeast: Int? = null
private var greaterThan: Int? = null
private var exactly: Long? = null
private var lessThan: Long? = null
private var atMost: Long? = null
private var atLeast: Long? = null
private var greaterThan: Long? = null

/** Asserts the number is an exact (=) value. */
fun exactly(length: Int): NumberAssertion {
fun exactly(length: Long): NumberAssertion {
exactly = length
return this
}

/** Asserts the number is less than (<) a value. */
fun lessThan(length: Int): NumberAssertion {
fun lessThan(length: Long): NumberAssertion {
lessThan = length
return this
}

/** Asserts the number is at most (<=) a value. */
fun atMost(length: Int): NumberAssertion {
fun atMost(length: Long): NumberAssertion {
atMost = length
return this
}

/** Asserts the number is at least (>=) a value. */
fun atLeast(length: Int): NumberAssertion {
fun atLeast(length: Long): NumberAssertion {
atLeast = length
return this
}

/** Asserts the number is greater (>) than a value. */
fun greaterThan(length: Int): NumberAssertion {
fun greaterThan(length: Long): NumberAssertion {
greaterThan = length
return this
}

override fun isValid(view: TextInputLayout): Boolean {
val intValue = view.text().toIntOrNull() ?: return false
val longValue = view.text().toLongOrNull() ?: return false
return when {
exactly != null && intValue != exactly!! -> false
lessThan != null && intValue >= lessThan!! -> false
atMost != null && intValue > atMost!! -> false
atLeast != null && intValue < atLeast!! -> false
greaterThan != null && intValue <= greaterThan!! -> false
exactly != null && longValue != exactly!! -> false
lessThan != null && longValue >= lessThan!! -> false
atMost != null && longValue > atMost!! -> false
atLeast != null && longValue < atLeast!! -> false
greaterThan != null && longValue <= greaterThan!! -> false
else -> true
}
}
Expand Down Expand Up @@ -187,13 +187,13 @@ sealed class InputLayoutAssertions {
}

override fun isValid(view: TextInputLayout): Boolean {
val intValue = view.text().toDoubleOrNull() ?: return false
val doubleValue = view.text().toDoubleOrNull() ?: return false
return when {
exactly != null && intValue != exactly!! -> false
lessThan != null && intValue >= lessThan!! -> false
atMost != null && intValue > atMost!! -> false
atLeast != null && intValue < atLeast!! -> false
greaterThan != null && intValue <= greaterThan!! -> false
exactly != null && doubleValue != exactly!! -> false
lessThan != null && doubleValue >= lessThan!! -> false
atMost != null && doubleValue > atMost!! -> false
atLeast != null && doubleValue < atLeast!! -> false
greaterThan != null && doubleValue <= greaterThan!! -> false
else -> true
}
}
Expand Down

0 comments on commit 23dd31f

Please sign in to comment.