⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 defaultcountryservice.java

📁 spring+sybase数据库处理连接的范例
💻 JAVA
字号:
package org.springframework.samples.countries;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.springframework.beans.factory.InitializingBean;

/**
 * @author Jean-Pierre Pawlak
 * @author Juergen Hoeller
 */
public class DefaultCountryService implements CountryService, InitializingBean {

	private final Map countriesLists = new HashMap();

	private final Map countriesMaps = new HashMap();

	public void afterPropertiesSet() {
		String countries[] = Locale.getISOCountries();
		String langs[] = { "fr", "en", "de" };
		for (int langId = 0; langId < langs.length; langId++) {
			String lang = langs[langId];
			Locale crtLoc = new Locale(lang, "");
			List list = new ArrayList();
			Map map = new HashMap();
			Country country = null;
			for (int j = 0; j < countries.length; j++) {
				String countryCode = countries[j];
				Locale countryLoc = new Locale("en", countryCode);
				String name = countryLoc.getDisplayCountry(crtLoc);
				if (!name.equals(countryCode)) {
					country = new Country(countryCode, name);
					list.add(country);
					map.put(countryCode, country);
				}
			}
			this.countriesLists.put(lang, list);
			this.countriesMaps.put(lang, map);
		}
	}

	public List getAllCountries(Locale locale) {
		List countries = (List) this.countriesLists.get(getLanguage(locale));
		if (countries == null) {
			countries = (List) this.countriesLists.get(Locale.getDefault().getLanguage());
		}
		return countries;
	}

	public List getFilteredCountries(String name, String code, Locale locale) {
		List allCountries = getAllCountries(locale);
		List countries = new ArrayList();
		Iterator it = allCountries.iterator();
		while (it.hasNext()) {
			Country country = (Country) it.next();
			if ((name == null || country.getName().startsWith(name))
					&& (code == null || country.getCode().startsWith(code))) {
				countries.add(country);
			}
		}
		return countries;
	}

	public Country getCountry(String code, Locale locale) {
		return (Country) ((Map) this.countriesMaps.get(getLanguage(locale))).get(code);
	}

	private String getLanguage(Locale locale) {
		if (locale != null) {
			return locale.getLanguage();
		}
		return Locale.getDefault().getLanguage();
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -