2011-03-22 80 views
3

我想获取所有具有不同语言的区域设置的列表,其中ISO3代码用于标识语言环境的语言。我认为以下应工作删除集合中的重复项

class ISO3LangComparator implements Comparator<Locale> { 

    int compare(Locale locale1, Locale locale2) { 
     locale1.ISO3Language <=> locale2.ISO3Language 
    } 
} 

def allLocales = Locale.getAvailableLocales().toList() 
def uniqueLocales = allLocales.unique {new ISO3LangComparator()} 

// Test how many locales there are with iso3 code 'ara' 
def arabicLocaleCount = uniqueLocales.findAll {it.ISO3Language == 'ara'}.size() 

// This assertion fails 
assert arabicLocaleCount <= 1 

回答

4

亚当说了什么。
或...

allLocales.unique{it.ISO3Language} 

,你忘了比较