Groovy web console

subscribe to the feed Subscribe
to this
site
Sort array based on Another array (via #groovywebconsole)
tweet this snippet Tweet
this
script

Sort array based on Another array

Published 10 months ago by Abhishek Raj Simon with tags sort array of objects
Actions  ➤ Edit in console Back to console Show/hide line numbers View recent scripts
def values = [["value":"INFO"],["value":"FATAL"],["value":"WARN"],["value":"ERROR"]]
def LOG_LEVEL_SORT_ORDER = ["fatal", "error", "warn","info"]
def tempArr = []
//LOG_LEVEL_SORT_ORDER = LOG_LEVEL_SORT_ORDER.reverse()
values.each {item->
    tempArr[LOG_LEVEL_SORT_ORDER.indexOf(item.value.toLowerCase())] = item
}
tempArr.removeAll(Collections.singleton(null))
values = tempArr
println values