From 5dc6a4ed60d207c33e40f82ba3624a1cd5015f13 Mon Sep 17 00:00:00 2001 From: Matthew Nelson Date: Sun, 10 Dec 2023 21:30:40 -0500 Subject: [PATCH] Implement `Comparable` (#20) --- .../src/commonMain/kotlin/io/matthewnelson/kmp/file/File.kt | 2 +- .../nonJvmMain/kotlin/io/matthewnelson/kmp/file/FileNonJvm.kt | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/file/src/commonMain/kotlin/io/matthewnelson/kmp/file/File.kt b/library/file/src/commonMain/kotlin/io/matthewnelson/kmp/file/File.kt index 1562514..c2c3f05 100644 --- a/library/file/src/commonMain/kotlin/io/matthewnelson/kmp/file/File.kt +++ b/library/file/src/commonMain/kotlin/io/matthewnelson/kmp/file/File.kt @@ -36,7 +36,7 @@ public fun String.toFile(): File = File(this) /** * A File * */ -public expect class File(pathname: String) { +public expect class File(pathname: String): Comparable { // Not exposing any secondary constructors because // Jvm has undocumented behavior that cannot be diff --git a/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/FileNonJvm.kt b/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/FileNonJvm.kt index d479a02..a8e1d5c 100644 --- a/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/FileNonJvm.kt +++ b/library/file/src/nonJvmMain/kotlin/io/matthewnelson/kmp/file/FileNonJvm.kt @@ -19,7 +19,7 @@ package io.matthewnelson.kmp.file import io.matthewnelson.kmp.file.internal.* -public actual class File { +public actual class File: Comparable { private val realPath: Path @@ -101,6 +101,8 @@ public actual class File { return File(path, direct = null) } + override fun compareTo(other: File): Int = realPath.compareTo(other.realPath) + override fun equals(other: Any?): Boolean = other is File && other.realPath == realPath override fun hashCode(): Int = realPath.hashCode() xor 1234321 override fun toString(): String = realPath