Следующая функция принимает ключи и события для сортировки. Максимальный размер ключей - 4, пока что.
def sortNow(keys: List[(String, String), events:List[java.util.HashMap[String, Any]]): Any = {
keys.length match {
case 1 => events.sortBy(event => {
val values = getValues(keys, event)
values match {
case List(a: String) => a.asInstanceOf[String]
}
})
case 2 => events.sortBy(event => {
val values = getValues(keys, event)
values match {
case List(a, b) => (a.asInstanceOf[String], b.asInstanceOf[String])
}
})
case 3 => events.sortBy(event => {
val values = getValues(keys, event)
values match {
case List(a, b, c) => (a.asInstanceOf[String], b.asInstanceOf[String], c.asInstanceOf[String])
}
})(Ordering[(String, String, String)].reverse)
case 4 => events.sortBy(event => {
val values = getValues(keys, event)
values match {
case List(a, b, c, d) => (a.asInstanceOf[String], b.asInstanceOf[String], c.asInstanceOf[String], d.asInstanceOf[String])
}
})
case default => throw new NotImplementedException
}
}