package com.akm.http.request;

import java.beans.IntrospectionException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;

import com.akm.http.exception.HttpRequestTranslationException;
import com.akm.http.util.BeanUtil;

/**
 * Base abstract class that provides default functionality for request parameter
 * translation.
 * <p>
 * All request object classes should extend this class.
 *
 * @see RequestParameter
 * @see RequestTranslator
 * @since 0.3
 * @author Amir
 */
public abstract class AbstractRequestTranslator implements RequestTranslator {
    /**
     * Predicate used to determine if a field has the RequestParameter
     * annotation for translation.
     */
    private static final Predicate<Field> IS_ANNOTATED = (field) -> field
            .isAnnotationPresent(RequestParameter.class);

    @Override
    public Map<String, String> translate()
            throws HttpRequestTranslationException {
        final Map<String, String> map = new HashMap<>();
        final List<Field> fields = Arrays
                .asList(getClass().getDeclaredFields());

        fields.parallelStream().filter(IS_ANNOTATED).forEach(field -> {
            try {
                final String name = field.getAnnotation(RequestParameter.class)
                        .value();
                final String value = BeanUtil
                        .invokeGetter(field.getName(), getClass(), this)
                        .toString();
                map.put(name, value);
            } catch (IllegalAccessException | IllegalArgumentException
                    | InvocationTargetException | IntrospectionException e) {
                throw new HttpRequestTranslationException(
                        "unable to translate request parameter fields", e);
            }
        });

        return map;
    }
}

@@ -205,31 +205,8 @@
 ap;%0A
-import java.util.List;%0A
 impo
@@ -1113,24 +1113,25 @@
 ap%3C%3E();%0A
+%0A
         
 final Li
@@ -1126,131 +1126,81 @@
     
-final List%3CField%3E fields = Arrays%0A                .asList(getClass().getDeclaredFields());%0A%0A        fields.parallelStream()
+Arrays.stream(getClass().getDeclaredFields()).parallel()%0A                
 .fil
@@ -1252,14 +1252,30 @@
     
+    
+    
 try %7B%0A
+        
     
@@ -1307,24 +1307,57 @@
 name = field
+%0A                                
 .getAnnotati
@@ -1386,33 +1386,8 @@
 ass)
-%0A                        
 .val
@@ -1388,24 +1388,32 @@
 s).value();%0A
+        
             
@@ -1446,16 +1446,24 @@
 eanUtil%0A
+        
         
@@ -1551,16 +1551,24 @@
         
+        
 .toStrin
@@ -1588,16 +1588,24 @@
         
+  
+      
 map.put(
@@ -1614,24 +1614,32 @@
 me, value);%0A
+        
             
@@ -1717,16 +1717,24 @@
         
+        
 %7C Invoca
@@ -1748,24 +1748,52 @@
 getException
+%0A                           
  %7C Introspec
@@ -1823,24 +1823,32 @@
             
+       
+ 
 throw new Ht
@@ -1878,16 +1878,24 @@
 eption(%0A
+        
         
@@ -1961,13 +1961,52 @@
 ds%22,
- e);%0A
+%0A                                e);%0A       
     
@@ -2013,18 +2013,27 @@
         
+ 
 %7D%0A
+        
         

Change how stream is acquired