Yes sure, you can use mylist.sortBy[a_property_name]
.
Here is a full example :
scenario Sortlist {
fix lst = new List<Somestuff>
for (i : 0..5) {
fix sti = new Somestuff
sti.v1 = i
sti.v2 = "azerty"+ (10-i)
sti.v3 = random
lst.add(sti)
}
println("Unsorted list:")
for (st:lst) println(st)
fix lst1 = lst.sortBy[v1]
println("\nsorted on v1:")
for (st:lst1) println(st)
fix lst2 = lst.sortBy[v2]
println("\nsorted on v2:")
for (st:lst2) println(st)
fix lst3 = lst.sortBy[v3]
println("\nsorted on v3:")
for (st:lst3) println(st)
}
entity Somestuff {
property Integer v1
property String v2
property Double v3
}
And when you run this example you get this kind of result :
Unsorted list:
v1=0; v2=azerty10; v3=0.8903757959043018;
v1=1; v2=azerty9; v3=0.6252856803753362;
v1=2; v2=azerty8; v3=0.6281761652344758;
v1=3; v2=azerty7; v3=0.7289768130514311;
v1=4; v2=azerty6; v3=0.38832695419835794;
v1=5; v2=azerty5; v3=0.35840151615637394;
sorted on v1:
v1=0; v2=azerty10; v3=0.8903757959043018;
v1=1; v2=azerty9; v3=0.6252856803753362;
v1=2; v2=azerty8; v3=0.6281761652344758;
v1=3; v2=azerty7; v3=0.7289768130514311;
v1=4; v2=azerty6; v3=0.38832695419835794;
v1=5; v2=azerty5; v3=0.35840151615637394;
sorted on v2:
v1=0; v2=azerty10; v3=0.8903757959043018;
v1=5; v2=azerty5; v3=0.35840151615637394;
v1=4; v2=azerty6; v3=0.38832695419835794;
v1=3; v2=azerty7; v3=0.7289768130514311;
v1=2; v2=azerty8; v3=0.6281761652344758;
v1=1; v2=azerty9; v3=0.6252856803753362;
sorted on v3:
v1=5; v2=azerty5; v3=0.35840151615637394;
v1=4; v2=azerty6; v3=0.38832695419835794;
v1=1; v2=azerty9; v3=0.6252856803753362;
v1=2; v2=azerty8; v3=0.6281761652344758;
v1=3; v2=azerty7; v3=0.7289768130514311;
v1=0; v2=azerty10; v3=0.8903757959043018;