本文整理了Java中org.springframework.core.convert.TypeDescriptor.getElementTypeDescriptor()
方法的一些代码示例,展示了TypeDescriptor.getElementTypeDescriptor()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeDescriptor.getElementTypeDescriptor()
方法的具体详情如下:
包路径:org.springframework.core.convert.TypeDescriptor
类名称:TypeDescriptor
方法名:getElementTypeDescriptor
[英]If this type is an array, returns the array's component type. If this type is a Stream, returns the stream's component type. If this type is a Collection and it is parameterized, returns the Collection's element type. If the Collection is not parameterized, returns null indicating the element type is not declared.
[中]如果此类型是数组,则返回数组的组件类型。如果此类型是流,则返回流的组件类型。如果此类型是集合且已参数化,则返回集合的元素类型。如果集合未参数化,则返回null,表示未声明元素类型。
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(
sourceType.getElementTypeDescriptor(), targetType.getElementTypeDescriptor(), this.conversionService);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType.getElementTypeDescriptor(),
targetType.getElementTypeDescriptor(), this.conversionService);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return (targetType.getElementTypeDescriptor() == null ||
this.conversionService.canConvert(sourceType, targetType.getElementTypeDescriptor()));
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(),
this.conversionService);
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public void setValue(@Nullable Object newValue) {
TypeDescriptor elementType = this.typeDescriptor.getElementTypeDescriptor();
Assert.state(elementType != null, "No element type");
setArrayElement(this.typeConverter, this.array, this.index, newValue, elementType.getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
return ConversionUtils.canConvertElements(sourceType, targetType.getElementTypeDescriptor(),
this.conversionService);
}
代码示例来源:origin: spring-projects/spring-framework
@Nullable
private Object convertFromStream(@Nullable Stream<?> source, TypeDescriptor streamType, TypeDescriptor targetType) {
List<Object> content = (source != null ? source.collect(Collectors.<Object>toList()) : Collections.emptyList());
TypeDescriptor listType = TypeDescriptor.collection(List.class, streamType.getElementTypeDescriptor());
return this.conversionService.convert(content, listType, targetType);
}
代码示例来源:origin: spring-projects/spring-framework
private Object convertToStream(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor streamType) {
TypeDescriptor targetCollection = TypeDescriptor.collection(List.class, streamType.getElementTypeDescriptor());
List<?> target = (List<?>) this.conversionService.convert(source, sourceType, targetCollection);
if (target == null) {
target = Collections.emptyList();
}
return target.stream();
}
代码示例来源:origin: spring-projects/spring-framework
@Override
public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
if (sourceType.isAssignableTo(STREAM_TYPE)) {
return matchesFromStream(sourceType.getElementTypeDescriptor(), targetType);
}
if (targetType.isAssignableTo(STREAM_TYPE)) {
return matchesToStream(targetType.getElementTypeDescriptor(), sourceType);
}
return false;
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void passDownGeneric() throws Exception {
TypeDescriptor td = new TypeDescriptor(getClass().getField("passDownGeneric"));
assertEquals(List.class, td.getElementTypeDescriptor().getType());
assertEquals(Set.class, td.getElementTypeDescriptor().getElementTypeDescriptor().getType());
assertEquals(Integer.class, td.getElementTypeDescriptor().getElementTypeDescriptor().getElementTypeDescriptor().getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void createCollectionWithNullElement() throws Exception {
TypeDescriptor typeDescriptor = TypeDescriptor.collection(List.class, null);
assertThat(typeDescriptor.getElementTypeDescriptor(), nullValue());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void elementTypePreserveContext() throws Exception {
TypeDescriptor desc = new TypeDescriptor(getClass().getField("listPreserveContext"));
assertEquals(Integer.class, desc.getElementTypeDescriptor().getElementTypeDescriptor().getType());
List<Integer> value = new ArrayList<>(3);
desc = desc.elementTypeDescriptor(value);
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(FieldAnnotation.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void propertyComplex() throws Exception {
Property property = new Property(getClass(), getClass().getMethod("getComplexProperty"),
getClass().getMethod("setComplexProperty", Map.class));
TypeDescriptor desc = new TypeDescriptor(property);
assertEquals(String.class, desc.getMapKeyTypeDescriptor().getType());
assertEquals(Integer.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getElementTypeDescriptor().getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void fieldComplexTypeDescriptor() throws Exception {
TypeDescriptor typeDescriptor = new TypeDescriptor(TypeDescriptorTests.class.getDeclaredField("arrayOfListOfString"));
assertTrue(typeDescriptor.isArray());
assertEquals(List.class,typeDescriptor.getElementTypeDescriptor().getType());
assertEquals(String.class, typeDescriptor.getElementTypeDescriptor().getElementTypeDescriptor().getType());
assertEquals("java.util.List<java.lang.String>[]",typeDescriptor.toString());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void propertyGenericTypeList() throws Exception {
GenericType<Integer> genericBean = new IntegerType();
Property property = new Property(getClass(), genericBean.getClass().getMethod("getListProperty"),
genericBean.getClass().getMethod("setListProperty", List.class));
TypeDescriptor desc = new TypeDescriptor(property);
assertEquals(List.class, desc.getType());
assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void elementTypeForCollectionSubclass() throws Exception {
@SuppressWarnings("serial")
class CustomSet extends HashSet<String> {
}
assertEquals(TypeDescriptor.valueOf(CustomSet.class).getElementTypeDescriptor(), TypeDescriptor.valueOf(String.class));
assertEquals(TypeDescriptor.forObject(new CustomSet()).getElementTypeDescriptor(), TypeDescriptor.valueOf(String.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void fieldMap() throws Exception {
TypeDescriptor desc = new TypeDescriptor(TypeDescriptorTests.class.getField("fieldMap"));
assertTrue(desc.isMap());
assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
assertEquals(Long.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void property() throws Exception {
Property property = new Property(
getClass(), getClass().getMethod("getProperty"), getClass().getMethod("setProperty", Map.class));
TypeDescriptor desc = new TypeDescriptor(property);
assertEquals(Map.class, desc.getType());
assertEquals(Integer.class, desc.getMapKeyTypeDescriptor().getElementTypeDescriptor().getType());
assertEquals(Long.class, desc.getMapValueTypeDescriptor().getElementTypeDescriptor().getType());
assertNotNull(desc.getAnnotation(MethodAnnotation1.class));
assertNotNull(desc.getAnnotation(MethodAnnotation2.class));
assertNotNull(desc.getAnnotation(MethodAnnotation3.class));
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void projectionTypeDescriptors_2() {
StandardEvaluationContext context = new StandardEvaluationContext(new C());
SpelExpressionParser parser = new SpelExpressionParser();
String el1 = "as.![#this.equals('abc')]";
SpelExpression exp = parser.parseRaw(el1);
Object[] value = (Object[]) exp.getValue(context);
// value is array containing [true,false]
assertEquals(Boolean.class, value[0].getClass());
TypeDescriptor evaluated = exp.getValueTypeDescriptor(context);
assertEquals(Boolean.class, evaluated.getElementTypeDescriptor().getType());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void valueOfArray() throws Exception {
TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(int[].class);
assertTrue(typeDescriptor.isArray());
assertFalse(typeDescriptor.isCollection());
assertFalse(typeDescriptor.isMap());
assertEquals(Integer.TYPE, typeDescriptor.getElementTypeDescriptor().getType());
}
内容来源于网络,如有侵权,请联系作者删除!