当前位置: 首页>>代码示例>>Java>>正文


Java CollectionFactory类代码示例

本文整理汇总了Java中org.springframework.core.CollectionFactory的典型用法代码示例。如果您正苦于以下问题:Java CollectionFactory类的具体用法?Java CollectionFactory怎么用?Java CollectionFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CollectionFactory类属于org.springframework.core包,在下文中一共展示了CollectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: convert

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	if (source == null) {
		return null;
	}

	TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
	Collection<Object> target = CollectionFactory.createCollection(targetType.getType(),
			(elementDesc != null ? elementDesc.getType() : null), 1);

	if (elementDesc == null || elementDesc.isCollection()) {
		target.add(source);
	}
	else {
		Object singleElement = this.conversionService.convert(source, sourceType, elementDesc);
		target.add(singleElement);
	}
	return target;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ObjectToCollectionConverter.java

示例2: populateInverseRelationship

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
/**
 * Populates the property on the other side of the relationship.
 *
 * @param relationship the relationship on the wrapped data object for which to populate the inverse relationship.
 * @param propertyValue the value of the property.
 */
protected void populateInverseRelationship(MetadataChild relationship, Object propertyValue) {
    if (propertyValue != null) {
        MetadataChild inverseRelationship = relationship.getInverseRelationship();
        if (inverseRelationship != null) {
            DataObjectWrapper<?> wrappedRelationship = dataObjectService.wrap(propertyValue);
            if (inverseRelationship instanceof DataObjectCollection) {
                DataObjectCollection collectionRelationship = (DataObjectCollection)inverseRelationship;
                String colRelName = inverseRelationship.getName();
                Collection<Object> collection =
                        (Collection<Object>)wrappedRelationship.getPropertyValue(colRelName);
                if (collection == null) {
                    // if the collection is null, let's instantiate an empty one
                    collection =
                            CollectionFactory.createCollection(wrappedRelationship.getPropertyType(colRelName), 1);
                    wrappedRelationship.setPropertyValue(colRelName, collection);
                }
                collection.add(getWrappedInstance());
            }
        }
    }
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:28,代码来源:DataObjectWrapperBase.java

示例3: readCollectionOfComplexTypes

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
/**
 * @param path
 * @param collectionType
 * @param valueType
 * @param source
 * @return
 */
private Collection<?> readCollectionOfComplexTypes(String path, Class<?> collectionType, Class<?> valueType,
		RedisData source) {

	Collection<Object> target = CollectionFactory.createCollection(collectionType, valueType, 10);

	Set<byte[]> values = getKeysStartingWith(toBytes(path + ".["), source);

	for (byte[] value : values) {

		RedisData newPartialSource = new RedisData(extractDataStartingWith(value, source));

		byte[] typeInfo = source.getDataForKey(ByteUtils.concat(value, toBytes("._class")));
		if (typeInfo != null && typeInfo.length > 0) {
			newPartialSource.addDataEntry(toBytes("_class"), typeInfo);
		}

		Object o = readInternal(fromBytes(value, String.class), valueType, newPartialSource);
		target.add(o);
	}
	return target;
}
 
开发者ID:christophstrobl,项目名称:spring-data-keyvalue-redis,代码行数:29,代码来源:MappingRedisConverter.java

示例4: readMapOfSimpleTypes

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
/**
 * @param path
 * @param mapType
 * @param keyType
 * @param valueType
 * @param source
 * @return
 */
private Map<?, ?> readMapOfSimpleTypes(String path, Class<?> mapType, Class<?> keyType, Class<?> valueType,
		RedisData source) {

	Map<Object, Object> target = CollectionFactory.createMap(mapType, 10);

	byte[] prefix = toBytes(path + ".[");
	byte[] postfix = toBytes("]");

	Map<byte[], byte[]> values = extractDataStartingWith(toBytes(path + ".["), source);
	for (Entry<byte[], byte[]> entry : values.entrySet()) {

		byte[] binKey = ByteUtils.extract(entry.getKey(), prefix, postfix);

		Object key = fromBytes(binKey, keyType);
		target.put(key, fromBytes(entry.getValue(), valueType));
	}
	return target;
}
 
开发者ID:christophstrobl,项目名称:spring-data-keyvalue-redis,代码行数:27,代码来源:MappingRedisConverter.java

示例5: readCollection

import org.springframework.core.CollectionFactory; //导入依赖的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;
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:27,代码来源:MappingSolrConverter.java

示例6: readCollection

import org.springframework.core.CollectionFactory; //导入依赖的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;
}
 
