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


Java TypeUtils.parameterize方法代码示例

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


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

示例1: downGradeType

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
 * If the requested type is not registered within the class hierarchy it may still be persistable if a superclass is
 * registered. But then we need to find the type that is in the set of registered types.
 *
 * @param type
 * @param classHierarchyNodeForType
 * @return
 */
private Type downGradeType(Type type, ClassHierarchyNode classHierarchyNodeForType) {
    if (classHierarchyNodeForType == null) {
        return type;
    }
    Class<?> clazz = classHierarchyNodeForType.getClazz();

    // if the type is directly assignable, we can simply return the type

    if (TypeUtils.isAssignable(clazz, type)) {
        return type;
    }

    // now we need to downgrade type to clazz
    if (clazz.getTypeParameters().length > 0) {
        //if clazz has type parameters, we need to figure out the correct types
        // TODO encoding with specific type arguments may work, but decoding into
        // TODO the type (that is within the group of registered classes) would loose information, so maybe
        // we should not try to infer the type arguments?
        return TypeUtils.parameterize(clazz, TypeUtils.getTypeArguments(type, clazz));
    } else {
        return clazz;
    }
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:32,代码来源:TypesModel.java

示例2: registerAggregateFactories

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> void registerAggregateFactories(
		final RegistrableAggregateSnaphotter snapshotter) {
	Set<Annotation> qualifiers = ImmutableSet.copyOf(getQualifiers());
	for (AggregateRootInfo aggregateRoot : aggregateRootsInfo) {
		if (aggregateRoot.matchQualifiers(QualifierType.SNAPSHOTTER, qualifiers)) {
			Set<Annotation> factoryQualifiers = aggregateRoot
					.getQualifiers(QualifierType.REPOSITORY);
			Type type = TypeUtils.parameterize(EventSourcingRepository.class,
					aggregateRoot.getType());
			EventSourcingRepository<T> repository = (EventSourcingRepository<T>) CdiUtils
					.getReference(getBeanManager(), type, factoryQualifiers);
			if (repository != null) {
				snapshotter.registerAggregateFactory(repository.getAggregateFactory());
			}
			new EventCountSnapshotTriggerDefinition(snapshotter, 10);
		}
	}
}
 
开发者ID:kamaladafrica,项目名称:axon-cdi,代码行数:20,代码来源:AutoConfiguringAggregateSnapshotterProducer.java

示例3: registerRepositories

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked" })
protected <T> void registerRepositories(X commandBus) {
	final Set<Annotation> qualifiers = ImmutableSet.copyOf(getQualifiers());
	for (AggregateRootInfo aggregateRootInfo : aggregateRootsInfo) {
		if (aggregateRootInfo.matchQualifiers(QualifierType.COMMAND_BUS, qualifiers)) {
			Class<T> aggregateType = (Class<T>) aggregateRootInfo.getType();
			ParameterizedType repositoryType = TypeUtils.parameterize(EventSourcingRepository.class,
					aggregateType);
			EventSourcingRepository<T> repository = (EventSourcingRepository<T>) CdiUtils.getReference(
					getBeanManager(), repositoryType, aggregateRootInfo.getQualifiers(QualifierType.REPOSITORY));
			AggregateAnnotationCommandHandler<?> aggregateAnnotationCommandHandler = new AggregateAnnotationCommandHandler<>(aggregateType,
					repository);
			aggregateAnnotationCommandHandler.subscribe(commandBus);
			if (commandBus instanceof DisruptorCommandBus) {
				((DisruptorCommandBus) commandBus).createRepository(repository.getAggregateFactory());
			}
		}
	}
}
 
开发者ID:kamaladafrica,项目名称:axon-cdi,代码行数:20,代码来源:AutoConfiguringCommandBusProducer.java

示例4: isParameterizedType

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
 * Checks that the actual field is parameterized.
 * 
 * @param expectedRawType the expected raw type
 * @param expectedTypeArguments the expected type arguments
 * @return this {@link FieldAssertion} for fluent linking
 */
public FieldAssertion isParameterizedType(final Class<?> expectedRawType,
    final Type... expectedTypeArguments) {
  isNotNull();
  if (!(actual.getGenericType() instanceof ParameterizedType)) {
    failWithMessage("Expected field <%s> to be a parameterized type but it was not", actual);
  }
  final ParameterizedType actualType = (ParameterizedType) actual.getGenericType();
  final ParameterizedType expectedParameterizedType =
      TypeUtils.parameterize(expectedRawType, expectedTypeArguments);
  if (!TypeUtils.equals(actualType, expectedParameterizedType)) {
    failWithMessage("Expected field %s.%s to be of type %s<%s> but it was %s<%s>",
        actual.getType().getName(), actual.getName(), expectedRawType, expectedTypeArguments,
        actualType.getRawType().getTypeName(), actualType.getActualTypeArguments());
  }
  return this;
}
 
开发者ID:lambdamatic,项目名称:lambdamatic-project,代码行数:24,代码来源:FieldAssertion.java

示例5: responseBodyConverter

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations,
                                                        Retrofit retrofit) {
    Type envelopType = TypeUtils.parameterize(ResponseEnvelop.class, type);
    Converter converter = retrofit.nextResponseBodyConverter(CustomConverterFactory.this,
            envelopType, annotations);
    return new ResponseConverter<>(converter);
}
 
