All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.tcurrie.rest.factory.proxy.ProxyInvocationHandler Maven / Gradle / Ivy

There is a newer version: 0.2.70
Show newest version
package com.github.tcurrie.rest.factory.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ProxyInvocationHandler implements InvocationHandler {
    private final Map> methodHandlers;

    public static > ProxyInvocationHandler create(final Stream methodHandlers) {
        return new ProxyInvocationHandler(methodHandlers.collect(Collectors.toMap(ProxyMethod::getMethod, m->m)));
    }

    private ProxyInvocationHandler(final Map> methodHandlers) {
        this.methodHandlers = methodHandlers;
    }

    @Override
    public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
        return methodHandlers.get(method).invoke(args);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy