package com.hamishrickerby.http_server;

import java.util.*;

/**
 * Created by rickerbh on 18/08/2016.
 */
public class Headers {
    private static String HEADER_SEPARATOR = ": ";

    Map<String, String> headers;

    public Headers() {
        headers = new HashMap<>();
    }

    public List<String> list() {
        List<String> headerList = new ArrayList<>();
        for (String key : headers.keySet()) {
            headerList.add(key + HEADER_SEPARATOR + headers.get(key));
        }
        return headerList;
    }

    public void put(String key, String value) {
        headers.put(key, value);
    }

    public void parse(String headerString) {
        String[] lines = headerString.split("\r\n");
        for (String line : Arrays.asList(lines)) {
            String[] components = line.split(":");
            put(components[0].trim(), components[1].trim());
        }
    }

    public String get(String key) {
        return headers.getOrDefault(key, "");
    }

}

@@ -51,17 +51,129 @@
 va.util.
-*
+Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0Aimport java.util.stream.Collectors
 ;%0A%0A/**%0A 
@@ -432,78 +432,14 @@
     
-List%3CString%3E headerList = new ArrayList%3C%3E();%0A        for (String key :
+return
  hea
@@ -451,19 +451,25 @@
 keySet()
-) %7B
+.stream()
 %0A       
@@ -477,23 +477,24 @@
     
-headerList.add(
+    .map(key -%3E 
 key 
@@ -531,17 +531,16 @@
 et(key))
-;
 %0A       
@@ -544,18 +544,16 @@
     
-%7D%0A
         
 retu
@@ -552,25 +552,37 @@
     
-return header
+.collect(Collectors.to
 List
+())
 ;%0A  

Refactor headers list() with map/collect