开发者ID:ramaava,项目名称:spring-data-solr,代码行数:22,代码来源:MappingSolrConverter.java

示例7: readCollectionOrArray

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
private Object readCollectionOrArray(Path path, Class<?> collectionType, Class<?> valueType, Tuple tuple) {
        List<Path> keys = new ArrayList<>(tuple.extractAllKeysFor(path));

        boolean isArray = collectionType.isArray();
        Class<?> collectionTypeToUse = isArray ? ArrayList.class : collectionType;
        Collection<Object> target = CollectionFactory.createCollection(collectionTypeToUse, valueType, keys.size());

        for (Path key : keys) {

//            if (key.endsWith(TYPE_HINT_ALIAS)) {
//                continue;
//            }
//
            Tuple elementData = tuple.extract(key);

//            byte[] typeInfo = elementData.get(key + "." + TYPE_HINT_ALIAS);
//            if (typeInfo != null && typeInfo.length > 0) {
//                elementData.put(TYPE_HINT_ALIAS, typeInfo);
//            }

            Class<?> typeToUse = getTypeHint(key, tuple, valueType);
            if (isTarantoolNativeType(valueType)) {
                target.add(fromTarantoolNativeType(elementData.get(key), typeToUse));
            } else {
                target.add(readInternal(key, valueType, new TarantoolData(elementData)));
            }
        }

        return isArray ? toArray(target, collectionType, valueType) : target;
    }
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:31,代码来源:MappingTarantoolConverter.java

示例8: convertDataArrayToTargetCollection

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
private Collection<?> convertDataArrayToTargetCollection(Object[] array, Class<?> collectionType, Class<?> elementType)
		throws NoSuchMethodException {

	Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType());
	Collection<Object> resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array));
	for (int i = 0; i < array.length; i++) {
		resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
	}
	return resultColl;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:MBeanClientInterceptor.java

