views:

201

answers:

4

Hi there ! 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 !

Thanks in advance !

Philippe

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()
+10  A: 

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.

Timwi
I agree that this should not be in a professional framework. I was just wondering if someone, somewhere, has one of those in his own libraries, just to start with...
Philippe
you're missing the point: enums are supposed to be forever. countries change.
Jason S
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.
irreputable
I think the planets in this solar system are vastly less likely to change than the set of politically-recognised countries in Europe.
Timwi
Pluto, man, Pluto.
irreputable
I mean from now on. Up until 2006 there was no official definition of planet, [now there is](http://en.wikipedia.org/wiki/IAU_definition_of_planet).
Timwi
+1  A: 

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.

Andreas_D
+6  A: 

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

barjak
Hey ! How do they cope with the changing countries in this world ???
Philippe
+2  A: 

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.

irreputable
Thanks for the comment, I feel less alone in the world of "not so perfect design decisions that may do the job anyway" :-)
Philippe