本文整理汇总了Java中java.util.ResourceBundle.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceBundle.containsKey方法的具体用法?Java ResourceBundle.containsKey怎么用?Java ResourceBundle.containsKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.ResourceBundle
的用法示例。
在下文中一共展示了ResourceBundle.containsKey方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: compareResources
import java.util.ResourceBundle; //导入方法依赖的package包/类
private static void compareResources(ResourceBundle compat, ResourceBundle cldr) {
Set<String> supplementalKeys = getSupplementalKeys(compat);
for (String key : supplementalKeys) {
Object compatData = compat.getObject(key);
String cldrKey = toCldrKey(key);
Object cldrData = cldr.containsKey(cldrKey) ? cldr.getObject(cldrKey) : null;
if (!Objects.deepEquals(compatData, cldrData)) {
// OK if key is for the Buddhist or Japanese calendars which had been
// supported before java.time, or if key is "java.time.short.Eras" due
// to legacy era names.
if (!(key.contains("buddhist") || key.contains("japanese")
|| key.equals("java.time.short.Eras"))) {
errors++;
System.out.print("Failure: ");
}
System.out.println("diff: " + compat.getLocale().toLanguageTag() + "\n"
+ " COMPAT: " + key + " -> " + toString(compatData) + "\n"
+ " CLDR: " + cldrKey + " -> " + toString(cldrData));
}
}
}
示例2: getJavaTimeNames
import java.util.ResourceBundle; //导入方法依赖的package包/类
String[] getJavaTimeNames(String key) {
String[] names = null;
String cacheKey = CALENDAR_NAMES + key;
removeEmptyReferences();
ResourceReference data = cache.get(cacheKey);
if (data == null || ((names = (String[]) data.get()) == null)) {
ResourceBundle rb = getJavaTimeFormatData();
if (rb.containsKey(key)) {
names = rb.getStringArray(key);
cache.put(cacheKey,
new ResourceReference(cacheKey, (Object) names, referenceQueue));
}
}
return names;
}
示例3: getCalendarData
import java.util.ResourceBundle; //导入方法依赖的package包/类
int getCalendarData(String key) {
Integer caldata;
String cacheKey = CALENDAR_DATA + key;
removeEmptyReferences();
ResourceReference data = cache.get(cacheKey);
if (data == null || ((caldata = (Integer) data.get()) == null)) {
ResourceBundle rb = localeData.getCalendarData(locale);
if (rb.containsKey(key)) {
caldata = Integer.parseInt(rb.getString(key));
} else {
caldata = 0;
}
cache.put(cacheKey,
new ResourceReference(cacheKey, (Object) caldata, referenceQueue));
}
return caldata;
}
示例4: getCollationData
import java.util.ResourceBundle; //导入方法依赖的package包/类
public String getCollationData() {
String key = "Rule";
String coldata = "";
removeEmptyReferences();
ResourceReference data = cache.get(COLLATION_DATA_CACHEKEY);
if (data == null || ((coldata = (String) data.get()) == null)) {
ResourceBundle rb = localeData.getCollationData(locale);
if (rb.containsKey(key)) {
coldata = rb.getString(key);
}
cache.put(COLLATION_DATA_CACHEKEY,
new ResourceReference(COLLATION_DATA_CACHEKEY, (Object) coldata, referenceQueue));
}
return coldata;
}
示例5: getCalendarNames
import java.util.ResourceBundle; //导入方法依赖的package包/类
String[] getCalendarNames(String key) {
String[] names = null;
String cacheKey = CALENDAR_NAMES + key;
removeEmptyReferences();
ResourceReference data = cache.get(cacheKey);
if (data == null || ((names = (String[]) data.get()) == null)) {
ResourceBundle rb = localeData.getDateFormatData(locale);
if (rb.containsKey(key)) {
names = rb.getStringArray(key);
cache.put(cacheKey,
new ResourceReference(cacheKey, (Object) names, referenceQueue));
}
}
return names;
}
示例6: getMessageOrNull
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* Returns a message if found or <code>null</code> if not.
*
* Arguments <b>can</b> be specified which will be used to format the String. In the
* {@link ResourceBundle} the String '{0}' (without ') will be replaced by the first argument,
* '{1}' with the second and so on.
*
*/
public static String getMessageOrNull(ResourceBundle bundle, String key, Object... arguments) {
if (bundle.containsKey(key)) {
return getMessage(bundle, key, arguments);
} else {
return null;
}
}
示例7: bundleContainsKey
import java.util.ResourceBundle; //导入方法依赖的package包/类
public static boolean bundleContainsKey(String l10nKey, ResourceBundle bundle) {
if (l10nKey == null || l10nKey.trim().length() == 0) {
return false;
}
if (bundle == null) {
return false;
}
return bundle.containsKey(l10nKey);
}
示例8: getTranslation
import java.util.ResourceBundle; //导入方法依赖的package包/类
public static String getTranslation(String key, TranslationType type, Object... variables) {
ResourceBundle bundle = getTranslationBundle();
if(type!=TranslationType.TEXT&&type!=TranslationType.EXTERNAL)
key = new StringBuilder(key).append('.').append(type.toString().toLowerCase()).toString();
if(!bundle.containsKey(key))
bundle = ResourceBundle.getBundle("lc/kra/jds/TranslationBundle");
if(!bundle.containsKey(key))
switch(type) {
case TEXT: case TITLE: return new StringBuilder("text missing ("+key+")").toString();
case ALTERNATIVE: return getTranslation(key);
case EXTERNAL: return key;
default: return null; }
else return MessageFormat.format(bundle.getString(key), variables);
}
示例9: getResource
import java.util.ResourceBundle; //导入方法依赖的package包/类
private static String getResource(String key, Locale locale, String baseName) {
ResourceBundle resourceBundle = ResourceBundle.getBundle(baseName, locale, new XMLResourceBundleControl());
if (!resourceBundle.containsKey(key)) {
System.err.printf("Can't find key %s in locale %s%n", key, locale.toLanguageTag());
}
return resourceBundle.getString(key);
}
示例10: getDisplayName
import java.util.ResourceBundle; //导入方法依赖的package包/类
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
return rb.containsKey("field.week") ? rb.getString("field.week") : toString();
}
示例11: getDisplayName
import java.util.ResourceBundle; //导入方法依赖的package包/类
@Override
public String getDisplayName(Locale locale) {
Objects.requireNonNull(locale, "locale");
if (rangeUnit == YEARS) { // only have values for week-of-year
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
return rb.containsKey("field.week") ? rb.getString("field.week") : name;
}
return name;
}
示例12: initializeData
import java.util.ResourceBundle; //导入方法依赖的package包/类
private void initializeData(Locale desiredLocale) {
locale = desiredLocale;
// Copy values of a cached instance if any.
SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
DateFormatSymbols dfs;
if (ref != null && (dfs = ref.get()) != null) {
copyMembers(dfs, this);
return;
}
// Initialize the fields from the ResourceBundle for locale.
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
// Avoid any potential recursions
if (!(adapter instanceof ResourceBundleBasedAdapter)) {
adapter = LocaleProviderAdapter.getResourceBundleBased();
}
ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);
// JRE and CLDR use different keys
// JRE: Eras, short.Eras and narrow.Eras
// CLDR: long.Eras, Eras and narrow.Eras
if (resource.containsKey("Eras")) {
eras = resource.getStringArray("Eras");
} else if (resource.containsKey("long.Eras")) {
eras = resource.getStringArray("long.Eras");
} else if (resource.containsKey("short.Eras")) {
eras = resource.getStringArray("short.Eras");
}
months = resource.getStringArray("MonthNames");
shortMonths = resource.getStringArray("MonthAbbreviations");
ampms = resource.getStringArray("AmPmMarkers");
localPatternChars = resource.getString("DateTimePatternChars");
// Day of week names are stored in a 1-based array.
weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
// Put a clone in the cache
ref = new SoftReference<>((DateFormatSymbols)this.clone());
SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
if (x != null) {
DateFormatSymbols y = x.get();
if (y == null) {
// Replace the empty SoftReference with ref.
cachedInstances.put(locale, ref);
}
}
}
示例13: getDecimalFormatSymbolsData
import java.util.ResourceBundle; //导入方法依赖的package包/类
public Object[] getDecimalFormatSymbolsData() {
Object[] dfsdata;
removeEmptyReferences();
ResourceReference data = cache.get(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY);
if (data == null || ((dfsdata = (Object[]) data.get()) == null)) {
// Note that only dfsdata[0] is prepared here in this method. Other
// elements are provided by the caller, yet they are cached here.
ResourceBundle rb = localeData.getNumberFormatData(locale);
dfsdata = new Object[3];
// NumberElements look up. First, try the Unicode extension
String numElemKey;
String numberType = locale.getUnicodeLocaleType("nu");
if (numberType != null) {
numElemKey = numberType + ".NumberElements";
if (rb.containsKey(numElemKey)) {
dfsdata[0] = rb.getStringArray(numElemKey);
}
}
// Next, try DefaultNumberingSystem value
if (dfsdata[0] == null && rb.containsKey("DefaultNumberingSystem")) {
numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements";
if (rb.containsKey(numElemKey)) {
dfsdata[0] = rb.getStringArray(numElemKey);
}
}
// Last resort. No need to check the availability.
// Just let it throw MissingResourceException when needed.
if (dfsdata[0] == null) {
dfsdata[0] = rb.getStringArray("NumberElements");
}
cache.put(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY,
new ResourceReference(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, (Object) dfsdata, referenceQueue));
}
return dfsdata;
}
示例14: getLocalizedResource
import java.util.ResourceBundle; //导入方法依赖的package包/类
/**
* Returns the localized resource of the given key and locale, or null
* if no localized resource is available.
*
* @param key the key of the localized resource, not null
* @param locale the locale, not null
* @return the localized resource, or null if not available
* @throws NullPointerException if key or locale is null
*/
@SuppressWarnings("unchecked")
static <T> T getLocalizedResource(String key, Locale locale) {
LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
.getLocaleResources(locale);
ResourceBundle rb = lr.getJavaTimeFormatData();
return rb.containsKey(key) ? (T) rb.getObject(key) : null;
}