Skip to content

Commit

Permalink
Sorting Collections simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperancinha committed Jan 16, 2024
1 parent fcd8548 commit 884cf51
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 2 deletions.
30 changes: 29 additions & 1 deletion jeorg-kotlin-crums/jeorg-kotlin-crums-4-variance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<configuration>
<experimentalCoroutines>enable</experimentalCoroutines>
<jvmTarget>${java.version}</jvmTarget>
<languageVersion>1.8</languageVersion>
<languageVersion>1.9</languageVersion>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -146,6 +146,34 @@
<artifactId>omni-coveragereporter-maven-plugin</artifactId>
<version>${omni-coveragereporter-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.jesperancinha.ktd

import java.util.Collections.sort

class CollectingCollections {
companion object {
@JvmStatic
fun main(args: Array<String> = emptyArray()) {
val mHullList = listOf(SquareFromZeroPoint(4, 2), SquareFromZeroPoint(2, 2))
sort(mHullList) { lhs, rhs ->
lhs.area().compareTo(rhs.area())
}
println(mHullList)
}
}
}

private fun SquareFromZeroPoint.area(): Double = (x * x + y + y).toDouble()

data class SquareFromZeroPoint(val x: Long, val y: Long)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Main {
Account.main(emptyArray())
IndexSolutionForRIDHashes.main()
Timeouts.main()
CollectingCollections.main()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.jesperancinha.ktd
import kotlin.test.Test

class AtmMachineTest {
val oldAtmMachine by lazy { OldAtmMachine() }
private val oldAtmMachine by lazy { OldAtmMachine() }

@Test
fun `should show compatibilities`() {
Expand Down

0 comments on commit 884cf51

Please sign in to comment.