org.rekex.common_util.AnnoInvoHandler Maven / Gradle / Ivy
The newest version!
package org.rekex.common_util;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Function;
import java.util.function.Predicate;
class AnnoInvoHandler implements InvocationHandler
{
final Class clazz;
final Map elemValues; // containing all elements of the anno class
AnnoInvoHandler(Class clazz, Map elemValues)
{
this.clazz = clazz;
this.elemValues = elemValues;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args)
{
String name = method.getName();
{
Object value = elemValues.get(name);
if(value!=null)
return klone.apply(value);
// else not an element, because elem value cannot be null.
}
return switch (name)
{
case "annotationType"
-> clazz;
case "equals"
-> handle_equals(args);
case "hashCode"
-> handle_hashCode();
case "toString"
-> handle_toString();
// other methods in Object won't be dispatched to here
default -> throw new AssertionError("unexpected method: "+method);
};
}
final static Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy