public static < N extends TreeNode < N > > boolean equalsWithoutOrder ( N tree1 , N tree2 ) { if ( ! tree1 . getName ( ) . equals ( tree2 . getName ( ) ) ) { return false ; } List < N > children1 = tree1 . getChildren ( ) ; List < N > children2 = tree2 . getChildren ( ) ; if ( children1 . size ( ) != children2 . size ( ) ) { return false ; } for ( N child1 : children1 ) { for ( N child2 : children2 ) { if ( child1 . equals ( child2 ) ) { boolean equals = equalsWithoutOrder ( child1 , child2 ) ; if ( ! equals ) { return false ; } } } } return true ; }
This method checks to trees for equality . Equality is only checked on name basis and the order of the children is neglected .