Sorts elements by group and subgroup using Comparable