private SortedSet < String > mergeSets ( SortedSet < String > primary , Set < String > secondary ) { SortedSet < String > result = primary ; if ( ! secondary . isEmpty ( ) ) { result = new TreeSet <> ( ) ; result . addAll ( primary ) ; result . addAll ( secondary ) ; } return result ; }
Merge two sets . If secondary set is empty return primary .