java.util.Collections.emptyMap()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(237)

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

Collections.emptyMap介绍

[英]Returns a type-safe empty, immutable Map.
[中]返回类型安全的空、不可变映射。

代码示例

代码示例来源:origin: square/okhttp

/** Returns an immutable copy of {@code map}. */
public static <K, V> Map<K, V> immutableMap(Map<K, V> map) {
 return map.isEmpty()
   ? Collections.emptyMap()
   : Collections.unmodifiableMap(new LinkedHashMap<>(map));
}

代码示例来源:origin: skylot/jadx

public static Map<String, String> newConstStringMap(String... parameters) {
    int len = parameters.length;
    if (len == 0) {
      return Collections.emptyMap();
    }
    Map<String, String> result = new HashMap<>(len / 2);
    for (int i = 0; i < len; i += 2) {
      result.put(parameters[i], parameters[i + 1]);
    }
    return Collections.unmodifiableMap(result);
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Override
@SuppressWarnings("unchecked")
protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) {
  String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE;
  return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name);
}

代码示例来源:origin: Graylog2/graylog2-server

private Map<String, String> prefixElements(final String prefix, final Map<String, String> elements) {
    if (elements == null || elements.isEmpty()) {
      return Collections.emptyMap();
    }

    final Map<String, String> prefixedMap = new HashMap<>(elements.size());
    for (Map.Entry<String, String> entry : elements.entrySet()) {
      prefixedMap.put(prefix.trim() + "_" + entry.getKey(), entry.getValue());
    }

    return prefixedMap;
  }
}

代码示例来源:origin: mpusher/mpush

@Override
public <T> Map<String, T> hgetAll(String key, Class<T> clazz) {
  Map<String, Object> m = (Map) cache.get(key);
  if (m == null || m.isEmpty()) return Collections.emptyMap();
  Map<String, T> result = new HashMap<>();
  for (Map.Entry<String, Object> o : m.entrySet()) {
    result.put(o.getKey(), Jsons.fromJson(String.valueOf(o.getValue()), clazz));
  }
  return result;
}

代码示例来源:origin: apache/kafka

@Test
public void testSaslLoginRefreshDefaults() {
  Map<String, Object> vals = new ConfigDef().withClientSaslSupport().parse(Collections.emptyMap());
  assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_WINDOW_FACTOR,
      vals.get(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_FACTOR));
  assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_WINDOW_JITTER,
      vals.get(SaslConfigs.SASL_LOGIN_REFRESH_WINDOW_JITTER));
  assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_MIN_PERIOD_SECONDS,
      vals.get(SaslConfigs.SASL_LOGIN_REFRESH_MIN_PERIOD_SECONDS));
  assertEquals(SaslConfigs.DEFAULT_LOGIN_REFRESH_BUFFER_SECONDS,
      vals.get(SaslConfigs.SASL_LOGIN_REFRESH_BUFFER_SECONDS));
}

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

public Map<String, Object> getTransientVariablesLocal() {
 if (transientVariabes != null) {
  Map<String, Object> variables = new HashMap<String, Object>();
  for (String variableName : transientVariabes.keySet()) {
   variables.put(variableName, transientVariabes.get(variableName).getValue());
  }
  return variables;
 } else {
  return Collections.emptyMap();
 }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
@SuppressWarnings("unchecked")
public void resolveArgumentNoUriVars() throws Exception {
  Map<String, String> map = (Map<String, String>) resolver.resolveArgument(paramMap, mavContainer, webRequest, null);
  assertEquals(Collections.emptyMap(), map);
}

代码示例来源:origin: spring-projects/spring-security

@Test
public void convertWhenIssuerIsOfTypeURLThenConvertsToString() throws Exception {
  MappedJwtClaimSetConverter converter = MappedJwtClaimSetConverter
      .withDefaults(Collections.emptyMap());
  Map<String, Object> issuer = Collections.singletonMap(JwtClaimNames.ISS, new URL("https://issuer"));
  Map<String, Object> target = converter.convert(issuer);
  assertThat(target.get(JwtClaimNames.ISS)).isEqualTo("https://issuer");
}

代码示例来源:origin: Netflix/eureka

private static Map<String, String> headersOf(Response response) {
    MultivaluedMap<String, String> jerseyHeaders = response.getStringHeaders();
    if (jerseyHeaders == null || jerseyHeaders.isEmpty()) {
      return Collections.emptyMap();
    }
    Map<String, String> headers = new HashMap<>();
    for (Entry<String, List<String>> entry : jerseyHeaders.entrySet()) {
      if (!entry.getValue().isEmpty()) {
        headers.put(entry.getKey(), entry.getValue().get(0));
      }
    }
    return headers;
  }
}

代码示例来源:origin: SonarSource/sonarqube

@Override
public ActiveRule find(RuleKey ruleKey) {
 return activeRulesByRepositoryAndKey.getOrDefault(ruleKey.repository(), Collections.emptyMap())
  .get(ruleKey.rule());
}

代码示例来源:origin: apache/storm

/**
 * Get a map of version to worker log writer from the conf Config.SUPERVISOR_WORKER_VERSION_LOGWRITER_MAP
 *
 * @param conf what to read it out of
 * @return the map
 */
public static NavigableMap<SimpleVersion, String> getConfiguredWorkerLogWriterVersions(Map<String, Object> conf) {
  TreeMap<SimpleVersion, String> ret = new TreeMap<>();
  Map<String, String> fromConf =
    (Map<String, String>) conf.getOrDefault(Config.SUPERVISOR_WORKER_VERSION_LOGWRITER_MAP, Collections.emptyMap());
  for (Map.Entry<String, String> entry : fromConf.entrySet()) {
    ret.put(new SimpleVersion(entry.getKey()), entry.getValue());
  }
  ret.put(VersionInfo.OUR_VERSION, "org.apache.storm.LogWriter");
  return ret;
}

代码示例来源:origin: spring-projects/spring-framework

@Test(expected = InvalidDataAccessApiUsageException.class)
public void buildValueArrayWithMissingParameterValue() {
  String sql = "select count(0) from foo where id = :id";
  NamedParameterUtils.buildValueArray(sql, Collections.<String, Object>emptyMap());
}

代码示例来源:origin: square/okhttp

@Override public List<Cookie> loadForRequest(HttpUrl url) {
 // The RI passes all headers. We don't have 'em, so we don't pass 'em!
 Map<String, List<String>> headers = Collections.emptyMap();
 Map<String, List<String>> cookieHeaders;
 try {
  cookieHeaders = cookieHandler.get(url.uri(), headers);
 } catch (IOException e) {
  Platform.get().log(WARN, "Loading cookies failed for " + url.resolve("/..."), e);
  return Collections.emptyList();
 }
 List<Cookie> cookies = null;
 for (Map.Entry<String, List<String>> entry : cookieHeaders.entrySet()) {
  String key = entry.getKey();
  if (("Cookie".equalsIgnoreCase(key) || "Cookie2".equalsIgnoreCase(key))
    && !entry.getValue().isEmpty()) {
   for (String header : entry.getValue()) {
    if (cookies == null) cookies = new ArrayList<>();
    cookies.addAll(decodeHeaderAsJavaNetCookies(url, header));
   }
  }
 }
 return cookies != null
   ? Collections.unmodifiableList(cookies)
   : Collections.emptyList();
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Create a WebSocketExtension with the given name and parameters.
 * @param name the name of the extension
 * @param parameters the parameters
 */
public WebSocketExtension(String name, @Nullable Map<String, String> parameters) {
  Assert.hasLength(name, "Extension name must not be empty");
  this.name = name;
  if (!CollectionUtils.isEmpty(parameters)) {
    Map<String, String> map = new LinkedCaseInsensitiveMap<>(parameters.size(), Locale.ENGLISH);
    map.putAll(parameters);
    this.parameters = Collections.unmodifiableMap(map);
  }
  else {
    this.parameters = Collections.emptyMap();
  }
}

代码示例来源:origin: skylot/jadx

public Map<CodePosition, JavaNode> getUsageMap() {
  Map<CodePosition, Object> map = getCodeAnnotations();
  if (map.isEmpty() || decompiler == null) {
    return Collections.emptyMap();
  }
  Map<CodePosition, JavaNode> resultMap = new HashMap<>(map.size());
  for (Map.Entry<CodePosition, Object> entry : map.entrySet()) {
    CodePosition codePosition = entry.getKey();
    Object obj = entry.getValue();
    if (obj instanceof LineAttrNode) {
      JavaNode node = convertNode(obj);
      if (node != null) {
        resultMap.put(codePosition, node);
      }
    }
  }
  return resultMap;
}

代码示例来源:origin: prestodb/presto

@Override
  public Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodeRow(byte[] data, Map<String, String> dataMap)
  {
    if (dataMap == null) {
      return Optional.of(emptyMap());
    }

    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = new HashMap<>();
    for (Map.Entry<DecoderColumnHandle, RedisFieldDecoder<String>> entry : fieldDecoders.entrySet()) {
      DecoderColumnHandle columnHandle = entry.getKey();

      String mapping = columnHandle.getMapping();
      checkState(mapping != null, "No mapping for column handle %s!", columnHandle);

      String valueField = dataMap.get(mapping);

      RedisFieldDecoder<String> decoder = entry.getValue();
      decodedRow.put(columnHandle, decoder.decode(valueField, columnHandle));
    }
    return Optional.of(decodedRow);
  }
}

代码示例来源:origin: apache/storm

@Test
public void getNimbusAutoCredPluginTest() {
  Map<String, Object> map = new HashMap<>();
  map.put(Config.NIMBUS_AUTO_CRED_PLUGINS,
      Arrays.asList(new String[]{ "org.apache.storm.security.auth.AuthUtilsTestMock" }));
  Assert.assertTrue(ClientAuthUtils.getNimbusAutoCredPlugins(Collections.emptyMap()).isEmpty());
  Assert.assertEquals(ClientAuthUtils.getNimbusAutoCredPlugins(map).size(), 1);
}

代码示例来源:origin: spring-projects/spring-framework

return Collections.emptyMap();
Map<String, List<String>> map = attributeAliasesCache.get(annotationType);
if (map != null) {
  return map;
  List<String> aliasNames = getAttributeAliasNames(attribute);
  if (!aliasNames.isEmpty()) {
    map.put(attribute.getName(), aliasNames);
attributeAliasesCache.put(annotationType, map);
return map;

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

/**
 * {@inheritDoc}
 */
public Generic get(int index) {
  // Avoid resolution of interface bound type unless a type annotation can be possibly resolved.
  Map<String, List<AnnotationToken>> annotationTokens = !this.annotationTokens.containsKey(index) && !this.annotationTokens.containsKey(index + 1)
      ? Collections.<String, List<AnnotationToken>>emptyMap()
      : this.annotationTokens.get(index + (boundTypeTokens.get(0).isPrimaryBound(typePool) ? 0 : 1));
  return boundTypeTokens.get(index).toGenericType(typePool,
      typeVariableSource,
      EMPTY_TYPE_PATH,
      annotationTokens == null
          ? Collections.<String, List<AnnotationToken>>emptyMap()
          : annotationTokens);
}

相关文章

Collections类方法