com.github.tcurrie.rest.factory.proxy.Methods Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rest.factory Show documentation
Show all versions of rest.factory Show documentation
Simple rest client-server factory, you give it a url, it does the rest!
package com.github.tcurrie.rest.factory.proxy;
import com.github.tcurrie.rest.factory.Strings;
import com.github.tcurrie.rest.factory.v1.RestFactoryException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.Stream;
public interface Methods {
Method EQUALS = TypeFactory.get(Object.class, "equals", Object.class);
Method HASH_CODE = TypeFactory.get(Object.class, "hashCode");
interface BeanFactory {
static Stream stream(final Object bean) {
return Arrays.stream(bean.getClass().getInterfaces()).flatMap(TypeFactory::stream);
}
static Stream map(final Object bean, Function, Function> function) {
return stream(bean).map(m -> function.apply(m.getDeclaringClass()).apply(m));
}
}
interface TypeFactory {
static Stream stream(final Class> type) {
return Arrays.stream(type.getMethods());
}
static Method get(Class> type, String methodName, Class>... args) {
try {
return type.getMethod(methodName, args);
} catch (NoSuchMethodException e) {
throw new RestFactoryException(Strings.format("Unable to find class[{}], method[{}], args[{}].", type, methodName, args));
}
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy