// 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;
/**
 *  Copyright 2009 Martin Traverso
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.weakref.jmx;



final class MBeanBuilder
{
    private final String className;
    private final List<MBeanAttributeBuilder> attributeBuilders = new ArrayList<>();
    private final List<MBeanOperationBuilder> operationBuilders = new ArrayList<>();
    private String description;

    private MBeanBuilder(String className)
    {
        this.className = className;
    }

    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();

// 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;

/**
 *  Copyright 2009 Martin Traverso
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.weakref.jmx;



final class MBeanBuilder
{
    private final String className;
    private final List<MBeanAttributeBuilder> attributeBuilders = new ArrayList<>();
    private final List<MBeanOperationBuilder> operationBuilders = new ArrayList<>();
    private String description;

    private MBeanBuilder(String className)
    {
        this.className = className;
    }

    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?