开发者ID:beta,项目名称:cloudier,代码行数:9,代码来源:CustomConverterFactory.java

示例6: createRepositoryBean

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private <T> Bean<EventSourcingRepository<T>> createRepositoryBean(
		final BeanManager bm, final AggregateRootInfo aggregateRootInfo) {

	BeanBuilder<T> aggregateRootBean = new BeanBuilder<T>(bm)
			.readFromType((AnnotatedType<T>) aggregateRootInfo.getAnnotatedType(bm));

	ParameterizedType type = TypeUtils.parameterize(EventSourcingRepository.class,
			aggregateRootInfo.getType());

	BeanBuilder<EventSourcingRepository<T>> builder = new BeanBuilder<EventSourcingRepository<T>>(
			bm)
					.beanClass(EventSourcingRepository.class)
					.qualifiers(CdiUtils.normalizedQualifiers(
							aggregateRootInfo.getQualifiers(QualifierType.REPOSITORY)))
					.alternative(aggregateRootBean.isAlternative())
					.nullable(aggregateRootBean.isNullable())
					.types(CdiUtils.typeClosure(type))
					.scope(aggregateRootBean.getScope())
					.stereotypes(aggregateRootBean.getStereotypes())
					.beanLifecycle(
							new RepositoryContextualLifecycle<T, EventSourcingRepository<T>>(bm,
									aggregateRootInfo));

	if (!Strings.isNullOrEmpty(aggregateRootBean.getName())) {
		builder.name(aggregateRootBean.getName() + "Repository");
	}
	return builder.create();
}
 
开发者ID:kamaladafrica,项目名称:axon-cdi,代码行数:30,代码来源:AxonCdiExtension.java

示例7: testGetMap

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
@Test
public void testGetMap() throws Exception {
    Cat simon = new Cat(null, "Simon", "mail", "unknown", "Well loved and now deceased.");
    String id = client.create("animals", "cat", simon);

    Type type = TypeUtils.parameterize(Map.class, String.class, Object.class);
    Optional<Map<String, Object>> retrieved = client.get("animals", "cat", id, type);
    assertTrue(retrieved.isPresent());
    assertEquals("unknown", retrieved.get().get("breed"));
}
 
开发者ID:Attensadev,项目名称:rubberband,代码行数:11,代码来源:GeneralizedTypesTest.java

示例8: from

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
private static ParameterizedType from(TypeInfo typeInfo) {
  Type[] typeArguments = new Type[0];
  if (typeInfo.typeInfo != null) {
    typeArguments = new Type[]{from(typeInfo.typeInfo)};
  } else if (typeInfo.typeArgs != null) {
    typeArguments = typeInfo.typeArgs;
  }
  return TypeUtils.parameterize(typeInfo.rawType, typeArguments);
}
 
