當前位置: 首頁>>代碼示例>>Java>>正文


Java ClassReflection.isAssignableFrom方法代碼示例

本文整理匯總了Java中com.badlogic.gdx.utils.reflect.ClassReflection.isAssignableFrom方法的典型用法代碼示例。如果您正苦於以下問題:Java ClassReflection.isAssignableFrom方法的具體用法?Java ClassReflection.isAssignableFrom怎麽用?Java ClassReflection.isAssignableFrom使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.badlogic.gdx.utils.reflect.ClassReflection的用法示例。


在下文中一共展示了ClassReflection.isAssignableFrom方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/**
 * Converts json string into java object.
 *
 * @param wantedType        Wanted type
 * @param genericTypeKeeper Object with wanted type inside generic argument
 * @param jsonString        Json string data
 * @param <R>               Return type
 * @return
 */
public static <R> R process(Class<?> wantedType, Object genericTypeKeeper, String jsonString)
{
    Json json = new Json();
    json.setIgnoreUnknownFields(true);
    json.setTypeName(null);
    R result = null;
    if (ClassReflection.isAssignableFrom(List.class, wantedType)
            || ClassReflection.isAssignableFrom(Map.class, wantedType)) {
        NestedGenericType nestedGenericType = AnnotationProcessor.getNestedGenericTypeAnnotation(genericTypeKeeper);
        if (nestedGenericType == null) throw new NestedGenericTypeAnnotationMissingException();
        json.setDefaultSerializer(new JsonListMapDeserializer(wantedType, nestedGenericType.value()));
        result = (R) json.fromJson(wantedType, jsonString);
    } else {
        result = (R) json.fromJson(wantedType, jsonString);
    }
    return result;
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:27,代碼來源:JsonProcessor.java

示例2: JsonListMapDeserializer

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/**
 * @param type List or map value type, not null
 */
public JsonListMapDeserializer(Class<?> type, Class<?> contentType)
{
    if (!(ClassReflection.isAssignableFrom(List.class, type) || ClassReflection.isAssignableFrom(Map.class, type)))
        throw new WrongTypeForDeserializerException();
    this.type = type;
    this.contentType = contentType;
}
 
開發者ID:mk-5,項目名稱:gdx-fireapp,代碼行數:11,代碼來源:JsonListMapDeserializer.java

示例3: findIndex

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/** @return the index of the Influencer of the given type. */
private <K extends Influencer> int findIndex(Class<K> type){
	for(int i = 0; i< influencers.size; ++i){
		Influencer influencer = influencers.get(i);
		if(ClassReflection.isAssignableFrom(type, influencer.getClass())){
			return i;
		}
	}
	return -1;
}
 
開發者ID:Osaris31,項目名稱:exterminate,代碼行數:11,代碼來源:ParticleController.java

示例4: isInstanceOfAny

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
/** @param testedClass will be validated.
 * @param interfaces set of interfaces to be checked against.
 * @return true if the class implements any of the passed interfaces. */
protected boolean isInstanceOfAny(final Class<?> testedClass, final Class<?>[] interfaces) {
    for (final Class<?> possibleMatch : interfaces) {
        if (ClassReflection.isAssignableFrom(possibleMatch, testedClass)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:czyzby,項目名稱:gdx-lml,代碼行數:12,代碼來源:AbstractClassScanner.java

示例5: dispose

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static void dispose(Object object, Class<?> type) {

		// null check

		if(object == null) {
			return;
		}

		// if the field implements Disposable, call dispose() on it

		if (ClassReflection.isAssignableFrom(Disposable.class, type)) {
			((Disposable) object).dispose();
		}

		// call recursively if this field is @AutoDisposable itself

		if (ClassReflection.isAnnotationPresent(type, AutoDisposable.class)) {
			dispose(object);
		}

		// check if the field is an iterable container

		if (ClassReflection.isAssignableFrom(Iterable.class, type)) {
			Iterable<?> iterable = (Iterable<?>) object;
			iterable.forEach(AutoDisposer::dispose);
		}
	}
 
開發者ID:code-disaster,項目名稱:libgdx-snippets,代碼行數:28,代碼來源:AutoDisposer.java

示例6: tryLoadAndroidTwitterAPI

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void tryLoadAndroidTwitterAPI() {

		if (Gdx.app.getType() != ApplicationType.Android) {
			Gdx.app.debug(TAG, "Skip loading Twitter API for Android. Not running Android. \n");
			return;
		}

		if (Gdx.app.getType() == ApplicationType.Android) {
			try {

				Class<?> activityClazz = ClassReflection.forName("android.app.Activity");

				Class<?> twitterClazz = ClassReflection.forName("de.tomgrill.gdxtwitter.android.AndroidTwitterAPI");

				Object activity = null;

				if (ClassReflection.isAssignableFrom(activityClazz, gdxAppObject.getClass())) {

					activity = gdxAppObject;
				} else {

					Class<?> supportFragmentClass = findClass("android.support.v4.app.Fragment");
					// {
					if (supportFragmentClass != null && ClassReflection.isAssignableFrom(supportFragmentClass, gdxAppObject.getClass())) {

						activity = ClassReflection.getMethod(supportFragmentClass, "getActivity").invoke(gdxAppObject);
					} else {
						Class<?> fragmentClass = findClass("android.app.Fragment");
						if (fragmentClass != null && ClassReflection.isAssignableFrom(fragmentClass, gdxAppObject.getClass())) {
							activity = ClassReflection.getMethod(fragmentClass, "getActivity").invoke(gdxAppObject);
						}
					}

				}

				if (activity == null) {
					throw new RuntimeException("Can't find your gdx activity to instantiate gdx-twitter. " + "Looks like you have implemented AndroidApplication without using "
							+ "Activity or Fragment classes or Activity is not available at the moment");
				}

				Object twitter = ClassReflection.getConstructor(twitterClazz, activityClazz, TwitterConfig.class).newInstance(activity, config);

				gdxAppAddLifecycleListenerMethod.invoke(gdxAppObject, twitter);

				twitterAPI = (TwitterAPI) twitter;

				Gdx.app.debug(TAG, "gdx-twitter for Android loaded successfully.");

			} catch (Exception e) {
				Gdx.app.debug(TAG, "Error creating gdx-twitter for Android (are the gdx-twitter **.jar files installed?). \n");
				e.printStackTrace();
			}
		}
	}
 
開發者ID:TomGrill,項目名稱:gdx-twitter,代碼行數:55,代碼來源:TwitterSystem.java

示例7: installAndroidGDXDialogs

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private void installAndroidGDXDialogs() {

		if (Gdx.app.getType() != ApplicationType.Android) {
			showDebugSkipInstall(ApplicationType.Android.name());
			return;
		}

		if (Gdx.app.getType() == ApplicationType.Android) {
			try {

				Class<?> activityClazz = ClassReflection.forName("android.app.Activity");

				Class<?> dialogManagerClazz = ClassReflection.forName("de.tomgrill.gdxdialogs.android.AndroidGDXDialogs");

				Object activity = null;

				if (ClassReflection.isAssignableFrom(activityClazz, gdxAppObject.getClass())) {

					activity = gdxAppObject;
				} else {

					Class<?> supportFragmentClass = findClass("android.support.v4.app.Fragment");
					// {
					if (supportFragmentClass != null && ClassReflection.isAssignableFrom(supportFragmentClass, gdxAppObject.getClass())) {

						activity = ClassReflection.getMethod(supportFragmentClass, "getActivity").invoke(gdxAppObject);
					} else {
						Class<?> fragmentClass = findClass("android.app.Fragment");
						if (fragmentClass != null && ClassReflection.isAssignableFrom(fragmentClass, gdxAppObject.getClass())) {
							activity = ClassReflection.getMethod(fragmentClass, "getActivity").invoke(gdxAppObject);
						}
					}

				}

				if (activity == null) {
					throw new RuntimeException("Can't find your gdx activity to instantiate gdx-dialogs. " + "Looks like you have implemented AndroidApplication without using "
							+ "Activity or Fragment classes or Activity is not available at the moment");
				}
				Object dialogManager = ClassReflection.getConstructor(dialogManagerClazz, activityClazz).newInstance(activity);

				this.gdxDialogs = (GDXDialogs) dialogManager;
				showDebugInstallSuccessful(ApplicationType.Android.name());

			} catch (Exception e) {
				showErrorInstall(ApplicationType.Android.name(), "android");
				e.printStackTrace();
			}
		}
	}
 
開發者ID:TomGrill,項目名稱:gdx-dialogs,代碼行數:51,代碼來源:GDXDialogsSystem.java

示例8: loadFCM

import com.badlogic.gdx.utils.reflect.ClassReflection; //導入方法依賴的package包/類
private static void loadFCM(String name, FirebaseConfiguration firebaseConfiguration) {

        Class<?> loaderCls = null;

        try {
            if (Gdx.app.getType() == Application.ApplicationType.Android) {

                Class<?> activityClazz = ClassReflection.forName("android.app.Activity");

                Class<?> firebaseFCMClazz = ClassReflection.forName("de.tomgrill.gdxfirebase.android.fcm.AndroidFirebaseFCM");

                Object activity = null;

                Class<?> gdxClazz = ClassReflection.forName("com.badlogic.gdx.Gdx");
                Object gdxAppObject = ClassReflection.getField(gdxClazz, "app").get(null);

                if (ClassReflection.isAssignableFrom(activityClazz, gdxAppObject.getClass())) {

                    activity = gdxAppObject;
                } else {

                    Class<?> supportFragmentClass = findClass("android.support.v4.app.Fragment");
                    // {
                    if (supportFragmentClass != null && ClassReflection.isAssignableFrom(supportFragmentClass, gdxAppObject.getClass())) {

                        activity = ClassReflection.getMethod(supportFragmentClass, "getActivity").invoke(gdxAppObject);
                    } else {
                        Class<?> fragmentClass = findClass("android.app.Fragment");
                        if (fragmentClass != null && ClassReflection.isAssignableFrom(fragmentClass, gdxAppObject.getClass())) {
                            activity = ClassReflection.getMethod(fragmentClass, "getActivity").invoke(gdxAppObject);
                        }
                    }

                }

                if (activity == null) {
                    throw new RuntimeException("Can't find your gdx activity to instantiate gdx-firebase. " + "Looks like you have implemented AndroidApplication without using "
                            + "Activity or Fragment classes or Activity is not available at the moment");
                }

                Object firebaseFCM = ClassReflection.getConstructor(firebaseFCMClazz, activityClazz, FirebaseConfiguration.class).newInstance(activity, firebaseConfiguration);

//                Class<?> gdxLifecycleListenerClazz = ClassReflection.forName("com.badlogic.gdx.LifecycleListener");
//                Method gdxAppAddLifecycleListenerMethod = ClassReflection.getMethod(gdxAppObject.getClass(), "addLifecycleListener", gdxLifecycleListenerClazz);

//                gdxAppAddLifecycleListenerMethod.invoke(gdxAppObject, firebaseFCM);

                Gdx.app.addLifecycleListener((LifecycleListener) firebaseFCM);

                GDXFirebase.setFirebaseFCM(name, (FirebaseFCM) firebaseFCM);

                Gdx.app.debug("gdx-firebase", "FCM loaded for " + Gdx.app.getType());


                return;

            }

            if (Gdx.app.getType() == Application.ApplicationType.iOS) {

                loaderCls = ClassReflection.forName("de.tomgrill.gdxfirebase.iosmoe.fcm.IOSMOEFirebaseFCM");
                if (loaderCls != null) {
                    //Object loaderObj = ClassReflection.getConstructor(loaderCls, String.class, FirebaseConfiguration.class).newInstance(name, firebaseConfiguration);
                    Object loaderObj = ClassReflection.getConstructor(loaderCls).newInstance();

                    GDXFirebase.setFirebaseFCM(name, (FirebaseFCM) loaderObj);
                    Gdx.app.debug("gdx-firebase", "FCM for " + Gdx.app.getType() + " installed successfully with default implementation.");
                } else {
                    Gdx.app.debug("gdx-firebase", "FCM NOT LOADED for " + Gdx.app.getType());
                }
                return;
            }


        } catch (ReflectionException e) {
            e.printStackTrace();
        }

        GDXFirebase.setFirebaseFCM(name, new NullFirebaseFCM());
    }
 
開發者ID:TomGrill,項目名稱:gdx-firebase,代碼行數:81,代碼來源:FirebaseLoader.java


注:本文中的com.badlogic.gdx.utils.reflect.ClassReflection.isAssignableFrom方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。