PathMatchInfo(Map<String, String> uriVars, @Nullable Map<String, MultiValueMap<String, String>> matrixVars) { this.uriVariables = Collections.unmodifiableMap(uriVars); this.matrixVariables = matrixVars != null ? Collections.unmodifiableMap(matrixVars) : Collections.emptyMap(); }
public class Test { private static final Map<Integer, String> myMap; static { Map<Integer, String> aMap = ....; aMap.put(1, "one"); aMap.put(2, "two"); myMap = Collections.unmodifiableMap(aMap); } }
public Set<Map.Entry<String, Object>> entrySet() { return Collections.unmodifiableMap(this.headers).entrySet(); }
Map<String, String> realMap = new HashMap<String, String>(); realMap.put("A", "B"); Map<String, String> unmodifiableMap = Collections.unmodifiableMap(realMap); // This is not possible: It would throw an // UnsupportedOperationException //unmodifiableMap.put("C", "D"); // This is still possible: realMap.put("E", "F"); // The change in the "realMap" is now also visible // in the "unmodifiableMap". So the unmodifiableMap // has changed after it has been created. unmodifiableMap.get("E"); // Will return "F".
public Challenge(String scheme, Map<String, String> authParams) { if (scheme == null) throw new NullPointerException("scheme == null"); if (authParams == null) throw new NullPointerException("authParams == null"); this.scheme = scheme; Map<String, String> newAuthParams = new LinkedHashMap<>(); for (Entry<String, String> authParam : authParams.entrySet()) { String key = (authParam.getKey() == null) ? null : authParam.getKey().toLowerCase(US); newAuthParams.put(key, authParam.getValue()); } this.authParams = unmodifiableMap(newAuthParams); }
@Override public JsonWriterFactory createWriterFactory(Map<String, ?> config) { Map<String, Object> providerConfig; boolean prettyPrinting; BufferPool pool; if (config == null) { providerConfig = Collections.emptyMap(); prettyPrinting = false; pool = bufferPool; } else { providerConfig = new HashMap<>(); if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) { providerConfig.put(JsonGenerator.PRETTY_PRINTING, true); } pool = (BufferPool)config.get(BufferPool.class.getName()); if (pool != null) { providerConfig.put(BufferPool.class.getName(), pool); } else { pool = bufferPool; } providerConfig = Collections.unmodifiableMap(providerConfig); } return new JsonWriterFactoryImpl(providerConfig, prettyPrinting, pool); }
@Override public Map getParameterMap() { if (parameterMap == null) { Map<String, String[]> map = new LinkedHashMap<>(); for (String formParam : formParams.keySet()) { map.put(formParam, formParams.get(formParam).toArray(new String[0])); } map.putAll(super.getParameterMap()); parameterMap = Collections.unmodifiableMap(map); } return parameterMap; }
public static Map<String, Map<String, Object>> parseYaml(String sampleYaml) { YamlMapFactoryBean factory = new YamlMapFactoryBean(); factory.setResolutionMethod(YamlProcessor.ResolutionMethod.OVERRIDE_AND_IGNORE); List<Resource> resources = new ArrayList<>(); ByteArrayResource resource = new ByteArrayResource(sampleYaml.getBytes()); resources.add(resource); factory.setResources(resources.toArray(new Resource[resources.size()])); Map<String, Object> tmpdata = factory.getObject(); Map<String, Map<String, Object>> dataMap = new HashMap<>(); for (Map.Entry<String, Object> entry : ((Map<String, Object>)tmpdata.get("providers")).entrySet()) { dataMap.put(entry.getKey(), (Map<String, Object>)entry.getValue()); } return Collections.unmodifiableMap(dataMap); }
@Override public Map<String, Long> updateValues(Map<MetricsFilter, Set<Metric>> map) { Map<String, Long> updated = new HashMap<>(); for (Metric metric : map.get(mFilter)) { Map<String, String> tags = metric.getTags(); if (tags.containsKey(mTagName)) { String ufsName = MetricsSystem.getClusterMetricName( Metric.getMetricNameWithTags(mAggregationName, mTagName, tags.get(mTagName))); long value = updated.getOrDefault(ufsName, 0L); updated.put(ufsName, (long) (value + metric.getValue())); } } synchronized (this) { mAggregates = updated; } return Collections.unmodifiableMap(mAggregates); }
public Map<InjectionTarget, ResourceInjectionConfiguration> getResourceInjections(final String className) { Map<InjectionTarget, ResourceInjectionConfiguration> injections = resourceInjections.get(className); if (injections == null) { return Collections.emptyMap(); } else { return Collections.unmodifiableMap(injections); } }
/** * @param statType Type of statistics which need to take. * @return All tracked statistics for given type. */ public Map<IoStatisticsHolderKey, IoStatisticsHolder> statistics(IoStatisticsType statType){ return Collections.unmodifiableMap(statByType.get(statType)); } }
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); } }
/** * 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(); } }
/** Returns a map of metadata name, value pairs to be set. Values are copied. */ public Map<String, Object> getEditedValues() { HashMap<String, Object> hashMap = new HashMap<>(editedValues); for (Entry<String, Object> entry : hashMap.entrySet()) { Object value = entry.getValue(); if (value instanceof byte[]) { byte[] bytes = (byte[]) value; entry.setValue(Arrays.copyOf(bytes, bytes.length)); } } return Collections.unmodifiableMap(hashMap); }
/** * Build a mapping of {@link TypeVariable#getName TypeVariable names} to * {@link Class concrete classes} for the specified {@link Class}. * Searches all super types, enclosing types and interfaces. * @see #resolveType(Type, Map) */ @SuppressWarnings("rawtypes") public static Map<TypeVariable, Type> getTypeVariableMap(Class<?> clazz) { Map<TypeVariable, Type> typeVariableMap = typeVariableCache.get(clazz); if (typeVariableMap == null) { typeVariableMap = new HashMap<>(); buildTypeVariableMap(ResolvableType.forClass(clazz), typeVariableMap); typeVariableCache.put(clazz, Collections.unmodifiableMap(typeVariableMap)); } return typeVariableMap; }
private Map<String, Exclusion> unmodifiableRefMap(Map<String, ParamsBuilder> fieldBuilderMap) { Map<String, Exclusion> fieldMap = new LinkedHashMap<>(); for (Map.Entry<String, ParamsBuilder> fieldEntry : fieldBuilderMap.entrySet()) { fieldMap.put(fieldEntry.getKey(), new Exclusion(fieldEntry.getValue())); } return unmodifiableMap(fieldMap); }
private static Map<ByteString, Integer> nameToFirstIndex() { Map<ByteString, Integer> result = new LinkedHashMap<>(STATIC_HEADER_TABLE.length); for (int i = 0; i < STATIC_HEADER_TABLE.length; i++) { if (!result.containsKey(STATIC_HEADER_TABLE[i].name)) { result.put(STATIC_HEADER_TABLE[i].name, i); } } return Collections.unmodifiableMap(result); }
@Override public JsonGeneratorFactory createGeneratorFactory(Map<String, ?> config) { Map<String, Object> providerConfig; boolean prettyPrinting; BufferPool pool; if (config == null) { providerConfig = Collections.emptyMap(); prettyPrinting = false; pool = bufferPool; } else { providerConfig = new HashMap<>(); if (prettyPrinting=JsonProviderImpl.isPrettyPrintingEnabled(config)) { providerConfig.put(JsonGenerator.PRETTY_PRINTING, true); } pool = (BufferPool)config.get(BufferPool.class.getName()); if (pool != null) { providerConfig.put(BufferPool.class.getName(), pool); } else { pool = bufferPool; } providerConfig = Collections.unmodifiableMap(providerConfig); } return new JsonGeneratorFactoryImpl(providerConfig, prettyPrinting, pool); }
static Map<String,String> resolveMessagesForOrigin(final Class<?> origin, final Locale locale) { final Map<String,String> combinedMessages = new HashMap<String, String>(20); Class<?> currentClass = origin; combinedMessages.putAll(resolveMessagesForSpecificClass(currentClass, locale)); while (!currentClass.getSuperclass().equals(Object.class)) { currentClass = currentClass.getSuperclass(); final Map<String,String> messagesForCurrentClass = resolveMessagesForSpecificClass(currentClass, locale); for (final String messageKey : messagesForCurrentClass.keySet()) { if (!combinedMessages.containsKey(messageKey)) { combinedMessages.put(messageKey, messagesForCurrentClass.get(messageKey)); } } } return Collections.unmodifiableMap(combinedMessages); }
@Override public Map<String, String> getProperties(Class<? extends Protocol> protocolClass) { Map<String, String> properties = this.map.get(protocolClass); return (properties != null) ? Collections.unmodifiableMap(properties) : Collections.<String, String>emptyMap(); } }