Skip to content

Commit

Permalink
🔥 Remove Zero.isEqualTo(Byte) function from types
Browse files Browse the repository at this point in the history
Only the `Zero.toByte()` function from the `types` Gradle subproject is necessary for the `ZeroAsByteSerializer` type from the `types-kotlinx-serialization` subproject.
  • Loading branch information
LVMVRQUXL committed Apr 15, 2024
1 parent 9decf2b commit 9517776
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal object ZeroAsByteSerializer : KSerializer<Zero> {

override fun deserialize(decoder: Decoder): Zero {
val decodedValue: Byte = decoder.decodeByte()
if (Zero isEqualTo decodedValue) return Zero
val zeroAsByte: Byte = Zero.toByte()
if (decodedValue == zeroAsByte) return Zero
val message: String = this.deserializationErrorMessage(decodedValue)
throw SerializationException(message)
}
Expand Down
1 change: 0 additions & 1 deletion subprojects/library/src/api/types.api
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,6 @@ public final class org/kotools/types/EmailAddress$Companion {

public final class org/kotools/types/Zero {
public static final field INSTANCE Lorg/kotools/types/Zero;
public final fun isEqualTo (B)Z
public final fun toByte ()B
public final fun toString ()Ljava/lang/String;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,6 @@ import org.kotools.types.internal.KotoolsTypesVersion
public object Zero {
private const val VALUE: Byte = 0

/**
* Returns `true` if the specified [number] equals zero.
*
* <br>
* <details open>
* <summary>
* <b>Calling from Kotlin</b>
* </summary>
*
* Here's an example of calling this function from Kotlin code:
*
* SAMPLE: ZeroKotlinSample.isEqualTo_Byte.md
* </details>
*
* <br>
* <details>
* <summary>
* <b>Calling from Java</b>
* </summary>
*
* Here's an example of calling this function from Java code:
*
* SAMPLE: ZeroJavaSample.isEqualTo_Byte.md
* </details>
*/
public infix fun isEqualTo(number: Byte): Boolean = this.VALUE == number

/**
* Returns this number as [Byte].
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,8 @@ package org.kotools.types
import kotools.types.experimental.ExperimentalKotoolsTypesApi
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertTrue

class ZeroTest {
@OptIn(ExperimentalKotoolsTypesApi::class)
@Test
fun isEqualTo_should_pass_with_a_Byte_that_equals_zero() {
val number: Byte = 0
val actual: Boolean = Zero isEqualTo number
assertTrue(actual, "$number should be considered as zero.")
}

@OptIn(ExperimentalKotoolsTypesApi::class)
@Test
fun isEqualTo_should_fail_with_a_Byte_other_than_zero() {
val number: Byte = listOf(Byte.MIN_VALUE..-1, 1..Byte.MAX_VALUE)
.random()
.random()
.toByte()
val actual: Boolean = Zero isEqualTo number
assertFalse(actual, "$number shouldn't be considered as zero.")
}

@OptIn(ExperimentalKotoolsTypesApi::class)
@Test
fun toByte_should_pass() {
Expand Down
6 changes: 0 additions & 6 deletions subprojects/samples/src/main/java/ZeroJavaSample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package org.kotools.types;

class ZeroJavaSample {
void isEqualTo_Byte() {
final byte number = 0;
final boolean result = Zero.INSTANCE.isEqualTo(number);
System.out.println(result); // true
} // END

void toByte() {
final byte number = Zero.INSTANCE.toByte();
System.out.println(number); // 0
Expand Down
7 changes: 0 additions & 7 deletions subprojects/samples/src/main/kotlin/ZeroKotlinSample.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ import kotools.types.experimental.ExperimentalKotoolsTypesApi

@OptIn(ExperimentalKotoolsTypesApi::class)
internal object ZeroKotlinSample {
@Suppress("FunctionName")
fun isEqualTo_Byte() {
val number: Byte = 0
val result: Boolean = Zero isEqualTo number
println(result) // true
} // END

fun toByte() {
val number: Byte = Zero.toByte()
println(number) // 0
Expand Down
6 changes: 0 additions & 6 deletions subprojects/samples/src/test/java/ZeroJavaSampleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
import org.junit.jupiter.api.Test;

class ZeroJavaSampleTest {
@Test
void isEqualTo_Byte_should_pass() {
final ZeroJavaSample sample = new ZeroJavaSample();
Assert.printsTrue(sample::isEqualTo_Byte);
}

@Test
void toByte_should_pass() {
final ZeroJavaSample sample = new ZeroJavaSample();
Expand Down
4 changes: 0 additions & 4 deletions subprojects/samples/src/test/kotlin/ZeroKotlinSampleTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ package org.kotools.types
import kotlin.test.Test

class ZeroKotlinSampleTest {
@Test
fun `isEqualTo(Byte) should pass`(): Unit =
assertPrintsTrue(ZeroKotlinSample::isEqualTo_Byte)

@Test
fun `toByte() should pass`() {
val expected = "0"
Expand Down

0 comments on commit 9517776

Please sign in to comment.