SortedSet を返すことができるように、grails のドメイン クラスに compareTo を実装しようとしています。ソートされたセットを親の名前で並べ替え、次に「子」の名前で並べ替えます。例 (P=親、C=子):
- P-1
- C-1
- C-2
- P-2
- C-3
- C-4
私のクラスは次のようになります。
class Issue implements Comparable {
String name
Issue parent
@Override
public int compareTo(obj){
if(obj.parent!=null && this.parent!=null){
parent.name.compareTo(obj.parent.name)
}else{
//What do I compare to sort the children relative to their parents?
}
}