• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConvertiblePair类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: register

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Registers the given {@link ConvertiblePair} as reading or writing pair depending on the type sides being basic
 * Redis types.
 *
 * @param converterRegistration
 */
private void register(ConverterRegistration converterRegistration) {

    ConvertiblePair pair = converterRegistration.getConvertiblePair();

    if (converterRegistration.isReading()) {

        readingPairs.add(pair);

        if (LOG.isWarnEnabled() && !converterRegistration.isSimpleSourceType()) {
            LOG.warn(String.format(READ_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType()));
        }
    }

    if (converterRegistration.isWriting()) {

        writingPairs.add(pair);
        customSimpleTypes.add(pair.getSourceType());

        if (LOG.isWarnEnabled() && !converterRegistration.isSimpleTargetType()) {
            LOG.warn(String.format(WRITE_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType()));
        }
    }
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:30,代码来源:CustomConversions.java


示例2: getCustomWriteTarget

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Returns the target type we can readTargetWriteLocl an inject of the given source type to. The returned type might
 * be a subclass of the given expected type though. If {@code expectedTargetType} is {@literal null} we will simply
 * return the first target type matching or {@literal null} if no conversion can be found.
 *
 * @param sourceType          must not be {@literal null}
 * @param requestedTargetType
 * @return
 */
public Class<?> getCustomWriteTarget(final Class<?> sourceType, final Class<?> requestedTargetType) {

    if (requestedTargetType == null) {
        return getCustomWriteTarget(sourceType);
    }

    return getOrCreateAndCache(new ConvertiblePair(sourceType, requestedTargetType), customWriteTargetTypes,
            new Producer() {

                @Override
                public Class<?> get() {
                    return getCustomTarget(sourceType, requestedTargetType, writingPairs);
                }
            });
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:25,代码来源:CustomConversions.java


示例3: getCustomReadTarget

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Returns the actual target type for the given {@code sourceType} and {@code requestedTargetType}. Note that the
 * returned {@link Class} could be an assignable type to the given {@code requestedTargetType}.
 *
 * @param sourceType          must not be {@literal null}.
 * @param requestedTargetType can be {@literal null}.
 * @return
 */
private Class<?> getCustomReadTarget(final Class<?> sourceType, final Class<?> requestedTargetType) {

    if (requestedTargetType == null) {
        return null;
    }

    return getOrCreateAndCache(new ConvertiblePair(sourceType, requestedTargetType), customReadTargetTypes,
            new Producer() {

                @Override
                public Class<?> get() {
                    return getCustomTarget(sourceType, requestedTargetType, readingPairs);
                }
            });
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:24,代码来源:CustomConversions.java


示例4: getCustomTarget

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Inspects the given {@link ConvertiblePair}s for ones that have a source compatible type as source. Additionally
 * checks assignability of the target type if one is given.
 *
 * @param sourceType          must not be {@literal null}.
 * @param requestedTargetType can be {@literal null}.
 * @param pairs               must not be {@literal null}.
 * @return
 */
private static Class<?> getCustomTarget(Class<?> sourceType, Class<?> requestedTargetType,
                                        Collection<ConvertiblePair> pairs) {

    Assert.notNull(sourceType);
    Assert.notNull(pairs);

    if (requestedTargetType != null && pairs.contains(new ConvertiblePair(sourceType, requestedTargetType))) {
        return requestedTargetType;
    }

    for (ConvertiblePair typePair : pairs) {
        if (typePair.getSourceType().isAssignableFrom(sourceType)) {
            Class<?> targetType = typePair.getTargetType();
            if (requestedTargetType == null || targetType.isAssignableFrom(requestedTargetType)) {
                return targetType;
            }
        }
    }

    return null;
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:31,代码来源:CustomConversions.java


示例5: find

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Find a {@link GenericConverter} given a source and target type.
 * <p>This method will attempt to match all possible converters by working
 * through the class and interface hierarchy of the types.
 * @param sourceType the source type
 * @param targetType the target type
 * @return a matching {@link GenericConverter}, or {@code null} if none found
 */
public GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetType) {
	// Search the full type hierarchy
	List<Class<?>> sourceCandidates = getClassHierarchy(sourceType.getType());
	List<Class<?>> targetCandidates = getClassHierarchy(targetType.getType());
	for (Class<?> sourceCandidate : sourceCandidates) {
		for (Class<?> targetCandidate : targetCandidates) {
			ConvertiblePair convertiblePair = new ConvertiblePair(sourceCandidate, targetCandidate);
			GenericConverter converter = getRegisteredConverter(sourceType, targetType, convertiblePair);
			if (converter != null) {
				return converter;
			}
		}
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:GenericConversionService.java


示例6: getRegisteredConverter

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalConverters for a dynamic match
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter) globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:GenericConversionService.java


示例7: CustomConversions

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Create new instance registering given converters
 *
 * @param converters
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public CustomConversions(List converters) {
	this.converters = (converters != null ? new ArrayList<Object>(converters) : new ArrayList<Object>());
	this.readingPairs = new HashSet<ConvertiblePair>();
	this.writingPairs = new HashSet<ConvertiblePair>();
	this.customSimpleTypes = new HashSet<Class<?>>();

	this.simpleTypeHolder = new SimpleTypeHolder(customSimpleTypes, SolrSimpleTypes.HOLDER);

	this.converters.add(GeoConverters.StringToPointConverter.INSTANCE);
	this.converters.add(GeoConverters.Point3DToStringConverter.INSTANCE);
	this.converters.add(new SolrjConverters.UpdateToSolrInputDocumentConverter());

	// Register Joda-Time converters only if Joda-Time was found in the classpath.
	if (VersionUtil.isJodaTimeAvailable()) {
		this.converters.add(DateTimeConverters.DateToJodaDateTimeConverter.INSTANCE);
		this.converters.add(DateTimeConverters.JodaDateTimeToDateConverter.INSTANCE);
		this.converters.add(DateTimeConverters.DateToLocalDateTimeConverter.INSTANCE);
		this.converters.add(DateTimeConverters.JodaLocalDateTimeToDateConverter.INSTANCE);
	}

	for (Object converter : this.converters) {
		registerConversion(converter);
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:31,代码来源:CustomConversions.java


示例8: getCustomTarget

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
Class<?> getCustomTarget(Class<?> sourceType, Class<?> expectedTargetType, Iterable<ConvertiblePair> pairs) {
	Assert.notNull(sourceType);
	Assert.notNull(pairs);

	ConvertiblePair expectedTypePair = new ConvertiblePair(sourceType, expectedTargetType != null ? expectedTargetType
			: Any.class);

	if (cache.containsKey(expectedTypePair)) {
		Class<?> cachedTargetType = cache.get(expectedTypePair);
		return cachedTargetType != Any.class ? cachedTargetType : null;
	}

	for (ConvertiblePair typePair : pairs) {
		if (typePair.getSourceType().isAssignableFrom(sourceType)) {
			Class<?> targetType = typePair.getTargetType();
			if (expectedTargetType == null || targetType.isAssignableFrom(expectedTargetType)) {
				cache.putIfAbsent(expectedTypePair, targetType);
				return targetType;
			}
		}
	}

	cache.putIfAbsent(expectedTypePair, Any.class);
	return null;
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:26,代码来源:CustomConversions.java


示例9: registerConversion

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
private void registerConversion(Object converter) {
	Class<?> type = converter.getClass();
	boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
	boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

	if (!isReading && !isWriting) {
		isReading = true;
		isWriting = true;
	}

	if (converter instanceof GenericConverter) {
		GenericConverter genericConverter = (GenericConverter) converter;
		for (ConvertiblePair pair : genericConverter.getConvertibleTypes()) {
			register(new ConvertibleContext(pair, isReading, isWriting));
		}
	} else if (converter instanceof Converter) {
		Class<?>[] arguments = GenericTypeResolver.resolveTypeArguments(converter.getClass(), Converter.class);
		register(new ConvertibleContext(arguments[0], arguments[1], isReading, isWriting));
	} else {
		throw new IllegalArgumentException("Unsupported Converter type! Expected either GenericConverter if Converter.");
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:23,代码来源:CustomConversions.java


示例10: getRegisteredConverter

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
private GenericConverter getRegisteredConverter(TypeDescriptor sourceType,
		TypeDescriptor targetType, ConvertiblePair convertiblePair) {

	// Check specifically registered converters
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair != null) {
		GenericConverter converter = convertersForPair.getConverter(sourceType, targetType);
		if (converter != null) {
			return converter;
		}
	}
	// Check ConditionalGenericConverter that match all types
	for (GenericConverter globalConverter : this.globalConverters) {
		if (((ConditionalConverter)globalConverter).matches(sourceType, targetType)) {
			return globalConverter;
		}
	}
	return null;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:GenericConversionService.java


示例11: CustomConversions

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Creates a new {@link CustomConversions} instance registering the given converters.
 *
 * @param converters
 */
public CustomConversions(List<?> converters) {

    Assert.notNull(converters);

    this.readingPairs = new LinkedHashSet<ConvertiblePair>();
    this.writingPairs = new LinkedHashSet<ConvertiblePair>();
    this.customSimpleTypes = new HashSet<Class<?>>();
    this.customReadTargetTypes = new ConcurrentHashMap<ConvertiblePair, CacheValue<Class<?>>>();
    this.customWriteTargetTypes = new ConcurrentHashMap<ConvertiblePair, CacheValue<Class<?>>>();
    this.rawWriteTargetTypes = new ConcurrentHashMap<Class<?>, CacheValue<Class<?>>>();

    List<Object> toRegister = new ArrayList<Object>();

    // Add user provided converters to make sure they can override the defaults
    toRegister.addAll(converters);

    toRegister.add(new BinaryConverters.EnumToStringConverter());
    toRegister.add(new BinaryConverters.StringToEnumConverterFactory());
    toRegister.add(new BinaryConverters.DateToNumberConverter());
    toRegister.add(new BinaryConverters.NumberToDateConverter());

    for (Object c : toRegister) {
        registerConversion(c);
    }

    Collections.reverse(toRegister);

    this.converters = Collections.unmodifiableList(toRegister);
    this.simpleTypeHolder = new SimpleTypeHolder(customSimpleTypes, true);
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:36,代码来源:CustomConversions.java


示例12: ConverterRegistration

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Creates a new {@link ConverterRegistration}.
 *
 * @param convertiblePair  must not be {@literal null}.
 * @param isReading        whether to force to consider the converter for reading.
 * @param isWriting        whether to force to consider the converter for reading.
 */
public ConverterRegistration(ConvertiblePair convertiblePair, boolean isReading, boolean isWriting) {

    Assert.notNull(convertiblePair);

    this.convertiblePair = convertiblePair;
    this.reading = isReading;
    this.writing = isWriting;
}
 
开发者ID:saladinkzn,项目名称:spring-data-tarantool,代码行数:16,代码来源:CustomConversions.java


示例13: addConverterFactory

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
@Override
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
	ResolvableType[] typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
	Assert.notNull(typeInfo, "Unable to the determine source type <S> and target range type R which your " +
			"ConverterFactory<S, R> converts between; declare these generic types.");
	addConverter(new ConverterFactoryAdapter(converterFactory,
			new ConvertiblePair(typeInfo[0].resolve(), typeInfo[1].resolve())));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:GenericConversionService.java


示例14: add

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
public void add(GenericConverter converter) {
	Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
	if (convertibleTypes == null) {
		Assert.state(converter instanceof ConditionalConverter,
				"Only conditional converters may return null convertible types");
		this.globalConverters.add(converter);
	}
	else {
		for (ConvertiblePair convertiblePair : convertibleTypes) {
			ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
			convertersForPair.add(converter);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:GenericConversionService.java


示例15: getMatchableConverters

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
private ConvertersForPair getMatchableConverters(ConvertiblePair convertiblePair) {
	ConvertersForPair convertersForPair = this.converters.get(convertiblePair);
	if (convertersForPair == null) {
		convertersForPair = new ConvertersForPair();
		this.converters.put(convertiblePair, convertersForPair);
	}
	return convertersForPair;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:GenericConversionService.java


示例16: testGetConvertibleTypes

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Test method for {@link io.springlets.format.EntityToStringConverter#getConvertibleTypes()}.
 */
@Test
public void testGetConvertibleTypes() {
  // Prepare

  // Exercise
  Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();

  // Validate
  assertThat(convertibleTypes).isNotEmpty()
      .containsExactly(new ConvertiblePair(Object.class, String.class));
}
 
开发者ID:DISID,项目名称:springlets,代码行数:15,代码来源:EntityToStringConverterTest.java


示例17: checkValidConvertibleTypes

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
@Test
public void checkValidConvertibleTypes() {
  // Prepare

  // Exercise
  Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();

  // Validate
  assertThat(convertibleTypes).isNotEmpty()
      .containsExactly(new ConvertiblePair(Enum.class, String.class));
}
 
开发者ID:DISID,项目名称:springlets,代码行数:12,代码来源:EnumToMessageConverterTest.java


示例18: register

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
private void register(ConvertibleContext context) {
	ConvertiblePair pair = context.getConvertible();
	if (context.isReading()) {
		readingPairs.add(pair);
	}
	if (context.isWriting()) {
		writingPairs.add(pair);
		customSimpleTypes.add(pair.getSourceType());
	}
}
 
开发者ID:yiduwangkai,项目名称:dubbox-solr,代码行数:11,代码来源:CustomConversions.java


示例19: ConverterRegistration

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
/**
 * Creates a new {@link ConverterRegistration}.
 *
 * @param convertiblePair must not be {@literal null}.
 * @param isReading whether to force to consider the converter for reading.
 * @param isWriting whether to force to consider the converter for reading.
 */
public ConverterRegistration(ConvertiblePair convertiblePair, boolean isReading, boolean isWriting) {
  notNull(convertiblePair, "Convertible Pair is required");

  this.convertiblePair = convertiblePair;
  reading = isReading;
  writing = isWriting;
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:15,代码来源:ConverterRegistration.java


示例20: addConverterFactory

import org.springframework.core.convert.converter.GenericConverter.ConvertiblePair; //导入依赖的package包/类
public void addConverterFactory(ConverterFactory<?, ?> converterFactory) {
	GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converterFactory, ConverterFactory.class);
	if (typeInfo == null) {
		throw new IllegalArgumentException("Unable to the determine sourceType <S> and " +
				"targetRangeType R which your ConverterFactory<S, R> converts between; " +
				"declare these generic types.");
	}
	addConverter(new ConverterFactoryAdapter(converterFactory, typeInfo));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:10,代码来源:GenericConversionService.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java WrappedRuntimeException类代码示例发布时间:2022-05-23
下一篇:
Java AfterMatchFiredEvent类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap