List of usage examples for java.lang Class isAssignableFrom
@HotSpotIntrinsicCandidate public native boolean isAssignableFrom(Class<?> cls);
From source file:Main.java
public static List<Field> getAllFieldsOfType(List<Field> fields, Class<?> type, Class<?> fieldType) { for (Field field : type.getDeclaredFields()) { if (fieldType == null || fieldType.isAssignableFrom(field.getType())) { fields.add(field);//from w w w . j av a 2s . com } } if (type.getSuperclass() != null) { fields = getAllFieldsOfType(fields, type.getSuperclass(), fieldType); } return fields; }
From source file:org.eumetsat.metop.visat.AmsuInfoView.java
private static <T extends Layer> T getLayer(Layer parentLayer, Class<T> layerClass) { if (layerClass.isAssignableFrom(parentLayer.getClass())) { return (T) parentLayer; }/*from www . j a v a 2 s . com*/ for (final Layer childLayer : parentLayer.getChildren()) { final T layer = getLayer(childLayer, layerClass); if (layer != null) { return layer; } } return null; }
From source file:org.lightadmin.core.config.domain.common.AbstractFieldSetConfigurationBuilder.java
protected static void assertFieldMetadataType(FieldMetadata currentFieldMetadata, Class<?> type) { if (currentFieldMetadata == null || !type.isAssignableFrom(currentFieldMetadata.getClass())) { throw new RuntimeException("Field is not defined or wrong type."); }//from w w w.j av a 2s . co m }
From source file:Main.java
public static Object[] getArray(Object val) { Class<?> valKlass = val.getClass(); Object[] outputArray = null;//from ww w.j a v a 2s . co m for (Class<?> arrKlass : ARRAY_PRIMITIVE_TYPES) { if (valKlass.isAssignableFrom(arrKlass)) { int arrlength = Array.getLength(val); outputArray = new Object[arrlength]; for (int i = 0; i < arrlength; ++i) { outputArray[i] = Array.get(val, i); } break; } } if (outputArray == null) // not primitive type array outputArray = (Object[]) val; return outputArray; }
From source file:shiver.me.timbers.spring.security.modification.SecurityFilterChainModifier.java
private static int findFirstIndexOf(Class<? extends Filter> filterClass, List<Filter> filters) { for (int i = 0; i < filters.size(); i++) { if (filterClass.isAssignableFrom(filters.get(i).getClass())) { return i; }/*from w w w . ja v a 2 s .c o m*/ } return -1; }
From source file:Main.java
private static boolean isListenerRegistered(Object[] objects, Class t, EventListener l) { for (int i = 0; i < objects.length; i++) { Object listener = objects[i]; if (t.isAssignableFrom(listener.getClass()) && (listener == l)) { return true; }//from w w w. j a v a 2 s.co m } return false; }
From source file:Main.java
public static ParameterizedType resolveParameterizedType(Type t, Class<?> baseClass) { Class<?> raw = getRawType(t); if (t instanceof ParameterizedType && baseClass.isAssignableFrom(raw)) { return (ParameterizedType) t; }/*from w ww .j av a 2 s .c o m*/ ParameterizedType pt = null; if (raw.getSuperclass() != null && raw.getSuperclass() != Object.class) { pt = resolveParameterizedType(raw.getGenericSuperclass(), baseClass); if (pt != null) return pt; } if (!raw.isInterface()) { for (Type ifs : raw.getGenericInterfaces()) { pt = resolveParameterizedType(ifs, baseClass); if (pt != null) return pt; } } return null; }
From source file:hudson.maven.settings.SettingsProviderUtils.java
/** * utility method to retrieve Config of type (MavenSettingsProvider etc..) * /*from w w w. j av a 2s. co m*/ * @param settingsConfigId * @param type * @return Config */ public static Config findConfig(String settingsConfigId, Class<?>... types) { ExtensionList<ConfigProvider> configProviders = ConfigProvider.all(); if (configProviders != null && configProviders.size() > 0) { for (ConfigProvider configProvider : configProviders) { for (Class<?> type : types) { if (type.isAssignableFrom(configProvider.getClass())) { if (configProvider.isResponsibleFor(settingsConfigId)) { return configProvider.getConfigById(settingsConfigId); } } } } } return null; }
From source file:Main.java
public static <X extends View> X getChild(ViewGroup row, Class<X> klass) { assert klass != null; for (int i = 0; i < row.getChildCount(); i++) { View child = row.getChildAt(i); if (klass.isAssignableFrom(child.getClass())) { return klass.cast(child); }/*from w w w . jav a2 s . com*/ if (child instanceof ViewGroup) { X kid = getChild((ViewGroup) child, klass); if (kid != null) return kid; } } // fail return null; }
From source file:info.magnolia.cms.util.ExceptionUtil.java
/** * Returns true if the given exception or any of the nested cause exceptions is an instance of the <tt>suspectedCause</tt> exception argument, or a subclass thereof. * This is equivalent to ExceptionUtils.indexOfThrowable(e, javax.jcr.AccessDeniedException.class) >= 0, only more readable, and possibly more performant. *//*from ww w .j ava2 s .c o m*/ public static boolean wasCausedBy(Throwable e, Class<? extends Throwable> suspectedCause) { if (e != null && suspectedCause.isAssignableFrom(e.getClass())) { return true; } else if (e == null) { return false; } else { return wasCausedBy(e.getCause(), suspectedCause); } }