public boolean containsKey(String key) { if (key == null) { throw new NullPointerException("key == null"); } return keySet().contains(key); }
/** * Convert <code>resourceBundle</code> to usable {@link Properties}. * * @param resourceBundle * ResourceBundle * @return Properties */ public static Properties getResourceBundleAsProperties(ResourceBundle resourceBundle) { Properties properties = new Properties(); for (String key : resourceBundle.keySet()) { properties.put(key, resourceBundle.getObject(key)); } return properties; }
/** * Create a JSON representation of a resource bundle * * @param bundle The resource bundle. * @return The bundle JSON. */ private static JSONObject toJSONObject(@Nonnull ResourceBundle bundle) { JSONObject json = new JSONObject(); for (String key : bundle.keySet()) { json.put(key, bundle.getString(key)); } return json; } }
protected Set<String> handleKeySet() { Set<String> set = keySet(); Set<String> ret = new HashSet<String>(); for (String key : set) { if (handleGetObject(key) != null) { ret.add(key); } } return ret; }
public Env(String bundleName, Properties properties) { if (bundleName != null) { try { ResourceBundle bundle = ResourceBundle.getBundle(bundleName); for (String key : bundle.keySet()) { put(key, bundle.getString(key)); } } catch (MissingResourceException ignore) { } } if (properties != null) { for (String key : properties.stringPropertyNames()) { put(key, properties.getProperty(key)); } } Map<String, String> env = System.getenv(); for (String key : env.keySet()) { put(key, env.get(key)); } }
private <T> ImmutableSortedMap<String, T> resourceBundleToMap(Locale locale, @NonNls String baseName, Function<String, T> integerResolver) { Collator caseInsensitive = Collator.getInstance(locale); caseInsensitive.setStrength(Collator.PRIMARY); ImmutableSortedMap.Builder<String, T> nameToModeBuilder = new ImmutableSortedMap.Builder<String, T>(caseInsensitive); ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale); for (String key : bundle.keySet()) { String outKey; String outValue; if (reversedMap) { outKey = bundle.getString(key); outValue = key; } else { outKey = key; outValue = bundle.getString(key); } nameToModeBuilder.put(outKey, (T) keyResolver.apply(outValue)); } return nameToModeBuilder.build(); }
@Test public void testAllTokenTypesHasDescription() { final String tokenTypes = "com.puppycrawl.tools.checkstyle.api.tokentypes"; final ResourceBundle bundle = ResourceBundle.getBundle(tokenTypes, Locale.ROOT); final Set<String> expected = Arrays.stream(TokenUtil.getAllTokenIds()) .mapToObj(TokenUtil::getTokenName).collect(Collectors.toSet()); final Set<String> actual = bundle.keySet(); assertEquals("TokenTypes without description", expected, actual); }
package org.springframework.context.support; import java.util.Locale; import java.util.ResourceBundle; import java.util.Set; public class ExposedResourceBundleMessageSource extends ResourceBundleMessageSource { public Set<String> getKeys(String basename, Locale locale) { ResourceBundle bundle = getResourceBundle(basename, locale); return bundle.keySet(); } }
@Override protected Set<String> handleKeySet() { if (_keys == null) { Set<String> keys = new HashSet<>(); for (ResourceBundle resourceBundle : _resourceBundles) { keys.addAll(resourceBundle.keySet()); } _keys = keys; } return _keys; }
/** * 获取指定前辍对应的所有的Message集合 * * @param locale @see Locale * @param codePrefixes code前辍 * @return Map[Key, Value] */ public Map<String, String> getMessages(final Locale locale, final String... codePrefixes) { final Map<String, String> messagesMap = new HashMap<>(128); if (ArrayUtils.isEmpty(codePrefixes)) { return messagesMap; } final Set<String> basenames = this.getBasenameSet(); for (final String basename : basenames) { final ResourceBundle bundle = getResourceBundle(basename, locale); if (bundle != null) { for (final String key : bundle.keySet()) { if (StringUtils.startsWithAny(key, codePrefixes)) { messagesMap.put(key, bundle.getString(key)); } } } } return messagesMap; } }
@Override public Iterable<String> keys() { return resourceBundle.keySet(); } }
public boolean containsKey(String key) { if (key == null) { throw new NullPointerException("key == null"); } return keySet().contains(key); }
@Override public Iterable<String> load(Locale locale) throws Exception { Optional<ResourceBundle> bundle = getBundle(locale); return bundle.isPresent() ? Ordering.natural().sortedCopy(bundle.get().keySet()) : Collections.<String>emptySet(); } });
protected Set<String> handleKeySet() { Set<String> set = keySet(); Set<String> ret = new HashSet<String>(); for (String key : set) { if (handleGetObject(key) != null) { ret.add(key); } } return ret; }
@Override public Set<String> getKeysForPrefix(final String prefix) { return Sets.filter(bundle.keySet(), new Predicate<String>() { @Override public boolean apply(final String input) { return input.startsWith(prefix); } }); }
/** ** Return ResourceBundle properties as if Map.keySet() **/ public Set keySet() { return getBundle().keySet(); }
private static void copyParameters(String prefix, BaseConfiguration config, ResourceBundle bundle) { for (String key : bundle.keySet()) { if (key.startsWith(prefix)) { config.setParameter(key, bundle.getString(key)); } } }
public Set<String> getKeys( ) { if ( keys == null ) { final ResourceBundle defaultBundle = ResourceBundle.getBundle( this.getTheClass().getName(), PwmConstants.DEFAULT_LOCALE ); keys = Collections.unmodifiableSet( new HashSet<>( defaultBundle.keySet() ) ); } return keys; }
protected Set<String> handleKeySet() { Set<String> set = keySet(); Set<String> ret = new HashSet<String>(); for (String key : set) { if (handleGetObject(key) != null) { ret.add(key); } } return ret; }
/** * Copies all entries from the given "symbols to names" mapping to the given "names to units" mapping. * During this copy, keys are converted from symbols to names and values are converted from symbols to * {@code Unit} instance. We use {@code Unit} values instead of their symbols because all {@code Unit} * instances are created at {@link Units} class initialization anyway (so we do not create new instance * here), and it avoid to retain references to the {@link String} instances loaded by the resource bundle. */ private static void copy(final Locale locale, final ResourceBundle symbolToName, final Map<String,Unit<?>> nameToUnit) { for (final String symbol : symbolToName.keySet()) { nameToUnit.put(CharSequences.toASCII(symbolToName.getString(symbol).toLowerCase(locale)).toString().intern(), Units.get(symbol)); } }