Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class SortTest {
  2.  
  3. @Test
  4. fun `sorting`() {
  5. DUMMY.sortedWith(
  6. compareByDescending<SortItem> { it.bool }
  7. .thenBy { it.num }
  8. .thenBy { it.date }
  9. .thenBy { it.name }
  10. ).print()
  11. }
  12.  
  13. private fun <T> List<T>.print() {
  14. println(this.joinToString("\n"))
  15. }
  16.  
  17. companion object {
  18. private val DUMMY = arrayListOf(
  19. SortItem(true, 5, Instant.now().plusSeconds(60), "A"),
  20. SortItem(false, 5, Instant.now().plusSeconds(120), "B"),
  21. SortItem(true, 10, Instant.now().plusSeconds(180), "C"),
  22. SortItem(true, 20, Instant.now().plusSeconds(180), "D"),
  23. SortItem(false, 5, Instant.now().plusSeconds(60), "E")
  24. )
  25. }
  26. }
  27.  
  28. data class SortItem(
  29. val bool: Boolean,
  30. val num: Int,
  31. val date: Instant,
  32. val name: String
  33. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement