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


Java GenericConverter.ConvertiblePair方法代码示例

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


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

示例1: registerConversion

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
/**
 * Registers a conversion for the given converter. Inspects either generics or the convertible pairs returned
 * by a {@link GenericConverter}.
 *
 * @param converter the converter to register.
 */
private void registerConversion(final Object converter) {
  Class<?> type = converter.getClass();
  boolean isWriting = type.isAnnotationPresent(WritingConverter.class);
  boolean isReading = type.isAnnotationPresent(ReadingConverter.class);

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

示例2: register

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

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

  if (registration.isWriting()) {
    writingPairs.add(pair);
    customSimpleTypes.add(pair.getSourceType());
    if (LOG.isWarnEnabled() && !registration.isSimpleTargetType()) {
      LOG.warn(String.format(WRITE_CONVERTER_NOT_SIMPLE, pair.getSourceType(), pair.getTargetType()));
    }
  }
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:25,代码来源:CustomConversions.java

示例3: getCustomReadTarget

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的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(Class<?> sourceType, Class<?> requestedTargetType) {
  notNull(sourceType);
  if (requestedTargetType == null) {
    return null;
  }

  GenericConverter.ConvertiblePair lookupKey = new GenericConverter.ConvertiblePair(sourceType, requestedTargetType);
  CacheValue readTargetTypeValue = customReadTargetTypes.get(lookupKey);

  if (readTargetTypeValue != null) {
    return readTargetTypeValue.getType();
  }

  readTargetTypeValue = CacheValue.of(getCustomTarget(sourceType, requestedTargetType, readingPairs));
  CacheValue cacheValue = customReadTargetTypes.putIfAbsent(lookupKey, readTargetTypeValue);

  return cacheValue != null ? cacheValue.getType() : readTargetTypeValue.getType();
}
 
开发者ID:KPTechnologyLab,项目名称:spring-data-crate,代码行数:27,代码来源:CustomConversions.java

示例4: getCustomTarget

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
/**
 * Inspects the given {@link org.springframework.core.convert.converter.GenericConverter.ConvertiblePair} 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,
  Iterable<GenericConverter.ConvertiblePair> pairs) {
  notNull(sourceType);
  notNull(pairs);

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

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

示例5: testConvertiblePairEqualsAndHash

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
@Test
public void testConvertiblePairEqualsAndHash() {
	GenericConverter.ConvertiblePair pair = new GenericConverter.ConvertiblePair(Number.class, String.class);
	GenericConverter.ConvertiblePair pairEqual = new GenericConverter.ConvertiblePair(Number.class, String.class);
	assertEquals(pair, pairEqual);
	assertEquals(pair.hashCode(), pairEqual.hashCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:GenericConversionServiceTests.java

示例6: testConvertiblePairDifferentEqualsAndHash

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
@Test
public void testConvertiblePairDifferentEqualsAndHash() {
	GenericConverter.ConvertiblePair pair = new GenericConverter.ConvertiblePair(Number.class, String.class);
	GenericConverter.ConvertiblePair pairOpposite = new GenericConverter.ConvertiblePair(String.class, Number.class);
	assertFalse(pair.equals(pairOpposite));
	assertFalse(pair.hashCode() == pairOpposite.hashCode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:GenericConversionServiceTests.java

示例7: listEntities

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
@RequestMapping(value = "/entities", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public List<String> listEntities(){
    List<String> data = new ArrayList<String>();
    Set<GenericConverter.ConvertiblePair> list =  entityConverter.getConvertibleTypes();
    for (GenericConverter.ConvertiblePair element: list){
        if (!Modifier.isAbstract(element.getSourceType().getModifiers())){
            data.add(element.getSourceType().getCanonicalName());
        }
    }
    return data;
}
 
开发者ID:Appverse,项目名称:appverse-server,代码行数:12,代码来源:SchemaGeneratorServiceImpl.java

示例8: addConverterFactory

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的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

示例9: addConverter

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
public void addConverter(Converter<?, ?> converter) {
	GenericConverter.ConvertiblePair typeInfo = getRequiredTypeInfo(converter, Converter.class);
	Assert.notNull(typeInfo, "Unable to the determine sourceType <S> and targetType " +
			"<T> which your Converter<S, T> converts between; declare these generic types.");
	addConverter(new ConverterAdapter(converter, typeInfo));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:7,代码来源:GenericConversionService.java

示例10: getRequiredTypeInfo

import org.springframework.core.convert.converter.GenericConverter; //导入方法依赖的package包/类
private GenericConverter.ConvertiblePair getRequiredTypeInfo(Object converter, Class<?> genericIfc) {
	Class<?>[] args = GenericTypeResolver.resolveTypeArguments(converter.getClass(), genericIfc);
	return (args != null ? new GenericConverter.ConvertiblePair(args[0], args[1]) : null);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:5,代码来源:GenericConversionService.java


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