示例9: newValue

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
private Object newValue(Class<?> type, String name) {
	try {
		if (type.isArray()) {
			Class<?> componentType = type.getComponentType();
			// TODO - only handles 2-dimensional arrays
			if (componentType.isArray()) {
				Object array = Array.newInstance(componentType, 1);
				Array.set(array, 0, Array.newInstance(componentType.getComponentType(), 0));
				return array;
			}
			else {
				return Array.newInstance(componentType, 0);
			}
		}
		else if (Collection.class.isAssignableFrom(type)) {
			return CollectionFactory.createCollection(type, 16);
		}
		else if (Map.class.isAssignableFrom(type)) {
			return CollectionFactory.createMap(type, 16);
		}
		else {
			return type.newInstance();
		}
	}
	catch (Exception ex) {
		// TODO Root cause exception context is lost here... should we throw another exception type that preserves context instead?
		throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,
				"Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path: " + ex);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:BeanWrapperImpl.java

示例10: convert

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
	if (source == null) {
		return null;
	}
	Collection<?> sourceCollection = (Collection<?>) source;

	// Shortcut if possible...
	boolean copyRequired = !targetType.getType().isInstance(source);
	if (!copyRequired && sourceCollection.isEmpty()) {
		return source;
	}
	TypeDescriptor elementDesc = targetType.getElementTypeDescriptor();
	if (elementDesc == null && !copyRequired) {
		return source;
	}

	// At this point, we need a collection copy in any case, even if just for finding out about element copies...
	Collection<Object> target = CollectionFactory.createCollection(targetType.getType(),
			(elementDesc != null ? elementDesc.getType() : null), sourceCollection.size());

	if (elementDesc == null) {
		target.addAll(sourceCollection);
	}
	else {
		for (Object sourceElement : sourceCollection) {
			Object targetElement = this.conversionService.convert(sourceElement,
					sourceType.elementTypeDescriptor(sourceElement), elementDesc);
			target.add(targetElement);
			if (sourceElement != targetElement) {
				copyRequired = true;
			}
		}
	}

	return (copyRequired ? target : source);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:CollectionToCollectionConverter.java

示例11: newValue

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
private Object newValue(Class<?> type, TypeDescriptor desc, String name) {
	try {
		if (type.isArray()) {
			Class<?> componentType = type.getComponentType();
			// TODO - only handles 2-dimensional arrays
			if (componentType.isArray()) {
				Object array = Array.newInstance(componentType, 1);
				Array.set(array, 0, Array.newInstance(componentType.getComponentType(), 0));
				return array;
			}
			else {
				return Array.newInstance(componentType, 0);
			}
		}
		else if (Collection.class.isAssignableFrom(type)) {
			TypeDescriptor elementDesc = (desc != null ? desc.getElementTypeDescriptor() : null);
			return CollectionFactory.createCollection(type, (elementDesc != null ? elementDesc.getType() : null), 16);
		}
		else if (Map.class.isAssignableFrom(type)) {
			TypeDescriptor keyDesc = (desc != null ? desc.getMapKeyTypeDescriptor() : null);
			return CollectionFactory.createMap(type, (keyDesc != null ? keyDesc.getType() : null), 16);
		}
		else {
			return BeanUtils.instantiate(type);
		}
	}
	catch (Exception ex) {
		// TODO: Root cause exception context is lost here; just exception message preserved.
		// Should we throw another exception type that preserves context instead?
		throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,
				"Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path: " + ex);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:AbstractNestablePropertyAccessor.java

示例12: readCollectionOrArray

import org.springframework.core.CollectionFactory; //导入依赖的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());
}
 
开发者ID:spring-projects,项目名称:spring-vault,代码行数:46,代码来源:MappingVaultConverter.java

示例13: readCollectionOfSimpleTypes

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
/**
 * @param path
 * @param collectionType
 * @param valueType
 * @param source
 * @return
 */
private Collection<?> readCollectionOfSimpleTypes(String path, Class<?> collectionType, Class<?> valueType,
		RedisData source) {

	Collection<Object> target = CollectionFactory.createCollection(collectionType, valueType, 10);

	Map<byte[], byte[]> values = extractDataStartingWith(toBytes(path + ".["), source);

	for (byte[] value : values.values()) {
		target.add(fromBytes(value, valueType));
	}
	return target;
}
 
开发者ID:christophstrobl,项目名称:spring-data-keyvalue-redis,代码行数:20,代码来源:MappingRedisConverter.java

示例14: readMapOfComplexTypes

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
/**
 * @param path
 * @param mapType
 * @param keyType
 * @param valueType
 * @param source
 * @return
 */
private Map<?, ?> readMapOfComplexTypes(String path, Class<?> mapType, Class<?> keyType, Class<?> valueType,
		RedisData source) {

	Map<Object, Object> target = CollectionFactory.createMap(mapType, 10);

	byte[] prefix = toBytes(path + ".[");
	byte[] postfix = toBytes("]");
	Set<byte[]> keys = getKeysStartingWith(prefix, source);

	for (byte[] fullKey : keys) {

		byte[] binKey = ByteUtils.extract(fullKey, prefix, postfix);

		Object key = fromBytes(binKey, keyType);

		RedisData newPartialSource = new RedisData(extractDataStartingWith(fullKey, source));

		byte[] typeInfo = source.getDataForKey(ByteUtils.concat(fullKey, toBytes("._class")));
		if (typeInfo != null && typeInfo.length > 0) {
			newPartialSource.addDataEntry(toBytes("_class"), typeInfo);
		}

		Object o = readInternal(fromBytes(fullKey, String.class), valueType, newPartialSource);

		target.put(key, o);
	}
	return target;
}
 
开发者ID:christophstrobl,项目名称:spring-data-keyvalue-redis,代码行数:37,代码来源:MappingRedisConverter.java

示例15: convertDataArrayToTargetCollection

import org.springframework.core.CollectionFactory; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Collection convertDataArrayToTargetCollection(Object[] array, Class collectionType, Class elementType)
		throws NoSuchMethodException {

	Method fromMethod = elementType.getMethod("from", array.getClass().getComponentType());
	Collection resultColl = CollectionFactory.createCollection(collectionType, Array.getLength(array));
	for (int i = 0; i < array.length; i++) {
		resultColl.add(ReflectionUtils.invokeMethod(fromMethod, null, array[i]));
	}
	return resultColl;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:12,代码来源:MBeanClientInterceptor.java


注:本文中的org.springframework.core.CollectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。