有没有欧洲国家和语言的java Enum?

发布于 2024-09-14 12:39:34 字数 588 浏览 5 评论 0原文

是否有任何 java (>5) 枚举用于在某处列出欧洲国家和语言? 如果没有,我可能会从这个列表中写出它们: http://www .nationsonline.org/oneworld/european_languages.htm

但如果我能避免这种负担,那就太好了!

PS:最后,我开始使用 geonames.org 上的 geoNames Web 服务。对于我在 Groovy 中使用此代码片段的国家/地区:

import org.geonames.*

ToponymSearchCriteria sc = new ToponymSearchCriteria()
sc.setContinentCode("eu")
sc.setFeatureCode("PCLI")
def res = WebService.search(sc)
def countries = res.getToponyms().collect{it.countryName}.sort()

Is there any java (>5) enum for listing european countries and languages somewhere?
If there aren't any, I'll probably write them from this list : http://www.nationsonline.org/oneworld/european_languages.htm

But if I could avoid that burden, that would be great!

P.S.: Finally, I'm starting to use the geoNames webservice at geonames.org. For the countries I use this snippet in Groovy :

import org.geonames.*

ToponymSearchCriteria sc = new ToponymSearchCriteria()
sc.setContinentCode("eu")
sc.setFeatureCode("PCLI")
def res = WebService.search(sc)
def countries = res.getToponyms().collect{it.countryName}.sort()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

离旧人 2024-09-21 12:39:34

专业框架设计者不太可能在他们的库中包含这样的枚举,因为国家集(以及政治上认可的官方语言集)一直在变化。您要么必须打破向后兼容性,使枚举对于应该运行几年以上的软件来说毫无用处,要么必须在枚举中保留旧的、不再被识别的国家和语言。

It is unlikely that professional framework designers will include such an Enum in their library, because the set of countries (and the set of politically-recognised official languages) changes all the time. You’d either have to break backwards-compatibility, making the Enum rather useless for software that is supposed to work for longer than a few years, or you’d have to keep old, no-longer-recognised countries and languages in the Enum.

深府石板幽径 2024-09-21 12:39:34

使用enum来存储一些比较稳定的数据并没有什么错。您还能做什么,将其存储在 XML 中?怎么样,好一点了吗?所以你不必重新编译(这是一个很大的麻烦)?我们生活在哪一年?

或者存入数据库;当一个新国家诞生时,我们只需要在数据库中插入一行,巧妙编写的应用程序就会加载它并立即使用它 - 无需重新启动应用程序!欢呼。

即使对于欧洲来说,这也太过分了。我确信他们更改国家/地区的频率不会比我们重新部署应用程序的频率高,在任何现代公司中,重新部署应用程序每周至少发生一次。

没有什么是永远的,伙计。我们可以枚举太阳系中的行星吗?根据 Joshua Bloch 的说法,是的 - 他在他的书中将其吹捧为 Java 的最佳建议。据你们说,不。

好吧,至少我们只能发现新的行星,而不能摧毁旧的行星(在任何可预见的未来),所以就兼容性而言,行星枚举是可以的,对吗?

把这件事告诉普鲁托。

There is nothing wrong to use enum to store some rather stable data. What else can you do, store it in XML? How's that any better? So you don't have to recompile(which is a huuuge hassle)? What year are we living in?

Or store it in database; when a new country is born, we just need to insert a row in the database, and the application, smartly written, will load it and use it immediately - without restarting the applicaiton! Hurray.

Even for Europe, that is such an overkill. I'm sure they don't change countries more frequently than we redeploy our applications, which, in any modern company, happens at least once a week.

Nothing is forever, dude. Can we have an enum of planets in this solar system? According to Joshua Bloch, yes - he has it in his book touted as best advices for Java. According to you guys, noooooo.

Well, at least we could only discover new planets, and we can't destroy old planets (in any foreseeable future), so a planet enum is ok as far as compatability, right?

Tell that to Pluto.

始终不够 2024-09-21 12:39:34

也许 Locale.getISOCountries()Locale.getISOLanguages() 会对您有所帮助。

Maybe Locale.getISOCountries() and Locale.getISOLanguages() will help you.

流绪微梦 2024-09-21 12:39:34

至少我会从该 URL 自动生成枚举类。您可以解析 HTML、获取值并编写定义枚举的 java 文件。

每当此 URL 的内容发生更改时,您都可以重新运行自动生成器并创建一个新的枚举类。

但请注意 - 枚举中的每个更改都有可能在代码的其余部分中引入错误。

At least I'd autogenerate the enum class from that URL. You can parse the HTML, fetch the values and write a java file that defines the enum.

And whenever the content at this URL changes, you can rerun the autogenerator and create a new enum class.

But be aware - every change in the enum has a potential to introduce errors in the rest of the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文