Skip to content

Commit

Permalink
Implement Comparable (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm authored Dec 11, 2023
1 parent 44b5c2b commit 5dc6a4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<File> {

// Not exposing any secondary constructors because
// Jvm has undocumented behavior that cannot be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.matthewnelson.kmp.file

import io.matthewnelson.kmp.file.internal.*

public actual class File {
public actual class File: Comparable<File> {

private val realPath: Path

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5dc6a4e

Please sign in to comment.