/** * 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); }
/** * 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); }
@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); }
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(); }
/** * 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); }
/** * 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); }
@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); }
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(); }
@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)); }
@Test public void createCollectionWithNullElement() throws Exception { TypeDescriptor typeDescriptor = TypeDescriptor.collection(List.class, null); assertThat(typeDescriptor.getElementTypeDescriptor(), nullValue()); }
@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()); }
@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()); }
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))));
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@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); }
@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); }
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(); }