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

Java TypeResolver类代码示例

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

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



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

示例1: run

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
private void run() {
    Class<?> type = TypeResolver.resolveRawArgument(Predicate.class, filter.getClass());
    Thread thread = new Thread(() -> {
        subscriber = new Object() {
            @EventSubscriber
            public void onEvent(T event) {
                if (type.isInstance(event) && filter.test(event)) {
                    deregisterEventSubscribers(this);
                    result = event;
                    isFinished.set(true);
                }
            }
        };
        registerEventSubscribers(subscriber);
    });
    thread.start();
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:18,代码来源:EventManager.java


示例2: setInterfaceClass

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Extracts information about listClass, listMetaClass, listLinkClass from the provided document
 * interface.
 *
 * @param interfaceClass of the document
 * @return this builder
 */
@SuppressWarnings("unchecked")
public Builder<T> setInterfaceClass(Class<? extends ResourceRepositoryV2<T, ?>> interfaceClass) {

	try {
		Method findMethod = interfaceClass.getDeclaredMethod("findAll", QuerySpec.class);
		Class<?> returnType = findMethod.getReturnType();
		if (!ResourceListBase.class.isAssignableFrom(returnType)) {
			throw new IllegalStateException("findAll return type must extend " + ResourceListBase.class.getName());
		}
		setListClass((Class<? extends DefaultResourceList<T>>) returnType);

		Class<?>[] typeArgs = TypeResolver.resolveRawArguments(ResourceListBase.class, returnType);
		setListMetaClass((Class<? extends MetaInformation>) typeArgs[1]);
		setListLinksClass((Class<? extends LinksInformation>) typeArgs[2]);
		return this;
	} catch (NoSuchMethodException e) {
		throw new IllegalStateException("findAll method not overriden by " + interfaceClass.getName(), e);
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:27,代码来源:JpaRepositoryConfig.java


示例3: setInterfaceClass

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Extracts information about listClass, listMetaClass, listLinkClass from the provided repository
 * interface.
 * 
 * @param interfaceClass of the repository
 * @return this builder
 */
@SuppressWarnings("unchecked")
public Builder<T> setInterfaceClass(Class<? extends ResourceRepositoryV2<T, ?>> interfaceClass) {

	try {
		Method findMethod = interfaceClass.getDeclaredMethod("findAll", QuerySpec.class);
		Class<?> returnType = findMethod.getReturnType();
		if (!ResourceListBase.class.isAssignableFrom(returnType)) {
			throw new IllegalStateException("findAll return type must extend " + ResourceListBase.class.getName());
		}
      setListClass((Class<? extends DefaultResourceList<T>>) returnType);

		Class<?>[] typeArgs = TypeResolver.resolveRawArguments(ResourceListBase.class, returnType);
      setListMetaClass((Class<? extends MetaInformation>) typeArgs[1]);
      setListLinksClass((Class<? extends LinksInformation>) typeArgs[2]);
		return this;
	}
	catch (NoSuchMethodException e) {
		throw new IllegalStateException("findAll method not overriden by " + interfaceClass.getName(), e);
	}
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:28,代码来源:JpaRepositoryConfig.java


示例4: decode

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@Override public <T> T decode(BitBuffer bitbuffer,
    Class<T> classOfT,
    Annotation[] extraAnnotations) {
AnnotationStore annotations = new AnnotationStore(classOfT.getAnnotations(),
        extraAnnotations);
UperEncoder.logger.debug("SEQUENCE OF for {}", classOfT);
FixedSize fixedSize = annotations.getAnnotation(FixedSize.class);
SizeRange sizeRange = annotations.getAnnotation(SizeRange.class);
long size =
  (fixedSize != null) ? fixedSize.value() :
      (sizeRange != null) ? UperEncoder.decodeConstrainedInt(bitbuffer, UperEncoder.intRangeFromSizeRange(sizeRange)) :
          UperEncoder.decodeLengthDeterminant(bitbuffer);
Collection<Object> coll = new ArrayList<Object>((int) size);
for (int i = 0; i < size; i++) {
    Class<?>[] typeArgs = TypeResolver.resolveRawArguments(List.class, classOfT);
    Class<?> classOfElements = typeArgs[0];
    if (classOfElements == Unknown.class) { throw new IllegalArgumentException(
            "Can't resolve type of elements for " + classOfT.getName()); }
    coll.add(UperEncoder.decode2(bitbuffer, classOfElements, new Annotation[] {}));
}
T result = UperEncoder.instantiate(classOfT, coll);
return result;        }
 
开发者ID:alexvoronov,项目名称:geonetworking,代码行数:23,代码来源:SeqOfCoder.java


示例5: onNext

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Asynchronously wait for the specified event, and perform an action.
 *
 * @param filter The filter to specify which event to wait for.
 * @param action The consumer action.
 * @param timeout The timeout in milliseconds. After the timeout, the action will not be performed.
 * @param onTimeout The actions to perform if timeout exceeds.
 * @param <T> The event to filter.
 */
public <T extends Event> void onNext(Predicate<T> filter, Consumer<T> action, long timeout, Runnable onTimeout) {
    Class<?> type = TypeResolver.resolveRawArgument(Predicate.class, filter.getClass());

    /* Event Subscriber */
    Object subscriber = new Object() {
        @EventSubscriber
        public void onEvent(T event) {
            if (type.isInstance(event) && filter.test(event)) {
                action.accept(event);
                // Deregistering Event Subscribers result in ConcurrentModificationException
                // So we use a ConcurrentHashMap
                deregisterEventSubscribers(this);
            }
        }
    };

    /* Run Asynchronously */
    Thread thread = new Thread(() -> {
        registerEventSubscribers(subscriber);
        long time = 0L;
        while (isRegistered(subscriber)) {
            if (time >= timeout && timeout > 0) {
                deregisterEventSubscribers(subscriber);
                if (onTimeout != null) onTimeout.run();
                break;
            }
            try {
                Thread.sleep(20);
            } catch (InterruptedException ignored) {}
            time += 20;
        }
    });
    thread.run();
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:44,代码来源:EventManager.java


示例6: registerListener

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@Override
public <T extends Event> void registerListener(EventKey eventKey, IEventListener<T> eventListener)
{
    Class eventClazz = TypeResolver.resolveRawArgument(IEventListener.class, eventListener.getClass());
    if (!registeredListeners.containsKey(eventClazz))
    {
        registeredListeners.put(eventClazz, new LinkedList<>());
    }
    registeredListeners.get(eventClazz).add(new EventEntity(eventListener, eventKey, eventClazz));
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:11,代码来源:EventManager.java


示例7: getExistingViewModel

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * This method is used to get the ViewModel instance of a given
 * view/codeBehind.
 *
 * @param view
 *            the view instance where the viewModel will be looked for.typetools-0.4.1.jar
 * @param <ViewType>
 *            the generic type of the View
 * @param <ViewModelType>
 *            the generic type of the ViewModel
 * @return the ViewModel instance or null if no viewModel could be found.
 */
@SuppressWarnings("unchecked")
public static <ViewType extends View<? extends ViewModelType>, ViewModelType extends ViewModel> ViewModelType getExistingViewModel(
        ViewType view) {
    final Class<?> viewModelType = TypeResolver.resolveRawArgument(View.class, view.getClass());
    Optional<Field> fieldOptional = getViewModelField(view.getClass(), viewModelType);
    if (fieldOptional.isPresent()) {
        Field field = fieldOptional.get();
        return ReflectionUtils.accessField(field, () -> (ViewModelType) field.get(view),
                "Can't get the viewModel of type <" + viewModelType + ">");
    } else {
        return null;
    }
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:26,代码来源:ViewLoaderReflectionUtils.java


示例8: createAndInjectViewModel

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * This method is used to create and inject the ViewModel for a given View
 * instance.
 * 
 * The following checks are done:
 * <ul>
 * <li>Check whether the View class specifies a ViewModel type as generic
 * type.</li>
 * <li>Check whether the View has a field with a matching ViewModel type and
 * the annotation {@link InjectViewModel}.</li>
 * 
 * <li>Check whether field in the view instance already contains a ViewModel
 * instance. In this case nothing will happen to the existing ViewModel
 * instance.</li>
 * 
 * </ul>
 * 
 * If a suitable field was found a new ViewModel instance will be created
 * and injected into the field. After that the given Consumer function will
 * be applied with the injected ViewModel instance as argument.
 * 
 * @param view
 *            the view instance.
 * @param <V>
 *            the generic type of the View.
 * @param <VM>
 *            the generic type of the ViewModel.
 * @param newVmConsumer
 *            a Consumer function that is applied when a new ViewModel
 *            instance is created.
 * 
 * @throws RuntimeException
 *             if there is a ViewModel field in the View with the
 *             {@link InjectViewModel} annotation whose type doesn't match
 *             the generic ViewModel type from the View class.
 */
public static <V extends View<? extends VM>, VM extends ViewModel> void createAndInjectViewModel(final V view,
        Consumer<ViewModel> newVmConsumer) {
    final Class<?> viewModelType = TypeResolver.resolveRawArgument(View.class, view.getClass());

    if (viewModelType == ViewModel.class) {
        // if no viewModel can be created, we have to check if the user has
        // tried to inject a ViewModel
        final List<Field> viewModelFields = ViewLoaderReflectionUtils.getViewModelFields(view.getClass());

        if (!viewModelFields.isEmpty()) {
            throw new RuntimeException("The given view of type <" + view.getClass()
                    + "> has no generic viewModel type declared but tries to inject a viewModel.");
        }
        return;
    }
    if (viewModelType == TypeResolver.Unknown.class) {
        return;
    }

    final Optional<Field> fieldOptional = getViewModelField(view.getClass(), viewModelType);
    if (fieldOptional.isPresent()) {
        Field field = fieldOptional.get();

        ReflectionUtils.accessField(field, () -> {
            Object existingViewModel = field.get(view);

            if (existingViewModel == null) {
                final Object newViewModel = DependencyInjector.getInstance().getInstanceOf(viewModelType);

                field.set(view, newViewModel);

                newVmConsumer.accept((ViewModel) newViewModel);
            }
        }, "Can't inject ViewModel of type <" + viewModelType + "> into the view <" + view + ">");

    }
}
 
开发者ID:cmlanche,项目名称:easyMvvmFx,代码行数:74,代码来源:ViewLoaderReflectionUtils.java


示例9: getTargetResourceType

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@Override
public String getTargetResourceType() {
	Class<?> repoClass = repositoryInstanceBuilder.getRepositoryClass();
	Class<?> repoInterface = RelationshipRepositoryV2.class.isAssignableFrom(repoClass) ? RelationshipRepositoryV2.class
			: RelationshipRepository.class;

	Class<?>[] typeArgs = TypeResolver
			.resolveRawArguments(repoInterface, repoClass);

	Class<?> typeArg = typeArgs[TARGET_TYPE_GENERIC_PARAMETER_IDX];
	Optional<JsonApiResource> annotation = ClassUtils.getAnnotation(typeArg, JsonApiResource.class);
	return annotation.get().type();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:14,代码来源:DirectResponseRelationshipEntry.java


示例10: createTypesafeList

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private Object createTypesafeList(Object result, Class<?> returnType) {
	DefaultResourceList defaultList = (DefaultResourceList) result;

	Class<?>[] typeArguments = TypeResolver.resolveRawArguments(ResourceListBase.class, returnType);
	Class<?> metaType = typeArguments[1];
	Class<?> linksType = typeArguments[2];

	ResourceListBase typedList = (ResourceListBase) ClassUtils.newInstance(returnType);
	typedList.addAll(defaultList);
	typedList.setMeta(defaultList.getMeta(metaType));
	typedList.setLinks(defaultList.getLinks(linksType));
	return typedList;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:15,代码来源:ClientStubInvocationHandler.java


示例11: registerListener

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Registers a single event listener.
 *
 * @param listener The listener.
 * @param isTemporary Whether the listener is temporary or not.
 */
private <T extends Event> void registerListener(IListener<T> listener, boolean isTemporary) {
	Class<?> rawType = TypeResolver.resolveRawArgument(IListener.class, listener.getClass());
	if (Event.class.isAssignableFrom(rawType)) {
		if (!classListeners.containsKey(rawType))
			classListeners.put(rawType, new CopyOnWriteArrayList<>());

		Logger.info(this, "Registered IListener %s", listener.getClass().getSimpleName());
		classListeners.get(rawType).add(new ListenerPair<>(isTemporary, listener));
	}
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:17,代码来源:EventDispatcher.java


示例12: unregisterListener

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Unregisters a single event listener.
 *
 * @param listener The listener.
 */
@SuppressWarnings("rawtypes")
public void unregisterListener(IListener listener) {
	Class<?> rawType = TypeResolver.resolveRawArgument(IListener.class, listener.getClass());
	if (Event.class.isAssignableFrom(rawType)) {
		if (classListeners.containsKey(rawType)) {
			classListeners.get(rawType).removeIf((ListenerPair pair) -> pair.listener == listener); //Yes, the == is intentional. We want the exact same instance.

			Logger.debug(this, "Unregistered IListener %s", listener.getClass().getSimpleName());
		}
	}
}
 
开发者ID:twitch4j,项目名称:twitch4j,代码行数:17,代码来源:EventDispatcher.java


示例13: resolveType

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
protected static Class<?> resolveType(Type type, MethodWrapper src) {
    if (type instanceof Class) {
        return PrimitiveTypeResolver.resolve((Class<?>) type);
    } else if (type instanceof ParameterizedType) {
        return (Class<?>) ((ParameterizedType) type).getRawType();
    }
    Class<?> resolvedType = TypeResolver.resolveRawArgument(type, src.getTargetClass());
    if (resolvedType == TypeResolver.Unknown.class) {
        // TODO: Decide what exception to throw here
        throw new RuntimeException("Cannot infer type of method parameter");
    } else {
        return resolvedType;
    }
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:15,代码来源:MethodTypeWrapper.java


示例14: getTargetAffiliation

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@Override
public Class<?> getTargetAffiliation() {
	Class<?> repoClass = repositoryInstanceBuilder.getRepositoryClass();
	Class<?> repoInterface = RelationshipRepositoryV2.class.isAssignableFrom(repoClass) ? RelationshipRepositoryV2.class : RelationshipRepository.class; 
	
    Class<?>[] typeArgs = TypeResolver
        .resolveRawArguments(repoInterface, repoClass);
    
    return typeArgs[RelationshipRepository.TARGET_TYPE_GENERIC_PARAMETER_IDX];
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:11,代码来源:DirectResponseRelationshipEntry.java


示例15: createTypesafeList

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
private Object createTypesafeList(Object result, Class<?> returnType) {
	DefaultResourceList defaultList = (DefaultResourceList) result;

	Class<?>[] typeArguments = TypeResolver.resolveRawArguments(ResourceListBase.class, returnType);
	Class<?> metaType = typeArguments[1];
	Class<?> linksType = typeArguments[2];

	ResourceListBase typedList = (ResourceListBase) ClassUtils.newInstance(returnType);
	typedList.addAll(defaultList);
	typedList.setMeta(defaultList.getMeta(metaType));
	typedList.setLinks(defaultList.getLinks(linksType));
	return typedList;
}
 
开发者ID:katharsis-project,项目名称:katharsis-framework,代码行数:15,代码来源:ClientStubInvocationHandler.java


示例16: extractParameterClass

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * @param parameterIndex
 * @return class if extracted properly, Unknown.class if it cannot be read
 */
public Class<?> extractParameterClass(int parameterIndex) {
    if (parameterIndex >= parameterCount || parameterIndex < 0) {
        throw new IllegalArgumentException("Invalid parameter index.");
    }
    return TypeResolver.resolveRawArguments(clazz, lambda.getClass())[parameterIndex];
}
 
开发者ID:Qubite,项目名称:tomoko,代码行数:11,代码来源:LambdaDescriptor.java


示例17: getRequestClass

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
public Class<?> getRequestClass(Class<?> usecaseClass) {
    Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Usecase.class, usecaseClass);
    Class<?> requestClass = typeArgs[0];
    if (requestClass == TypeResolver.Unknown.class) {
        throw new UsecaseExecutorException("Could not resolve usecase request type for class '" + usecaseClass.getName() + "'. Hint: The concrete usecase class is required to resolve the request class.");
    }

    return requestClass;
}
 
开发者ID:casid,项目名称:jusecase,代码行数:10,代码来源:UsecaseRequestResolver.java


示例18: createRequest

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@Before
public void createRequest() {
    try {
        Class<?> requestClass = TypeResolver.resolveRawArguments(UsecaseTest.class, getClass())[0];
        request = (Request) requestClass.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Failed to instantiate request. You need to override createRequest() and do it manually.", e);
    }
}
 
开发者ID:casid,项目名称:jusecase,代码行数:10,代码来源:UsecaseTest.java


示例19: ConsumerMessageListener

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
/**
 * Construct a MessageListener that wraps around a Java 8+ lambda to support quick and easy listener generation.
 * @param consumer Lambda logic to be run against the received message.
 */
@SuppressWarnings("unchecked")
public ConsumerMessageListener(Consumer<T> consumer) {
    Class typeArguments[] = TypeResolver.resolveRawArguments(Consumer.class, consumer.getClass());
    this.consumer = consumer;
    this.messageType = typeArguments[0];
}
 
开发者ID:reapzor,项目名称:FiloFirmata,代码行数:11,代码来源:ConsumerMessageListener.java


示例20: createRequest

import net.jodah.typetools.TypeResolver; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@BeforeEach
void createRequest() {
    try {
        Class<?> requestClass = TypeResolver.resolveRawArguments(UsecaseTest.class, getClass())[1];
        request = (Request) requestClass.newInstance();
    } catch (Exception e) {
        throw new RuntimeException("Failed to instantiate request. You need to override createRequest() and do it manually.", e);
    }
}
 
开发者ID:casid,项目名称:mazebert-ladder,代码行数:11,代码来源:UsecaseTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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