当前位置: 首页>>代码示例>>Java>>正文


Java ClassUtils.isAssignable方法代码示例

本文整理汇总了Java中org.apache.commons.lang3.ClassUtils.isAssignable方法的典型用法代码示例。如果您正苦于以下问题:Java ClassUtils.isAssignable方法的具体用法?Java ClassUtils.isAssignable怎么用?Java ClassUtils.isAssignable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.lang3.ClassUtils的用法示例。


在下文中一共展示了ClassUtils.isAssignable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: byteVectorToByteArray

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
protected byte[] byteVectorToByteArray(Vector<?> _vector) {
    if (_vector == null) {
        return null;
    }
    if (_vector.isEmpty()) {
        return new byte[] {};
    }

    if (!ClassUtils.isAssignable(byte.class, _vector.get(0).getClass())) {
        return null;
    }

    byte[] result = new byte[_vector.size()];
    for (int i = 0; i < _vector.size(); i++) {
        Object x = _vector.get(i);
        result[i] = (byte) x;
    }

    return result;
}
 
开发者ID:hypfvieh,项目名称:bluez-dbus,代码行数:21,代码来源:AbstractBluetoothObject.java

示例2: init

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private Object init(Class<?> clazz)
{
	Object o = null;

	try
	{
		if(ClassUtils.isAssignable(clazz, ScriptListener.class))
		{
			o = clazz.newInstance();

			_listeners.add((ScriptListener)o);
		}
	}
	catch(Exception e)
	{
		_log.error("", e);
	}
	return o;
}
 
开发者ID:CalypsoToolz,项目名称:FPAgar,代码行数:20,代码来源:ScriptsLoader.java

示例3: resolveException

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
@Override
public ModelAndView resolveException(HttpServletRequest request,
                                     HttpServletResponse response,
                                     Object handler,
                                     Exception ex) {

    log.error("Unexpected errs occurred in handle request.", ex);

    // if handler is instance of HandlerMethod then it's a http request,
    // otherwise it's a websocket request or other service.
    if (handler instanceof HandlerMethod) {
        HandlerMethod handlerMethod = (HandlerMethod) handler;
        boolean returnResponseEntity = ClassUtils.isAssignable(handlerMethod.getMethod().getReturnType(),
                ResponseEntity.class);
        boolean hasResponseBodyAnnotation = Objects.nonNull(handlerMethod.getMethodAnnotation(ResponseBody.class));

        if (returnResponseEntity || hasResponseBodyAnnotation) {
            return new ModelAndView(new RedirectView(view5xx));
        } else {
            return new ModelAndView(new RedirectView(ajax5xx));
        }
    }

    return null;
}
 
开发者ID:srarcbrsent,项目名称:tc,代码行数:26,代码来源:TcHandleExceptionHandler.java

示例4: isAssignableTypes

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * Tests whether are passed arguments assignable to the given types.
 * 
 * @param args Arguments to be tested.
 * @param types Types.
 * @return True if are passed arguments assignable to the given types.
 */
public static boolean isAssignableTypes(Object[] args, Class<?>... types) {
	if (args.length != types.length) {
		return false;
	}
	
	for (int i = 0; i < args.length; i++) {
		Class<?> argClass = (args[i] == null)? null : args[i].getClass();
		Class<?> paramClass = types[i];
		
		if (paramClass.isPrimitive() && argClass == null) {
			return false;
		} else if (!paramClass.isPrimitive() && argClass == null) {
			continue; 
		} else if (!ClassUtils.isAssignable(argClass, paramClass, true)) {
			return false;
		}
	}
	
	return true;
}
 
开发者ID:jutils,项目名称:jsen-core,代码行数:28,代码来源:ClassFunction.java

示例5: convert

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * Convert value to enum.
 *
 * @param cls enum to convert to
 * @param value value to convert
 * @param <T> enum type
 * @return enum
 */
@Override
public <T> T convert(Class<T> cls, Object value) {

    try {
        if (ClassUtils.isAssignable(value.getClass(), String.class)) {
            return stringToEnum(cls, (String) value);
        } else if (ClassUtils.isAssignable(value.getClass(), Integer.class, true)) {
            return intToEnum(cls, (Integer) value);
        } else {
           throw new UnsupportedOperationException(value.getClass().getSimpleName() + " to Enum no supported");
        }
    } catch (IndexOutOfBoundsException | ReflectiveOperationException
            | UnsupportedOperationException | IllegalArgumentException e) {
        throw new InvalidAttributeException("Unknown " + cls.getSimpleName() + " value " + value, e);
    }
}
 
开发者ID:yahoo,项目名称:elide,代码行数:25,代码来源:ToEnumConverter.java

示例6: getProperty

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
@Nullable
public static <T> T getProperty(Map<String, Object> props, String propName, Class<T> propValueClass, @Nullable T defaultPropValue) {
    if (!props.containsKey(propName)) {
        return null;
    }

    Object propValue = props.get(propName);

    if (propValue == null) {
        return defaultPropValue;
    }

    Class<?> actualPropValueClass = propValue.getClass();

    if (!ClassUtils.isAssignable(actualPropValueClass, propValueClass)) {
        throw new ClassCastException(String.format("Property (name=%s) value is not assignable (actualClass=%s, class=%s).", propName,
            actualPropValueClass.getName(), propValueClass.getName()));
    }

    return propValueClass.cast(propValue);
}
 
开发者ID:esacinc,项目名称:sdcct,代码行数:22,代码来源:SdcctWsPropertyUtils.java

示例7: getTyped

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * Helper to get a value of a DBus property.
 * @param _field DBus property key
 * @param _type expected return type of DBus property
 * @param <T> class of the expected result
 * @return value of _field as _type class or null
 */
@SuppressWarnings("unchecked")
protected <T> T getTyped(String _field, Class<T> _type) {
    try {
        SignalAwareProperties remoteObject = dbusConnection.getRemoteObject("org.bluez", dbusPath, SignalAwareProperties.class);
        Object obj = remoteObject.Get(getInterfaceClass().getName(), _field);
        if (ClassUtils.isAssignable(_type, obj.getClass())) {
            return (T) obj;
        }

    } catch (DBusException _ex) {
    }
    return null;
}
 
开发者ID:hypfvieh,项目名称:bluez-dbus,代码行数:21,代码来源:AbstractBluetoothObject.java

示例8: isAssignableFrom

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public boolean isAssignableFrom(Type type) {
    if (! ClassUtils.isAssignable(type.C(), this.C()))
        return false;
    if (t == null || ! t.isParameterizedType()) // this type is not yet concretized or not parametric
        return true;
    if (! type.T().isParameterizedType())
        return false;

    // sanity check
    ParameterizedType pt1 = (ParameterizedType) T();
    ParameterizedType pt2 = (ParameterizedType) type.T();
    int n1 = pt1.typeArguments().size();
    int n2 = pt2.typeArguments().size();
    if (n1 != n2)
        throw new SynthesisException(SynthesisException.GenericTypeVariableMismatch);

    for (int i = 0; i < n1; i++) {
        Type t1 = new Type((org.eclipse.jdt.core.dom.Type) pt1.typeArguments().get(i));
        Type t2 = new Type((org.eclipse.jdt.core.dom.Type) pt2.typeArguments().get(i));

        // generic type arguments should always be invariant, not covariant
        // for example, a List<Dog> cannot be a List<Animal> even if Dog extends Animal
        if (! t1.isInvariant(t2))
            return false;
    }
    return true;
}
 
开发者ID:capergroup,项目名称:bayou,代码行数:28,代码来源:Type.java

