Skip to content

Commit

Permalink
Use require instead of raw throws for validation requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
rayrobdod committed Jun 11, 2024
1 parent 05b7351 commit e1aed72
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Base/src/main/scala/CodePoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.math.Ordering
* Represents a unicode codepoint
*/
final class CodePoint private (val intValue:Int) {
if (! Character.isValidCodePoint(intValue)) throw new IllegalArgumentException(s"$intValue")
require(Character.isValidCodePoint(intValue), s"$intValue is not a valid codepoint")

override def toString:String = new String(Array[Int](intValue), 0, 1)
override def hashCode:Int = intValue
Expand Down
7 changes: 2 additions & 5 deletions TimeParser/src/main/scala/Digit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ final class Digits(val value:Int)

object Digit {
def apply(x:Char):Digit = {
if ('0' <= x && x <= '9') {
new Digit(x - '0')
} else {
throw new IllegalArgumentException("Expected ascii digit")
}
require('0' <= x && x <= '9', "Expected ascii digit")
new Digit(x - '0')
}

implicit def given_Repeated:Repeated[Digit, Digits] = new Repeated[Digit, Digits]{
Expand Down

0 comments on commit e1aed72

Please sign in to comment.