package io.highway.to.urhell.service.impl;

import io.highway.to.urhell.VersionUtils;
import io.highway.to.urhell.domain.EntryPathData;
import io.highway.to.urhell.domain.EntryPathParam;
import io.highway.to.urhell.domain.FrameworkEnum;
import io.highway.to.urhell.domain.TypePath;
import io.highway.to.urhell.service.AbstractLeechService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.NameValueExpression;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;

public class SpringServiceMethod extends AbstractLeechService {

    public SpringServiceMethod() {
        super(FrameworkEnum.SPRING_METHOD, VersionUtils.getVersion(
                RequestMappingInfo.class, "org.springframework",
                "spring-webmvc"));
    }

    public void gatherData(Object dataIncoming) {
        Map<RequestMappingInfo, HandlerMethod> handlerMethods = (Map<RequestMappingInfo, HandlerMethod>) dataIncoming;
        for (RequestMappingInfo element : handlerMethods.keySet()) {
            EntryPathData entry = new EntryPathData();
            entry.setTypePath(TypePath.DYNAMIC);
            entry.setUri(element.getPatternsCondition().toString());

            entry.setMethodEntry(element.getMethodsCondition().toString());
            if (element.getParamsCondition().getExpressions() != null) {
                List<EntryPathParam> listEntryPathData = new ArrayList<EntryPathParam>();
                for (NameValueExpression<String> nv : element
                        .getParamsCondition().getExpressions()) {
                    EntryPathParam param = new EntryPathParam();
                    param.setKey(nv.getName());
                    param.setValue(nv.getValue());
                    listEntryPathData.add(param);
                }
                entry.setListEntryPathData(listEntryPathData);

            }
            entry.setMethodName(handlerMethods.get(element).toString());
            addEntryPath(entry);
        }

    }

}

@@ -406,16 +406,44 @@
 til.Map;
+%0Aimport java.util.Map.Entry;
 %0A%0Aimport
@@ -1091,16 +1091,22 @@
    for (
+Entry%3C
 RequestM
@@ -1115,16 +1115,32 @@
 pingInfo
+, HandlerMethod%3E
  element
@@ -1161,10 +1161,12 @@
 ods.
-k
 e
+ntr
 ySet
@@ -1167,24 +1167,94 @@
 trySet()) %7B%0A
+            RequestMappingInfo requestMappingInfo = element.getKey();%0A
             
@@ -1272,16 +1272,20 @@
 ta entry
+path
  = new E
@@ -1313,24 +1313,28 @@
        entry
+path
 .setTypePath
@@ -1374,16 +1374,20 @@
 ntry
+path
 .setUri(
 elem
@@ -1382,23 +1382,34 @@
 .setUri(
-element
+requestMappingInfo
 .getPatt
@@ -1447,32 +1447,36 @@
            entry
+path
 .setMethodEntry(
@@ -1475,23 +1475,34 @@
 odEntry(
-element
+requestMappingInfo
 .getMeth
@@ -1545,23 +1545,34 @@
     if (
-element
+requestMappingInfo
 .getPara
@@ -1761,40 +1761,26 @@
 v : 
-element%0A                        
+requestMappingInfo
 .get
@@ -2066,24 +2066,28 @@
        entry
+path
 .setListEntr
@@ -2148,16 +2148,20 @@
    entry
+path
 .setMeth
@@ -2171,34 +2171,25 @@
 ame(
-handlerMethods.get(element
+element.getValue(
 ).to
@@ -2229,16 +2229,20 @@
 th(entry
+path
 );%0A     

use entryset in place of keySet + map.get(value)