本文整理汇总了Java中com.google.common.reflect.TypeToken.isSubtypeOf方法的典型用法代码示例。如果您正苦于以下问题:Java TypeToken.isSubtypeOf方法的具体用法?Java TypeToken.isSubtypeOf怎么用?Java TypeToken.isSubtypeOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.reflect.TypeToken
的用法示例。
在下文中一共展示了TypeToken.isSubtypeOf方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
if (targetTypeToken.isPrimitive()) {
targetTypeToken = PrimitiveTypeUtils.toWrapperTypeToken(targetTypeToken);
}
if (!targetTypeToken.isSubtypeOf(Number.class)) return false;
if (!(source instanceof String)) return false;
try {
NumberUtils.parseNumber((String) source, (Class) targetTypeToken.getType());
return true;
} catch (IllegalArgumentException e){
return false;
}
}
示例2: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
if (targetTypeToken.isPrimitive()) {
targetTypeToken = PrimitiveTypeUtils.toWrapperTypeToken(targetTypeToken);
}
return TypeToken.of(source.getClass()).isSubtypeOf(Number.class)
&& targetTypeToken.isSubtypeOf(Number.class);
}
示例3: extractElementTypeToken
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
* Extract TypeToken of generic type or Array component type.
* @param typeToken Target TypeToken
* @return generic TypeToken if typeToken is array or component TypeToken if typeToken is Array
*/
public static TypeToken<?> extractElementTypeToken(TypeToken<?> typeToken) {
if (typeToken.isSubtypeOf(List.class)) {
List<TypeToken<?>> genericTypeTokens = TypeTokenUtils.extractGenericTypeTokens(typeToken);
if (genericTypeTokens.size() == 0) {
return TypeToken.of(Object.class);
} else {
return genericTypeTokens.get(0);
}
} else if (typeToken.isArray()) {
return typeToken.getComponentType();
} else {
throw new IllegalArgumentException("typeToken must be from List or array");
}
}
示例4: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
return targetTypeToken.isSubtypeOf(BaseSingleFieldPeriod.class)
&& ((source instanceof Number) || (stringToNumberConverter.canHandle(source, TypeToken.of(Long.class))));
}
示例5: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
return targetTypeToken.isSubtypeOf(BaseLocal.class) && stringToDateConverter.canHandle(source, TypeToken.of(Date.class));
}
示例6: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
return targetTypeToken.isSubtypeOf(BaseLocal.class) && (source instanceof Date);
}
示例7: canHandle
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
public boolean canHandle(Object source, TypeToken<?> targetTypeToken) {
return (source != null) && targetTypeToken.isSubtypeOf(String.class);
}
示例8: convert
import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
* Convert the fixtureList to the given TypeToken
* @param fixtureList
* @param typeToken
* @return converted object from fixtureList.
* @throws IllegalAccessException
* @throws InstantiationException
*/
protected Object convert(FixtureList fixtureList, TypeToken<?> typeToken) {
boolean isArray = typeToken.isArray();
boolean isList = typeToken.isSubtypeOf(TypeToken.of(List.class));
if (!isList && !isArray) {
throw new FixtureMappingException("Target setter of '" + fixtureList.getFixtureName() + "' must be List or array.");
}
final List convertedList;
if (isArray || typeToken.getRawType().isInterface()) {
convertedList = new ArrayList();
} else {
try {
convertedList = (List) typeToken.getRawType().newInstance();
} catch (Exception e) {
throw new FixtureMappingException(e);
}
}
TypeToken<?> elementTypeToken = TypeTokenUtils.extractElementTypeToken(typeToken);
for (FixtureTemplate template : fixtureList) {
Object converted = convert(template, elementTypeToken);
if (converted != null) {
convertedList.add(converted);
} else {
logger.warn("Can not find converter for " + fixtureList.getFixtureName());
}
}
// not found converter
if (convertedList.size() == 0) return null;
if(isArray) {
if (elementTypeToken.isPrimitive()) {
return PrimitiveTypeUtils.toWrapperListToPrimitiveArray(convertedList, (Class<?>) elementTypeToken.getType());
} else {
return Arrays.copyOf(convertedList.toArray(), convertedList.size(), (Class) typeToken.getRawType());
}
} else {
return convertedList;
}
}