<commit_before>package com.timgroup.karg.reflection;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.google.common.base.Preconditions;

public class Delegator<T, I> {
    
    private final Method targetMethod;
    private final Class<? super I> delegateClass;
    
    public static final class MethodNameBinder {
        private final String methodName;
        private MethodNameBinder(String methodName) {
            this.methodName = methodName;
        }
        
        public <T> Delegator.TargetClassBinder<T> of(final Class<? super T> targetClass) {
            return new Delegator.TargetClassBinder<T>() {
                @Override public <I> Delegator<T, I> to(Class<? super I> delegateClass) {
                   Method targetMethod = getTargetMethod(methodName, targetClass, delegateClass);
                   return new Delegator<T, I>(targetMethod, delegateClass);
                }
            };
        }
        
        public <T> ProxyBinder<T> ofInstance(final T targetInstance) {
            return new ProxyBinder<T>() {
                @SuppressWarnings("unchecked")
                @Override public <I> I to(Class<? super I> delegateClass) {
                    Class<T> targetClass = (Class<T>) targetInstance.getClass();
                    return ofMethod(methodName).of(targetClass).to(delegateClass).delegateTo(targetInstance);
                }
            };
        }
    }
    
    public static interface TargetClassBinder<T> {
        <I> Delegator<T, I> to(Class<? super I> delegateClass);
    }
    
    public static interface ProxyBinder<T> {
        <I> I to(Class<? super I> delegateClass);
    }
    
    public static Delegator.MethodNameBinder ofMethod(final String methodName) {
        return new MethodNameBinder(methodName);
    }
    <commit_msg>Fix generics compile error on some Linux machines.<commit_after>package com.timgroup.karg.reflection;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import com.google.common.base.Preconditions;

public class Delegator<T, I> {
    
    private final Method targetMethod;
    private final Class<? super I> delegateClass;
    
    public static final class MethodNameBinder {
        private final String methodName;
        private MethodNameBinder(String methodName) {
            this.methodName = methodName;
        }
        
        public <T> Delegator.TargetClassBinder<T> of(final Class<? super T> targetClass) {
            return new Delegator.TargetClassBinder<T>() {
                @Override public <I> Delegator<T, I> to(Class<? super I> delegateClass) {
                   Method targetMethod = getTargetMethod(methodName, targetClass, delegateClass);
                   return new Delegator<T, I>(targetMethod, delegateClass);
                }
            };
        }
        
        public <T> ProxyBinder<T> ofInstance(final T targetInstance) {
            return new ProxyBinder<T>() {
                @SuppressWarnings("unchecked")
                @Override public <I> I to(Class<? super I> delegateClass) {
                    Class<T> targetClass = (Class<T>) targetInstance.getClass();
                    return ofMethod(methodName).of(targetClass).<I>to(delegateClass).delegateTo(targetInstance);
                }
            };
        }
    }
    
    public static interface TargetClassBinder<T> {
        <I> Delegator<T, I> to(Class<? super I> delegateClass);
    }
    
    public static interface ProxyBinder<T> {
        <I> I to(Class<? super I> delegateClass);
    }
    
    public static Delegator.MethodNameBinder ofMethod(final String methodName) {
        return new MethodNameBinder(methodName);
    }
    
{'fraction_non_alphanumeric': 0.09373394966615306, 'fraction_numerical': 0.0, 'mean_word_length': 2.4196663740122917, 'pattern_counts': {'":': 0, '<': 52, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5214457', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1053, 'n_words': 255}