开发者ID:secucard,项目名称:secucard-connect-java-sdk,代码行数:10,代码来源:DynamicTypeReference.java

示例9: readJson

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
private void readJson(JsonObject obj, boolean pm) {
    for (Entry<String, JsonElement> entry : obj.entrySet()) {
        Channel chan = getChannel(entry.getKey(), pm);
        Type type = TypeUtils.parameterize(List.class, ChatMessage.class);
        List<Message> list = gson.fromJson(entry.getValue(), type);
        chan.getMessages().addAll(list);
    }
}
 
开发者ID:killjoy1221,项目名称:TabbyChat-2,代码行数:9,代码来源:ChatManager.java

示例10: getMatchingType

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
/**
 * @param parameterizedType the type to match to
 * @param clazz             the class for which the correct parametrization is to be found
 * @return the parameterized type of clazz or null if no match
 */
private Type getMatchingType(ParameterizedType parameterizedType, Class<?> clazz) {
    Type matchingType = null;
    if (parameterizedType.getRawType().equals(clazz)) {
        matchingType = parameterizedType;
    } else {
        // first find the superclass...may be an interface though
        Type genericSuperclass = null;
        if (ReflectionHelper.extractRawClass(parameterizedType).isInterface()) {
            for (Type genericInterface : clazz.getGenericInterfaces()) {
                if (TypeUtils.isAssignable(genericInterface, parameterizedType)) {
                    genericSuperclass = genericInterface;
                    break;
                }
            }
        } else {
            genericSuperclass = clazz.getGenericSuperclass();
        }


        if (genericSuperclass instanceof ParameterizedType) {
            ParameterizedType parameterizedSuperClassType = (ParameterizedType) genericSuperclass;

            Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
            Type[] superClassTypeArguments = parameterizedSuperClassType.getActualTypeArguments();
            Map<String, Type> parameter = new HashMap<>();
            for (int i = 0; i < superClassTypeArguments.length; i++) {
                Type classTypeArgument = superClassTypeArguments[i];
                if (classTypeArgument instanceof TypeVariable) {
                    if (actualTypeArguments[i] instanceof WildcardType) {
                        WildcardType wildcardType = (WildcardType) actualTypeArguments[i];
                        parameter.put(((TypeVariable) classTypeArgument).getName(), wildcardType.getUpperBounds()[0]);
                    } else {
                        parameter.put(((TypeVariable) classTypeArgument).getName(), actualTypeArguments[i]);
                    }
                }
            }

            TypeVariable<? extends Class<?>>[] typeParameters = clazz.getTypeParameters();
            Type[] specifiedTypeArguments = new Type[typeParameters.length];
            for (int i = 0; i < typeParameters.length; i++) {
                Type inferredType = inferRealType(typeParameters[i], parameter);

                if (TypeUtils.isAssignable(inferredType, typeParameters[i].getBounds()[0])) {
                    specifiedTypeArguments[i] = inferredType;
                } else {
                    return null;
                }
            }

            if (specifiedTypeArguments.length > 0) {
                matchingType = TypeUtils.parameterize(clazz, specifiedTypeArguments);
            } else {
                matchingType = clazz;
            }
        } else {
            LOGGER.debug("Type {} will be ignored as it has no generic superclass, but should have.", clazz);
        }
    }
    return matchingType;
}
 
开发者ID:axelspringer,项目名称:polymorphia,代码行数:66,代码来源:TypesModel.java

示例11: DynamicTypeReference

import org.apache.commons.lang3.reflect.TypeUtils; //导入方法依赖的package包/类
public DynamicTypeReference(Class type, Type... types) {
  this.type = TypeUtils.parameterize(type, types);
}
 
开发者ID:secucard,项目名称:secucard-connect-java-sdk,代码行数:4,代码来源:DynamicTypeReference.java


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