Replaces all parameters with the given attribute with a single parameter with the given value. If multiple parameters with the same attributes are necessary use #withParameters. Prefer #withCharset for setting the charset parameter when using a Charset object
(String attribute, String value)
| 756 | |
| 757 | |
| 758 | public MediaType withParameter(String attribute, String value) { |
| 759 | checkNotNull(attribute); |
| 760 | checkNotNull(value); |
| 761 | String normalizedAttribute = normalizeToken(attribute); |
| 762 | ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder(); |
| 763 | for (Entry<String, String> entry : parameters.entries()) { |
| 764 | String key = entry.getKey(); |
| 765 | if (!normalizedAttribute.equals(key)) { |
| 766 | builder.put(key, entry.getValue()); |
| 767 | } |
| 768 | } |
| 769 | builder.put(normalizedAttribute, normalizeParameterValue(normalizedAttribute, value)); |
| 770 | MediaType mediaType = new MediaType(type, subtype, builder.build()); |
| 771 | // Return one of the constants if the media type is a known type. |
| 772 | return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType); |
| 773 | } |
| 774 | |
| 775 | /** |
| 776 | * Returns a new instance with the same type and subtype as this instance, with the |
no test coverage detected