/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.mock;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.ranides.assira.generic.Function;
import net.ranides.assira.text.LexicalCast;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class ForMethodFactory<Q> {
    
    public final int value;
    
    public ForMethodFactory() {
        this.value = 77;
    }
    
    public ForMethodFactory(int a, int b) {
        if(a < 0 || b<0) {
            throw new ArithmeticException();
        }
        this.value = 100 * a + b;
    }
    
    public ForMethodFactory(List<String> list) {
        this(Integer.parseInt(list.get(0)), Integer.parseInt(list.get(1)));
    }
    
    public ForMethodFactory(Map<String,Q> map) {
        this(asint(map.get("a")), asint(map.get("b")));
    }
    
    public static int asint(Object value) {
        return LexicalCast.cast(value, int.class);
    }
    
    public static List<String> aslist(int a, int b) {
        if(a < 0 || b<0) {
            throw new ArithmeticException();
        }
        return Arrays.asList(""+a, ""+b);
    }
    
    public static Map<String, Short> asmap(int a, int b) {
        Map<String, Short> map = new HashMap<>();
        map.put("a", (short)a);
        map.put("b", (short)b);
        return map;
    }
    
    public List<Number> values(int a, int b, int c) {
        return Arrays.<Number>asList(a,b,c);
    }
    
    public int current() {
        return value;
    }
    
    public static class Function1 implements Function<Integer, String> {
        @Override
        public Integer apply(String source) {
            return Integer.parseInt(source);
        }
    };
    
    public static class Function2 implements Function<List<Integer>, List<String>> {
        @Override
        public List<Integer> apply(List<String> input) {
            List<Integer> ret = new ArrayList<>(input.size());
            for(String item : input) {
                ret.add(Integer.parseInt(item));
            }
            return ret;
        }
    };
    
}