示例9: implAs

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static ComponentMeta implAs(Class<?> asClass, Object instance) {
    if (!ClassUtils.isAssignable(instance.getClass(), asClass)) {
        throw new IllegalArgumentException("instance(type["+instance.getClass()+"]) cannot not assign to asClass["+asClass+"]");
    }
    return new ComponentMeta(asClass, instance);
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:8,代码来源:ComponentMeta.java

示例10: fillHeader

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private void fillHeader(Header header, Data item) {
    for (String key : item.keySet()) {
        Serializable serializable = item.get(key);

        if (key.length() > 8) {
            log.warn("Key {} too long, truncating to {}", key, key.substring(0, 8));
            key = key.substring(0, 8);
        }

        Class<? extends Serializable> type = serializable.getClass();
        try {
            if (ClassUtils.isAssignable(type, String.class)) {
                header.addValue(key, (String) serializable, "");
            } else if (ClassUtils.isAssignable(type, Integer.class)) {
                header.addValue(key, (int) serializable, "");
            } else if (ClassUtils.isAssignable(type, Double.class)) {
                header.addValue(key, (double) serializable, "");
            } else if (ClassUtils.isAssignable(type, Float.class)) {
                header.addValue(key, (float) serializable, "");
            } else if (ClassUtils.isAssignable(type, Short.class)) {
                header.addValue(key, (short) serializable, "");
            } else if (ClassUtils.isAssignable(type, Long.class)) {
                header.addValue(key, (long) serializable, "");
            } else if (ClassUtils.isAssignable(type, Boolean.class)) {
                header.addValue(key, (boolean) serializable, "");
            } else if (ClassUtils.isAssignable(type, ZonedDateTime.class)) {
                ZonedDateTime zonedDateTime = (ZonedDateTime) serializable;
                String iso = formatDateTime(zonedDateTime);
                header.addValue(key, iso, "");
            } else {
                throw new RuntimeException("Key '" + key + "' cannot be saved to FITS Header");
            }
        } catch (HeaderCardException e) {
            log.error("Could not write key {} to FITS header", key);
            throw new RuntimeException(e);
        }
    }
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:39,代码来源:FITSWriter.java

示例11: wrapInArray

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
private Object wrapInArray(Serializable serializable) throws RuntimeException {
    Class<? extends Serializable> type = serializable.getClass();

    // if the value is an array, we can directly add it
    if (type.isArray()) {
        return serializable;
    } else {
        // primitive values need to be wrapped into an array of length 1
        if (ClassUtils.isAssignable(type, String.class)) {
            return new String[]{(String) serializable};
        } else if (ClassUtils.isAssignable(type, Integer.class)) {
            return new int[]{(int) serializable};
        } else if (ClassUtils.isAssignable(type, Double.class)) {
            return new double[]{(double) serializable};
        } else if (ClassUtils.isAssignable(type, Float.class)) {
            return new float[]{(float) serializable};
        } else if (ClassUtils.isAssignable(type, Short.class)) {
            return new short[]{(short) serializable};
        } else if (ClassUtils.isAssignable(type, Long.class)) {
            return new long[]{(long) serializable};
        } else if (ClassUtils.isAssignable(type, Boolean.class)) {
            return new boolean[]{(boolean) serializable};
        } else if (ClassUtils.isAssignable(type, ZonedDateTime.class)) {
            ZonedDateTime zonedDateTime = (ZonedDateTime) serializable;
            String iso = formatDateTime(zonedDateTime);
            return new String[]{iso};
        } else {
            throw new RuntimeException("Serializable cannot be saved to FITS");
        }
    }
}
 
开发者ID:fact-project,项目名称:fact-tools,代码行数:32,代码来源:FITSWriter.java

示例12: cleanValueToSend

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * When send keys is being executed in a input file=type {@link LocalFileDetector} must be configured for remote drivers. Additionally,
 * the file path is expanded to be absolute
 *
 * @param driver used to run commands
 * @param element receiving keys
 * @param value to be set to input file type
 * @return value expanded to absolute path if for input file type.
 */
private String cleanValueToSend(WebDriver driver, WebElement element, String value) {
	if (!StringUtils.equals(element.getAttribute(SeleniumFixture.INPUT_TYPE_ATTRIBUTE), SeleniumFixture.INPUT_TYPE_FILE_VALUE)) {
		return this.fitnesseMarkup.clean(value);
	}
	// set file detector for remote web elements. Local FirefoxDriver uses RemoteWebElement and
	if (element instanceof RemoteWebElement && !ClassUtils.isAssignable(driver.getClass(), FirefoxDriver.class)) {
		((RemoteWebElement) element).setFileDetector(new LocalFileDetector());
	}
	return this.fitnesseMarkup.cleanFile(value).getAbsolutePath();
}
 
开发者ID:andreptb,项目名称:fitnesse-selenium-slim,代码行数:20,代码来源:SeleniumFixture.java

示例13: getObjectTransformationCost

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * Gets the number of steps required needed to turn the source class into
 * the destination class. This represents the number of steps in the object
 * hierarchy graph.
 *
 * @param srcClass  The source class
 * @param destClass The destination class
 * @return The cost of transforming an object
 */
private static float getObjectTransformationCost(Class<?> srcClass, final Class<?> destClass) {
    if (destClass.isPrimitive()) {
        return getPrimitivePromotionCost(srcClass, destClass);
    }
    float cost = 0.0f;
    while (srcClass != null && !destClass.equals(srcClass)) {
        if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass)) {
            // slight penalty for interface match.
            // we still want an exact match to override an interface match,
            // but
            // an interface match should override anything where we have to
            // get a superclass.
            cost += 0.25f;
            break;
        }
        cost++;
        srcClass = srcClass.getSuperclass();
    }
    /*
     * If the destination class is null, we've travelled all the way up to
     * an Object match. We'll penalize this by adding 1.5 to the cost.
     */
    if (srcClass == null) {
        cost += 1.5f;
    }
    return cost;
}
 
