From 5d8f9d955b8acab04a7356572fbb3c3f91d845f5 Mon Sep 17 00:00:00 2001 From: Frank Viernau Date: Fri, 24 May 2024 18:09:58 +0200 Subject: [PATCH] refactor(model): Stop implementing Comparable with DependencyReference The first two test cases of `AnalyzerResultBuilder` [1] compare instances of `DependencyReference`s in their assertion. Without the `Comparable` interface implemented, these assertions fail because the equality is changed to compare whether the instances (memory locations) are the same. So, turn the `DependencyReference` into a data class to fix that. [1]: https://github.com/oss-review-toolkit/ort/blob/41b450b11c5930179016ba1a54d77e03f0c70b4c/analyzer/src/test/kotlin/AnalyzerResultBuilderTest.kt#L128-L154 Signed-off-by: Frank Viernau --- model/src/main/kotlin/DependencyGraph.kt | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/model/src/main/kotlin/DependencyGraph.kt b/model/src/main/kotlin/DependencyGraph.kt index b073fa06ca3c5..125149619ea98 100644 --- a/model/src/main/kotlin/DependencyGraph.kt +++ b/model/src/main/kotlin/DependencyGraph.kt @@ -295,7 +295,7 @@ data class RootDependencyIndex( * Note: This is by intention no data class. Equality is tested via references and not via the values contained. */ @JsonInclude(JsonInclude.Include.NON_DEFAULT) -class DependencyReference( +data class DependencyReference( /** * Stores the numeric index of the package dependency referenced by this object. The package behind this index can * be resolved by evaluating the list of identifiers stored in [DependencyGraph] at this index. @@ -326,17 +326,7 @@ class DependencyReference( * A list of [Issue]s that occurred handling this dependency. */ val issues: List = emptyList() -) : Comparable { - /** - * Define an order on [DependencyReference] instances. Instances are ordered by their indices and fragment indices. - */ - override fun compareTo(other: DependencyReference): Int = - if (pkg != other.pkg) { - pkg - other.pkg - } else { - fragment - other.fragment - } -} +) /** * A data class representing a node in the dependency graph.