/**
 * Copyright 2019 The CloudEvents Authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.cloudevents.v02.http;

import java.util.AbstractMap.SimpleEntry;
import java.util.stream.Collectors;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;

import io.cloudevents.v02.ContextAttributes;

import static io.cloudevents.v02.http.AttributeMapper.HEADER_PREFIX;

/**
 * 
 * @author fabiojose
 * @version 0.2
 */
public final class HeaderMapper {
	private HeaderMapper() {}

	public static Map<String, Object> map(Map<String, String> attributes, 
			Map<String, String> extensions) {
		Objects.requireNonNull(attributes);
		Objects.requireNonNull(extensions);
		
		Map<String, Object> result = attributes.entrySet()
			.stream()
			.map(header -> new SimpleEntry<>(header.getKey()
					.toLowerCase(Locale.US), header.getValue()))
			.filter(header -> !header.getKey()
					.equals(ContextAttributes.contenttype.name()))
			.map(header -> new SimpleEntry<>(HEADER_PREFIX+header.getKey(),
					header.getValue()))
			.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
		
		result.putAll(
			extensions.entrySet()
				.stream()
				.map(header -> new SimpleEntry<>(HEADER_PREFIX+header.getKey(),
						header.getValue()))
				.collect(Collectors.toMap(Entry::getKey, Entry::getValue))
		);
		
		result.put("Content-Type", attributes
				.get(ContextAttributes.contenttype.name()));
		
		return result;
	}
	
}

@@ -642,42 +642,70 @@
 ort 
-java.util.AbstractMap.SimpleEntry;
+static io.cloudevents.v02.http.AttributeMapper.HEADER_PREFIX;%0A
 %0Aimp
@@ -722,25 +722,31 @@
 til.
+Ab
 str
-eam.Collectors
+actMap.SimpleEntry
 ;%0Aim
@@ -848,62 +848,131 @@
 ts;%0A
-%0Aimport io.cloudevents.v02.ContextAttributes;%0A
+import java.util.Optional;%0Aimport java.util.stream.Collectors;%0A%0Aimport io.cloudevents.fun.BinaryFormatHeaderMapper;
 %0Aimport 
 stat
@@ -959,39 +959,32 @@
 rMapper;%0Aimport 
-static 
 io.cloudevents.v
@@ -978,37 +978,39 @@
 cloudevents.v02.
-http.
+Context
 AttributeMapper.
@@ -1002,36 +1002,17 @@
 ttribute
-Mapper.HEADER_PREFIX
+s
 ;%0A%0A/**%0A 
@@ -1116,16 +1116,351 @@
 er() %7B%7D%0A
+%09%0A%09private static final String HTTP_CONTENT_TYPE = %22Content-Type%22;%0A%0A%09/**%0A%09 * Following the signature of %7B@link BinaryFormatHeaderMapper%7D%0A%09 * @param attributes The map of attributes created by %7B@link AttributeMapper%7D%0A%09 * @param extensions The map of extensions created by %7B@link ExtensionMapper%7D%0A%09 * @return The map of HTTP Headers%0A%09 */
 %0A%09public
@@ -1706,16 +1706,69 @@
 tream()%0A
+%09%09%09.filter(attribute -%3E null!= attribute.getValue())%0A
 %09%09%09.map(
@@ -2174,83 +2174,44 @@
 %09%09%09.
-map(header -%3E new SimpleEntry%3C%3E(HEADER_PREFIX+header.getKey(),%0A%09%09%09%09%09%09header
+filter(extension -%3E null!= extension
 .get
@@ -2214,25 +2214,25 @@
 .getValue())
-)
+%0A
 %0A%09%09%09%09.collec
@@ -2297,35 +2297,28 @@
 %09%0A%09%09
-result.put(%22Content-Type%22, 
+Optional.ofNullable(
 attr
@@ -2323,21 +2323,16 @@
 tributes
-%0A%09%09%09%09
 .get(Con
@@ -2366,16 +2366,85 @@
 name()))
+%0A%09%09%09.ifPresent((ct) -%3E %7B%0A%09%09%09%09result.put(HTTP_CONTENT_TYPE, ct);%0A%09%09%09%7D)
 ;%0A%09%09%0A%09%09r

Fix on null and no ce prefix for extensions