package com.metamx.common.parsers;

import com.google.common.collect.Maps;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 */
public class ToLowerCaseParser implements Parser<String, Object>
{
  private final Parser baseParser;

  public ToLowerCaseParser(Parser baseParser)
  {
    this.baseParser = baseParser;
  }

  @Override
  public Map parse(String input) throws IOException
  {
    Map<String, Object> line = baseParser.parse(input);
    Map<String, Object> retVal = Maps.newLinkedHashMap();
    for (Map.Entry<String, Object> entry : line.entrySet()) {
      retVal.put(entry.getKey().toLowerCase(), entry.getValue());
    }
    return retVal;
  }

  @Override
  public void setFieldNames(Iterable<String> fieldNames)
  {
    baseParser.setFieldNames(fieldNames);
  }

  @Override
  public List<String> getFieldNames()
  {
    return baseParser.getFieldNames();
  }
}

@@ -25,24 +25,69 @@
 n.parsers;%0A%0A
+import com.google.common.base.Preconditions;%0A
 import com.g
@@ -642,19 +642,19 @@
     
-retVal.put(
+String k = 
 entr
@@ -677,16 +677,118 @@
 erCase()
+;%0A%0A      Preconditions.checkState(!retVal.containsKey(k), %22Duplicate key %5B%25s%5D%22, k);%0A      retVal.put(k
 , entry.

add checks for duplicate key when switching to lower case