I'm looking for a way to add an element in a list already sorted or move an existing element.
data class House(
val id: Int,
val sold: Boolean,
val creationDate: LocalDate,
...
)
My list is already sorted on 2 parameters (sold and creationDate).
Example of a list already sorted :
[
House(123, false, 2015-03-23, ...),
House(456, false, 2015-01-11, ...),
House(789, false, 2014-08-30, ...), // <- I'm looking for move this one
House(147, false, 2014-02-15, ...),
House(258, true, 2016-06-02, ...),
House(369, true, 2015-04-20, ...),
House(321, true, 2015-01-28, ...),
House(654, true, 2011-11-01, ...)
]
Now if an house is sold, (House with id 789) how can I move an item from the first part of the list to the other part without reordering all the list. (for a performance concern) This new position have to consider the key "creationDate".
List updated :
[
House(123, false, 2015-03-23, ...),
House(456, false, 2015-01-11, ...),
House(147, false, 2014-02-15, ...),
House(258, true, 2016-06-02, ...),
House(369, true, 2015-04-20, ...),
House(321, true, 2015-01-28, ...),
House(789, true, 2014-08-30, ...), // <- Result expected
House(654, true, 2011-11-01, ...)
]
Thank's for your help.