本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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");
}
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}