java.util.ResourceBundle.keySet()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(250)

本文整理了Java中java.util.ResourceBundle.keySet方法的一些代码示例,展示了ResourceBundle.keySet的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ResourceBundle.keySet方法的具体详情如下:
包路径:java.util.ResourceBundle
类名称:ResourceBundle
方法名:keySet

ResourceBundle.keySet介绍

[英]A Set of the keys contained only in this ResourceBundle.
[中]仅包含在此ResourceBundle中的一组密钥。

代码示例

代码示例来源:origin: robovm/robovm

public boolean containsKey(String key) {
  if (key == null) {
    throw new NullPointerException("key == null");
  }
  return keySet().contains(key);
}

代码示例来源:origin: pmd/pmd

/**
 * 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;
}

代码示例来源:origin: jenkinsci/jenkins

/**
   * 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;
  }
}

代码示例来源:origin: robovm/robovm

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;
}

代码示例来源:origin: cucumber/cucumber-jvm

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));
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

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();
}

代码示例来源:origin: checkstyle/checkstyle

@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);
}

代码示例来源:origin: stackoverflow.com

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();
  }
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

@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;
}

代码示例来源:origin: xianrendzw/EasyReport

/**
   * 获取指定前辍对应的所有的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;
  }
}

代码示例来源:origin: com.atlassian.jira/jira-core

@Override
  public Iterable<String> keys()
  {
    return resourceBundle.keySet();
  }
}

代码示例来源:origin: MobiVM/robovm

public boolean containsKey(String key) {
  if (key == null) {
    throw new NullPointerException("key == null");
  }
  return keySet().contains(key);
}

代码示例来源:origin: restx/restx

@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();
  }
});

代码示例来源:origin: ibinti/bugvm

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;
}

代码示例来源:origin: com.atlassian.jira/jira-tests

@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);
    }
  });
}

代码示例来源:origin: sakaiproject/sakai

/**
 ** Return ResourceBundle properties as if Map.keySet() 
 **/
public Set keySet()
{
  return getBundle().keySet();
}

代码示例来源:origin: org.semanticweb.elk/elk-util-common

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));
    }
  }
}

代码示例来源:origin: pwm-project/pwm

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;
}

代码示例来源:origin: com.bugvm/bugvm-rt

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;
}

代码示例来源:origin: org.apache.sis.core/sis-utility

/**
 * 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));
  }
}

相关文章