org.springframework.core.convert.TypeDescriptor.collection()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(89)

本文整理了Java中org.springframework.core.convert.TypeDescriptor.collection()方法的一些代码示例,展示了TypeDescriptor.collection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TypeDescriptor.collection()方法的具体详情如下:
包路径:org.springframework.core.convert.TypeDescriptor
类名称:TypeDescriptor
方法名:collection

TypeDescriptor.collection介绍

[英]Create a new type descriptor from a java.util.Collection type.

Useful for converting to typed Collections.

For example, a List could be converted to a List by converting to a targetType built with this method. The method call to construct such a TypeDescriptor would look something like: collection(List.class, TypeDescriptor.valueOf(EmailAddress.class));
[中]从java创建一个新的类型描述符。util。收集类型。
用于转换为类型化集合。
例如,可以通过转换为使用此方法生成的targetType将列表转换为列表。构造这样一个TypeDescriptor的方法调用如下所示:collection(List.class,TypeDescriptor.valueOf(EmailAddress.class));

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
 * the type of the stream elements.
 * @param elementType the type of the stream elements
 * @param sourceType the type to convert from
 */
public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(sourceType, collectionOfElement);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Validate that a {@link Collection} of the elements held within the stream can be
 * converted to the specified {@code targetType}.
 * @param elementType the type of the stream elements
 * @param targetType the type to convert to
 */
public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(collectionOfElement, targetType);
}

代码示例来源: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: org.springframework/spring-core

/**
 * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
 * the type of the stream elements.
 * @param elementType the type of the stream elements
 * @param sourceType the type to convert from
 */
public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(sourceType, collectionOfElement);
}

代码示例来源:origin: org.springframework/spring-core

/**
 * Validate that a {@link Collection} of the elements held within the stream can be
 * converted to the specified {@code targetType}.
 * @param elementType the type of the stream elements
 * @param targetType the type to convert to
 */
public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(collectionOfElement, targetType);
}

代码示例来源:origin: org.springframework/spring-core

@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: org.springframework/spring-core

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

@Test
public void collection() {
  List<String> strings = new ArrayList<>();
  strings.add("3");
  strings.add("9");
  @SuppressWarnings("unchecked")
  List<Integer> integers = (List<Integer>) conversionService.convert(strings,
      TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(Integer.class)));
  assertEquals(Integer.valueOf(3), integers.get(0));
  assertEquals(Integer.valueOf(9), integers.get(1));
}

代码示例来源: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 collectionNested() {
  TypeDescriptor desc = TypeDescriptor.collection(List.class, TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(Integer.class)));
  assertEquals(List.class, desc.getType());
  assertEquals(List.class, desc.getObjectType());
  assertEquals("java.util.List", desc.getName());
  assertEquals("java.util.List<java.util.List<java.lang.Integer>>", desc.toString());
  assertTrue(!desc.isPrimitive());
  assertEquals(0, desc.getAnnotations().length);
  assertTrue(desc.isCollection());
  assertFalse(desc.isArray());
  assertEquals(List.class, desc.getElementTypeDescriptor().getType());
  assertEquals(TypeDescriptor.valueOf(Integer.class), desc.getElementTypeDescriptor().getElementTypeDescriptor());
  assertFalse(desc.isMap());
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void collection() {
  TypeDescriptor desc = TypeDescriptor.collection(List.class, TypeDescriptor.valueOf(Integer.class));
  assertEquals(List.class, desc.getType());
  assertEquals(List.class, desc.getObjectType());
  assertEquals("java.util.List", desc.getName());
  assertEquals("java.util.List<java.lang.Integer>", desc.toString());
  assertTrue(!desc.isPrimitive());
  assertEquals(0, desc.getAnnotations().length);
  assertTrue(desc.isCollection());
  assertFalse(desc.isArray());
  assertEquals(Integer.class, desc.getElementTypeDescriptor().getType());
  assertEquals(TypeDescriptor.valueOf(Integer.class), desc.getElementTypeDescriptor());
  assertFalse(desc.isMap());
}

代码示例来源:origin: spring-projects/spring-integration

TypeDescriptor targetType = TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class),
    TypeDescriptor.map(Map.class, TypeDescriptor.valueOf(String.class),
        TypeDescriptor.collection(Set.class, TypeDescriptor.valueOf(Bar.class))));

代码示例来源:origin: apache/servicemix-bundles

/**
 * Validate that a {@link Collection} of the elements held within the stream can be
 * converted to the specified {@code targetType}.
 * @param elementType the type of the stream elements
 * @param targetType the type to convert to
 */
public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(collectionOfElement, targetType);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Validate that a {@link Collection} of the elements held within the stream can be
 * converted to the specified {@code targetType}.
 * @param elementType the type of the stream elements
 * @param targetType the type to convert to
 */
public boolean matchesFromStream(@Nullable TypeDescriptor elementType, TypeDescriptor targetType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(collectionOfElement, targetType);
}

代码示例来源:origin: apache/servicemix-bundles

/**
 * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
 * the type of the stream elements.
 * @param elementType the type of the stream elements
 * @param sourceType the type to convert from
 */
public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(sourceType, collectionOfElement);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

/**
 * Validate that the specified {@code sourceType} can be converted to a {@link Collection} of
 * the type of the stream elements.
 * @param elementType the type of the stream elements
 * @param sourceType the type to convert from
 */
public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescriptor sourceType) {
  TypeDescriptor collectionOfElement = TypeDescriptor.collection(Collection.class, elementType);
  return this.conversionService.canConvert(sourceType, collectionOfElement);
}

代码示例来源:origin: apache/servicemix-bundles

@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: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

@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: apache/servicemix-bundles

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();
}

相关文章

微信公众号

最新文章

更多