Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * This file is part of the PanoramaGL library for Android.
 *
 *  Authors: Javier Baez <javbaezga@gmail.com> and Miguel auay <mg_naunay@hotmail.com>
 *
 *  $Id$
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of
 * the License
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.lang.reflect.Method;

import java.util.HashMap;

public class Main {
    protected static HashMap<String, Method> methods = new HashMap<String, Method>();

    @SuppressWarnings("unchecked")
    public static Method getMethod(Object target, String name, Class... parameterTypes) {
        String key = target.getClass().getSimpleName() + ":" + name + ":"
                + (parameterTypes == null ? 0 : parameterTypes.length);
        Method method = methods.get(key);
        if (method == null) {
            for (Class obj = target.getClass(); !obj.equals(Object.class); obj = obj.getSuperclass()) {
                try {
                    method = obj.getDeclaredMethod(name, parameterTypes);
                    method.setAccessible(true);
                    methods.put(key, method);
                    break;
                } catch (SecurityException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    e.printStackTrace();
                }
            }
        }
        return method;
    }
}