Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions library/api/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package me.saket.bytesize {
method public inline operator long plus(me.saket.bytesize.ByteSize other);
method public inline long times(Number other);
method public inline String toString();
method public operator long unaryMinus();
property public inline long inWholeBytes;
property public final inline long inWholeGibibytes;
property public final inline long inWholeKibibytes;
Expand All @@ -32,6 +33,7 @@ package me.saket.bytesize {
method public operator me.saket.bytesize.ByteSize minus(me.saket.bytesize.ByteSize other);
method public operator me.saket.bytesize.ByteSize plus(me.saket.bytesize.ByteSize other);
method public operator me.saket.bytesize.ByteSize times(Number other);
method public operator me.saket.bytesize.ByteSize unaryMinus();
property public abstract long inWholeBytes;
}

Expand All @@ -57,6 +59,7 @@ package me.saket.bytesize {
method public inline long plus(me.saket.bytesize.ByteSize other);
method public inline long times(Number other);
method public inline String toString();
method public operator long unaryMinus();
property public inline long inWholeBits;
property public inline long inWholeBytes;
property public final inline long inWholeGigabits;
Expand All @@ -82,6 +85,7 @@ package me.saket.bytesize {
method public inline operator long plus(me.saket.bytesize.ByteSize other);
method public inline long times(Number other);
method public inline String toString();
method public operator long unaryMinus();
property public inline long inWholeBytes;
property public final inline long inWholeGigabytes;
property public final inline long inWholeKilobytes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ value class BinaryByteSize(
override inline fun div(other: Number): BinaryByteSize =
BinaryByteSize(commonDiv(other))

override operator fun unaryMinus(): BinaryByteSize =

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing inline for all the 3 impls.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Np, I can add these

BinaryByteSize(-bytes)

override inline fun compareTo(other: ByteSize): Int =
commonCompareTo(other)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sealed interface ByteSize : Comparable<ByteSize> {
operator fun times(other: Number): ByteSize
operator fun div(other: ByteSize): Double
operator fun div(other: Number): ByteSize
operator fun unaryMinus(): ByteSize
}

inline operator fun Number.times(other: ByteSize): ByteSize =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ value class DecimalBitSize(
return DecimalBitSize(bits = commonDiv(other))
}

override operator fun unaryMinus(): DecimalBitSize =
DecimalBitSize(-bits)

override inline fun compareTo(other: ByteSize): Int {
return commonCompareTo(other)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ value class DecimalByteSize(
override inline fun div(other: Number): DecimalByteSize =
DecimalByteSize(commonDiv(other))

override operator fun unaryMinus(): DecimalByteSize =
DecimalByteSize(-bytes)

override inline fun compareTo(other: ByteSize): Int =
commonCompareTo(other)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,12 @@ class BinaryByteSizeTest {
BinaryByteSize(500.50)
}.hasMessage(BytePrecisionLossErrorMessage)
}

@Test fun unary_minus() {
val twelve = 12.binaryBytes
val negativeTwelve = -twelve
assertThat(negativeTwelve).isEqualTo((-12).binaryBytes)
val positiveTwelve = -negativeTwelve
assertThat(positiveTwelve).isEqualTo(twelve)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@ class DecimalBitSizeTest {
DecimalBitSize(123.45)
}.hasMessage(BitPrecisionLossErrorMessage)
}

@Test fun unary_minus() {
val twelve = 12.decimalBits
val negativeTwelve = -twelve
assertThat(negativeTwelve).isEqualTo((-12).decimalBits)
val positiveTwelve = -negativeTwelve
assertThat(positiveTwelve).isEqualTo(twelve)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,12 @@ class DecimalByteSizeTest {
DecimalByteSize(500.50)
}.hasMessage(BytePrecisionLossErrorMessage)
}

@Test fun unary_minus() {
val twelve = 12.decimalBytes
val negativeTwelve = -twelve
assertThat(negativeTwelve).isEqualTo((-12).decimalBytes)
val positiveTwelve = -negativeTwelve
assertThat(positiveTwelve).isEqualTo(twelve)
}
}
Loading