Skip to content

Commit

Permalink
refactor: convert message and overflowValue to val
Browse files Browse the repository at this point in the history
  • Loading branch information
lbressler13 committed Jan 23, 2024
1 parent 64c7cd2 commit 1ecc436
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ package xyz.lbres.exactnumbers.exactfraction
* [ArithmeticException] for ExactFraction overflow.
* Has field for string representation of value that caused overflow
*/
class ExactFractionOverflowException() : ArithmeticException() {
override var message: String? = null
var overflowValue: String? = null
class ExactFractionOverflowException private constructor(message: String?, overflowValue: String?, noArgs: Boolean) : ArithmeticException() {
override val message: String?
val overflowValue: String?

constructor (message: String) : this() {
init {
this.message = message
}

constructor (message: String, overflowValue: String) : this(message) {
this.overflowValue = overflowValue
}

constructor() : this(null, null, true)

constructor(message: String) : this(message, null, false)

constructor(message: String, overflowValue: String) : this(message, overflowValue, false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,28 @@ package xyz.lbres.exactnumbers.exceptions
/**
* ArithmeticException for overflows when casting numbers
*/
class CastingOverflowException() : ArithmeticException() {
override var message: String? = null
var overflowValue: Any? = null
class CastingOverflowException private constructor(baseType: String, targetType: String, valueString: String, overflowValue: Any?, noArgs: Boolean) : ArithmeticException() {
override val message: String?
val overflowValue: Any?

init {
if (noArgs) {
this.message = null
this.overflowValue = null
} else {
this.message = "Overflow casting value $valueString of type $baseType to $targetType"
this.overflowValue = overflowValue
}
}

constructor() : this("", "", "", null, true)

/**
* @param baseType [String]: name of type being cast from
* @param targetType [String]: name of type being cast to
* @param valueString [String]: string to display for value that caused overflow
* @param overflowValue [Any]?: number that caused overflow. Optional, defaults to `null`
*/
constructor (baseType: String, targetType: String, valueString: String, overflowValue: Any? = null) : this() {
this.message = "Overflow casting value $valueString of type $baseType to $targetType"
this.overflowValue = overflowValue
}
constructor (baseType: String, targetType: String, valueString: String, overflowValue: Any? = null) :
this(baseType, targetType, valueString, overflowValue, false)
}
10 changes: 9 additions & 1 deletion signatures/v1.0.0/updates.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@ ADD fun pow(other: Int): ExactFraction
ADD fun roundToWhole(roundingMode: RoundingMode): ExactFraction
```

**Other**
**ExactFractionOverflowException**
```kotlin
DEL var message: String?
ADD val message: String?

DEL var overflowValue: String?
ADD val overflowValue: String?
```

**Other**
```kotlin
DEL fun checkIsEFString(s: String): Boolean
```
Expand Down
10 changes: 5 additions & 5 deletions signatures/v1.0.0/v1.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ ExactFractionOverflowException()
ExactFractionOverflowException(message: String)
ExactFractionOverflowException(message: String, overflowValue: String)

var message: String?
var overflowValue: String?
val message: String?
val overflowValue: String?
```

### xyz.lbres.exactnumbers.exceptions
Expand All @@ -115,8 +115,8 @@ class CastingOverflowException: ArithmeticException()
CastingOverflowException()
CastingOverflowException(baseType: String, targetType: String, valueString: String, overflowValue: Any?)

var message: String?
var overflowValue: Any?
val message: String?
val overflowValue: Any?
```

### xyz.lbres.exactnumbers.expressions.term
Expand Down Expand Up @@ -261,5 +261,5 @@ val ONE: Sqrt
### xyz.lbres.expression.term

```kotlin
class Term // DEPRECATED
typealias Term = xyz.lbres.exactnumbers.expressions.term.Term // DEPRECATED
```

0 comments on commit 1ecc436

Please sign in to comment.