/** 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)); }
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); } }
@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); }
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; } }
@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; }
@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)); }
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(); } }
@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); }
@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"); }
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; } }
/** * 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; }
@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(); }
/** * 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(); } }
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; }
@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); } }
@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); }
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;
/** * {@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); }