// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static String getAttributeName(Method method)
// {
//     Matcher matcher = getterOrSetterPattern.matcher(method.getName());
//     if (!matcher.matches()) {
//         throw new IllegalArgumentException("method does not represent a getter or setter");
//     }
//     return matcher.group(2);
// }
// 
// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static boolean isGetter(Method method)
// {
//     String methodName = method.getName();
//     return (methodName.startsWith("get") || methodName.startsWith("is")) && isValidGetter(method);
// }
// 
// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static boolean isSetter(Method method)
// {
//     return method.getName().startsWith("set") && isValidSetter(method);
// }


import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static org.weakref.jmx.ReflectionUtils.getAttributeName;
import static org.weakref.jmx.ReflectionUtils.isGetter;
import static org.weakref.jmx.ReflectionUtils.isSetter;
    public static MBeanBuilder from(String className)
    {
        return new MBeanBuilder(className);
    }

    public static MBeanBuilder from(Object object)
    {
        return new MBeanBuilder(object);
    }

    public MBeanBuilder(Object target)
    {
        if (target == null) {
            throw new NullPointerException("target is null");
        }

        Map<String, MBeanAttributeBuilder> attributeBuilders = new TreeMap<>();

        for (Map.Entry<Method, Method> entry : AnnotationUtils.findManagedMethods(target.getClass()).entrySet()) {
            Method concreteMethod = entry.getKey();
            Method annotatedMethod = entry.getValue();

            if (isGetter(concreteMethod) || isSetter(concreteMethod)) { // is it an attribute?
                String attributeName = getAttributeName(concreteMethod);

                MBeanAttributeBuilder attributeBuilder = attributeBuilders.get(attributeName);
                if (attributeBuilder == null) {
                    attributeBuilder = new MBeanAttributeBuilder().named(attributeName).onInstance(target);
                }
                
// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static String getAttributeName(Method method)
// {
//     Matcher matcher = getterOrSetterPattern.matcher(method.getName());
//     if (!matcher.matches()) {
//         throw new IllegalArgumentException("method does not represent a getter or setter");
//     }
//     return matcher.group(2);
// }
// 
// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static boolean isGetter(Method method)
// {
//     String methodName = method.getName();
//     return (methodName.startsWith("get") || methodName.startsWith("is")) && isValidGetter(method);
// }
// 
// Path: src/main/java/org/weakref/jmx/ReflectionUtils.java
// public static boolean isSetter(Method method)
// {
//     return method.getName().startsWith("set") && isValidSetter(method);
// }


// Path: src/main/java/org/weakref/jmx/MBeanBuilder.java
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import static org.weakref.jmx.ReflectionUtils.getAttributeName;
import static org.weakref.jmx.ReflectionUtils.isGetter;
import static org.weakref.jmx.ReflectionUtils.isSetter;

    public static MBeanBuilder from(String className)
    {
        return new MBeanBuilder(className);
    }

    public static MBeanBuilder from(Object object)
    {
        return new MBeanBuilder(object);
    }

    public MBeanBuilder(Object target)
    {
        if (target == null) {
            throw new NullPointerException("target is null");
        }

        Map<String, MBeanAttributeBuilder> attributeBuilders = new TreeMap<>();

        for (Map.Entry<Method, Method> entry : AnnotationUtils.findManagedMethods(target.getClass()).entrySet()) {
            Method concreteMethod = entry.getKey();
            Method annotatedMethod = entry.getValue();

            if (isGetter(concreteMethod) || isSetter(concreteMethod)) { // is it an attribute?
                String attributeName = getAttributeName(concreteMethod);

                MBeanAttributeBuilder attributeBuilder = attributeBuilders.get(attributeName);
                if (attributeBuilder == null) {
                    attributeBuilder = new MBeanAttributeBuilder().named(attributeName).onInstance(target);
                }
                
                if (isGetter(concreteMethod)) {