本文整理汇总了Java中org.springframework.data.util.TypeInformation.getComponentType方法的典型用法代码示例。如果您正苦于以下问题:Java TypeInformation.getComponentType方法的具体用法?Java TypeInformation.getComponentType怎么用?Java TypeInformation.getComponentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.data.util.TypeInformation
的用法示例。
在下文中一共展示了TypeInformation.getComponentType方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
private Object readCollection(Collection<?> source, TypeInformation<?> type, Object parent) {
Assert.notNull(type);
Class<?> collectionType = type.getType();
if (CollectionUtils.isEmpty(source)) {
return source;
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items;
if (type.getType().isArray()) {
items = new ArrayList<Object>();
} else {
items = CollectionFactory.createCollection(collectionType, source.size());
}
TypeInformation<?> componentType = type.getComponentType();
Iterator<?> it = source.iterator();
while (it.hasNext()) {
items.add(readValue(it.next(), componentType, parent));
}
return type.getType().isArray() ? convertItemsToArrayOfType(type, items) : items;
}
示例2: writeCollectionInternal
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Helper method to write the internal collection.
*
* @param source the source object.
* @param target the target document.
* @param type the type information for the document.
* @return the created crate list.
*/
private CrateArray writeCollectionInternal(final Collection<?> source, final CrateArray target, final TypeInformation<?> type) {
TypeInformation<?> componentType = type == null ? null : type.getComponentType();
for(Object element : source) {
validateCollectionLikeElement(element);
Class<?> elementType = element == null ? null : element.getClass();
if(elementType == null || conversions.isSimpleType(elementType)) {
target.add(element);
}else {
CrateDocument document = new CrateDocument();
writeInternal(element, document, componentType);
target.add(document);
}
}
return target;
}
示例3: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Object readCollection(Collection<?> source, TypeInformation<?> type, Object parent) {
Assert.notNull(type);
Class<?> collectionType = type.getType();
if (CollectionUtils.isEmpty(source)) {
return source;
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items = type.getType().isArray() ? new ArrayList<Object>() : CollectionFactory
.createCollection(collectionType, source.size());
TypeInformation<?> componentType = type.getComponentType();
Iterator<?> it = source.iterator();
while (it.hasNext()) {
items.add(readValue(it.next(), componentType, parent));
}
return type.getType().isArray() ? convertItemsToArrayOfType(type, items) : items;
}
示例4: readCollectionOrArray
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Reads the given {@link List} into a collection of the given {@link TypeInformation}
* .
*
* @param targetType must not be {@literal null}.
* @param sourceValue must not be {@literal null}.
* @return the converted {@link Collection} or array, will never be {@literal null}.
*/
@Nullable
@SuppressWarnings({ "rawtypes", "unchecked" })
private Object readCollectionOrArray(TypeInformation<?> targetType, List sourceValue) {
Assert.notNull(targetType, "Target type must not be null!");
Class<?> collectionType = targetType.getType();
TypeInformation<?> componentType = targetType.getComponentType() != null ? targetType
.getComponentType() : ClassTypeInformation.OBJECT;
Class<?> rawComponentType = componentType.getType();
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType
: List.class;
Collection<Object> items = targetType.getType().isArray() ? new ArrayList<>(
sourceValue.size()) : CollectionFactory.createCollection(collectionType,
rawComponentType, sourceValue.size());
if (sourceValue.isEmpty()) {
return getPotentiallyConvertedSimpleRead(items, collectionType);
}
for (Object obj : sourceValue) {
if (obj instanceof Map) {
items.add(read(componentType, (Map) obj));
}
else if (obj instanceof List) {
items.add(readCollectionOrArray(ClassTypeInformation.OBJECT, (List) obj));
}
else {
items.add(getPotentiallyConvertedSimpleRead(obj, rawComponentType));
}
}
return getPotentiallyConvertedSimpleRead(items, targetType.getType());
}
示例5: writeCollectionInternal
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Populates the given {@link List} with values from the given {@link Collection}.
*
* @param source the collection to create a {@link List} for, must not be
* {@literal null}.
* @param type the {@link TypeInformation} to consider or {@literal null} if unknown.
* @param sink the {@link List} to write to.
* @return
*/
private List<Object> writeCollectionInternal(Collection<?> source,
@Nullable TypeInformation<?> type, List<Object> sink) {
TypeInformation<?> componentType = null;
if (type != null) {
componentType = type.getComponentType();
}
for (Object element : source) {
Class<?> elementType = element == null ? null : element.getClass();
if (elementType == null || conversions.isSimpleType(elementType)) {
sink.add(getPotentiallyConvertedSimpleWrite(element));
}
else if (element instanceof Collection || elementType.isArray()) {
sink.add(writeCollectionInternal(asCollection(element), componentType,
new ArrayList<>()));
}
else {
SecretDocumentAccessor accessor = new SecretDocumentAccessor(
new SecretDocument());
writeInternal(element, accessor, componentType);
sink.add(accessor.getBody());
}
}
return sink;
}
示例6: readMap
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Recursively parses the a map from the source document.
*
* @param type the type information for the document.
* @param source the source document.
* @param parent the optional parent.
* @return the recursively parsed map.
*/
protected Map<Object, Object> readMap(final TypeInformation<?> type, final CrateDocument source, final Object parent) {
notNull(source);
Class<?> mapType = typeMapper.readType(source, type).getType();
Map<Object, Object> map = createMap(mapType, source.keySet().size());
for(Map.Entry<String, Object> entry : source.entrySet()) {
Object key = entry.getKey();
Object value = entry.getValue();
TypeInformation<?> keyTypeInformation = type.getComponentType();
if(keyTypeInformation != null) {
Class<?> keyType = keyTypeInformation.getType();
key = conversionService.convert(key, keyType);
}
TypeInformation<?> valueType = type.getMapValueType();
if(value instanceof CrateDocument) {
map.put(key, read(valueType, (CrateDocument) value, parent));
}else if(value instanceof CrateArray) {
map.put(key, readCollection(valueType, (CrateArray) value, parent));
}else {
Class<?> valueClass = valueType == null ? null : valueType.getType();
map.put(key, getPotentiallyConvertedSimpleRead(value, valueClass));
}
}
return map;
}
示例7: readCollection
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Read a collection from the source object.
*
* @param targetType the target type.
* @param source the list as source.
* @param parent the optional parent.
* @return the converted {@link Collection} or array, will never be {@literal null}.
*/
private Object readCollection(final TypeInformation<?> targetType, final CrateArray source, final Object parent) {
notNull(targetType);
Class<?> collectionType = targetType.getType();
if(source.isEmpty()) {
return getPotentiallyConvertedSimpleRead(new HashSet<Object>(), collectionType);
}
collectionType = Collection.class.isAssignableFrom(collectionType) ? collectionType : List.class;
Collection<Object> items = targetType.getType().isArray() ? new ArrayList<Object>(source.size()) :
createCollection(collectionType, source.size());
TypeInformation<?> componentType = targetType.getComponentType();
Class<?> rawComponentType = componentType == null ? null : componentType.getType();
for(Object object : source) {
if(object instanceof CrateDocument) {
items.add(read(componentType, (CrateDocument) object, parent));
}else {
items.add(getPotentiallyConvertedSimpleRead(object, rawComponentType));
}
}
return getPotentiallyConvertedSimpleRead(items, targetType.getType());
}
示例8: readMap
import org.springframework.data.util.TypeInformation; //导入方法依赖的package包/类
/**
* Reads the given {@link Map} into a {@link Map}. will recursively resolve nested
* {@link Map}s as well.
*
* @param type the {@link Map} {@link TypeInformation} to be used to unmarshall this
* {@link Map}.
* @param sourceMap must not be {@literal null}
* @return
*/
@SuppressWarnings("unchecked")
protected Map<Object, Object> readMap(TypeInformation<?> type,
Map<String, Object> sourceMap) {
Assert.notNull(sourceMap, "Source map must not be null!");
Class<?> mapType = typeMapper.readType(sourceMap, type).getType();
TypeInformation<?> keyType = type.getComponentType();
TypeInformation<?> valueType = type.getMapValueType();
Class<?> rawKeyType = keyType != null ? keyType.getType() : null;
Class<?> rawValueType = valueType != null ? valueType.getType() : null;
Map<Object, Object> map = CollectionFactory.createMap(mapType, rawKeyType,
sourceMap.keySet().size());
for (Entry<String, Object> entry : sourceMap.entrySet()) {
if (typeMapper.isTypeKey(entry.getKey())) {
continue;
}
Object key = entry.getKey();
if (rawKeyType != null && !rawKeyType.isAssignableFrom(key.getClass())) {
key = conversionService.convert(key, rawKeyType);
}
Object value = entry.getValue();
TypeInformation<?> defaultedValueType = valueType != null ? valueType
: ClassTypeInformation.OBJECT;
if (value instanceof Map) {
map.put(key, read(defaultedValueType, (Map) value));
}
else if (value instanceof List) {
map.put(key,
readCollectionOrArray(valueType != null ? valueType
: ClassTypeInformation.LIST, (List) value));
}
else {
map.put(key, getPotentiallyConvertedSimpleRead(value, rawValueType));
}
}
return map;
}