Skip to content

Commit

Permalink
Reformat, add size()
Browse files Browse the repository at this point in the history
  • Loading branch information
io7m committed Apr 24, 2024
1 parent 06a73e3 commit b189ee4
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ package com.io7m.kabstand.core
import java.math.BigInteger

data class IntervalB(
val lower : BigInteger, val upper : BigInteger
val lower : BigInteger,
val upper : BigInteger
) : IntervalType<BigInteger> {

init {
Expand All @@ -38,6 +39,10 @@ data class IntervalB(
return IntervalB(lower, upper.max(other.upper()))
}

override fun size() : BigInteger {
return BigInteger.ONE + (this.upper - this.lower)
}

override fun upper() : BigInteger {
return this.upper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ data class IntervalD(
)
}

override fun size() : Double {
return 1.0 + (this.upper - this.lower)
}

override fun upper() : Double {
return this.upper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ data class IntervalI(
)
}

override fun size() : Int {
return 1 + (this.upper - this.lower)
}

override fun upper() : Int {
return this.upper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ data class IntervalL(
) : IntervalType<Long> {

init {
check(upper >= lower) { "Upper $upper must be >= lower $lower " }
check(this.upper >= this.lower) { "Upper ${this.upper} must be >= lower ${this.lower} " }
}

override fun overlaps(
Expand All @@ -38,6 +38,10 @@ data class IntervalL(
)
}

override fun size() : Long {
return 1L + (this.upper - this.lower)
}

override fun upper() : Long {
return this.upper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ interface IntervalType<S : Comparable<S>> : Comparable<IntervalType<S>> {

fun overlaps(other : IntervalType<S>) : Boolean

/**
* The interval size (1 + (upper - lower))
*/

fun size() : S

/**
* @return The inclusive upper bound
*/
Expand Down

0 comments on commit b189ee4

Please sign in to comment.