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

import java.util.function.IntFunction;
import net.ranides.assira.generic.CompareUtils;
import net.ranides.assira.generic.HashUtils;
import net.ranides.assira.test.TCollection;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class TCollections {
    
    private static final char[] LOWER_CHARS = "abcdefghijklmnopqrstuvwxyz".toCharArray();
    private static final char[] UPPER_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
    
    public static final TCollection<String> LOWER = produce(i -> {
        return "c-" + LOWER_CHARS[i%LOWER_CHARS.length] + "-" + i;
    });
    
    public static final TCollection<String> UPPER = produce(i -> {
        return "C-" + UPPER_CHARS[i%UPPER_CHARS.length] + "-" + i;
    });
    
    public static final TCollection<TPoint> POINT = produce(i -> new TPoint(i, i, i));
    
    public static final TCollection<Integer> NATURAL = produce(Integer::valueOf);
            
    public static <T> TCollection<T> produce(IntFunction<T> supplier) {
        return new ACollection<>(supplier);
    }
    
    private static class ACollection<T> extends TCollection<T> {
        
        private final IntFunction<T> supplier;

        public ACollection(IntFunction<T> supplier) {
            this.supplier = supplier;
        }

        @Override
        protected T value(int index, int n) {
            if(n != 0) {
                throw new UnsupportedOperationException("NO TEST");
            }
            return supplier.apply(index);
        }

        @Override
        protected int cmp(T a, T b) {
            return CompareUtils.cmp(a, b);
        }

        @Override
        protected int hash(T value) {
            return HashUtils.hash(value);
        }
        
        
    };
    
}
