import java.lang.reflect.Method;
import java.lang.reflect.Array;


public final class Debugger
{
    
    public static String debug (Object inObject, String match)
    {
        StringBuffer sb = new StringBuffer();
        try
        {
            Object obj = null;
            Class cls = inObject.getClass();
            Method[] meths = cls.getMethods();
            Method method = null;
            
            for (int i = 0; i < meths.length; i++)
            {
                method = meths[i];
                String methodName = method.getName();
                int len = method.getParameterTypes().length;
                
                if (methodName.indexOf (match) > -1 && len == 0)
                {
                    obj = method.invoke (inObject, null);
                    if (obj != null)
                    {
                        if (method.getReturnType().isArray())
                        {
                            String arrString = printArray (obj);
                            sb.append (methodName + ":" + arrString);
                        }
                        else
                        {
                            sb.append (methodName + ":" + obj.toString() + "\n");    
                        }
                    }
                }
            }    
        }
        catch (Exception e)
        {
            System.out.println ("Debugger:debug(Object, String)::Exception--" +e.toString());    
        }
        return sb.toString();
        
    }
    
    private static String printArray (Object arr)
    {
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < Array.getLength(arr); i++)
        {
            sb.append (Array.get(arr,i).toString() + "\n");
        }
        return sb.toString();
    }
    
    public static void main (String args[])
    {
        //Use to print out values for TestObject's get methods.
        //NOTE: Debugger is set up for methods with null argument lists.
        //methods that do not have null argument lists will not be invoked
        TestObject t = new TestObject();
        String s = Debugger.debug (t, "get");
        System.out.println (s);
    }
}

class TestObject
{
    String name = "John";
    String age = "30";
    
    public String getName ()
    {
        return name;    
    }
    
    public String getAge ()
    {
        return age;    
    }
    
}