开发者ID:rogerxaic,项目名称:gestock,代码行数:37,代码来源:MemberUtils.java

示例14: fetchSubclassByJar

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
public static String[] fetchSubclassByJar(Class<?> clazz, String jarName, List<String> filters) {
	ZipFile zip = null;
	try {
		zip = new ZipFile(jarName);
		ZipEntry entry = null;
		Enumeration<? extends ZipEntry> entries = zip.entries();
		String entryName = null;
		String className = null;
		int endsLen = CLASS_FILE_SUFFIX.length();// 扩展名的长度,包括点号
		ArrayList<String> list = new ArrayList<String>();
		while (entries.hasMoreElements()) {
			entry = entries.nextElement();
			entryName = entry.getName();
			if (!entry.isDirectory() && entryName.endsWith(CLASS_FILE_SUFFIX)) {
				className = entryName.substring(0, entryName.length() - endsLen);
				className = className.replace(File.separator, ".");
				className = className.replaceAll("/", ".");//纯粹是为了保护,避免\/的处理,可能会损失性能
				//过滤jar包中所需要过滤的包
				if(isFilterPackage(className,filters)){
					if(ClassUtils.isAssignable(Class.forName(className), clazz)) {
						list.add(className);
					}
				}
			}
		}
		if (list.size() > 0) {
			String[] rets = new String[list.size()];
			list.toArray(rets);
			return rets;
		}
	} catch (Exception e) {//
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:noc0der,项目名称:uranus,代码行数:36,代码来源:ClassRefHelper.java

示例15: isEntityClass

import org.apache.commons.lang3.ClassUtils; //导入方法依赖的package包/类
/**
 * 
 * @param subClassName
 * @return
 */
private static boolean isEntityClass(String subClassName) {
	//FIXME 叫isEntityClass会更合适一些
	try {
		Class<?> temp = Class.forName(subClassName);
		//如果是接口或者抽象类,就不是实体类
		//如果没有实现ivalueobject就不算实体类
		if(temp.isInterface() || Modifier.isAbstract(temp.getModifiers()) || ClassUtils.isAssignable(temp,IValueObject.class)){
			return false;
		}
		return true;
	} catch (Throwable e) {
	}
	return false;
}
 
开发者ID:noc0der,项目名称:uranus,代码行数:20,代码来源:ClassRefHelper.java


注:本文中的org.apache.commons.lang3.ClassUtils.isAssignable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。