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


Java TypeResolver.resolveRawArgument方法代码示例

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


在下文中一共展示了TypeResolver.resolveRawArgument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: Factory

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Creates a new factory with a constructor function that instantiates the factory object,
 * and with a processor that is capable of mutating the instantiated object after its initialization.
 *
 * A factory's processor may be modified to allow specific customization of instantiated objects before it is used.
 * @param id The identifier for this factory type
 * @param constructor The construction function
 * @param processor The processor function
 */
@SuppressWarnings("unchecked")
public Factory(String id, Supplier<T> constructor, Function<T, T> processor) {
	this.id = id;
	this.constructor = constructor;
	this.processor = processor;
	Class<?> type = TypeResolver.resolveRawArguments(Function.class, processor.getClass())[1];
	if (type == TypeResolver.Unknown.class || type == Identifiable.class) {
		type = TypeResolver.resolveRawArgument(Supplier.class, constructor.getClass());
	}
	this.type = (Class<? extends T>) type;
}
 
开发者ID:NOVA-Team,项目名称:NOVA-Core,代码行数:21,代码来源:Factory.java

示例10: registerHandler

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Registers a handler which will/may be notified of incoming messages.
 *
 * @param handler
 *          The handler which should be registered.
 */
@SuppressWarnings("unchecked")
public final <T extends MsgT> void registerHandler(final Consumer<T> handler) {
  final Class<?> tMessageType =
      TypeResolver.resolveRawArgument(Consumer.class, handler.getClass());
  routes.merge(tMessageType, Collections.singletonList((Consumer<MsgT>) handler),
      (associated, given) -> {
        List<Consumer<MsgT>> handlers = new ArrayList<>(associated);
        handlers.addAll(given);
        return handlers;
      });
}
 
开发者ID:sventorben,项目名称:cqrs,代码行数:18,代码来源:InMemoryBus.java

示例11: registerListener

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Registers an IListener to receive events.
 * @param listener Listener to register
 */
@Override public void registerListener(Object listener) {
	if(listener instanceof IListener) {
		Class<?> rawType = TypeResolver.resolveRawArgument(IListener.class, listener.getClass());
		if (IEvent.class.isAssignableFrom(rawType)) {
			Class<? extends IEvent> eventType = (Class<? extends IEvent>) rawType;
			if (listenerMap.containsKey(eventType)) {
				listenerMap.get(eventType).add((IListener) listener);
			} else {
				listenerMap.put(eventType, new ArrayList<>(Collections.singletonList((IListener) listener)));
			}
			Discord4J.logger.debug("Registered IListener for {}. Map size now {}.", eventType.getSimpleName(), listenerMap.size());
		}
	}
}
 
开发者ID:nerd,项目名称:Discord4J,代码行数:19,代码来源:EventDispatcher.java

示例12: registerCustomSerializers

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
private void registerCustomSerializers(Reflections reflections, SimpleModule jacksonModule) {
    Set<Class<? extends JsonSerializer>> customSerializers = reflections.getSubTypesOf(JsonSerializer.class);
    for (Class<? extends JsonSerializer> customSerializer : customSerializers) {
        Class<?> objectClass = TypeResolver.resolveRawArgument(JsonSerializer.class,customSerializer);
        try {
            jacksonModule.addSerializer(objectClass, customSerializer.newInstance());
        } catch(Exception e) {
            logger.warn(String.format("Failed to create Custom Jackson Serializer: %s",customSerializer.getName()),e);
        }
    }
}
 
开发者ID:elasticsoftwarefoundation,项目名称:elasticactors,代码行数:12,代码来源:ObjectMapperBuilder.java

示例13: configClass

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Returns the {@link Class} for the app's config. {@link YamlConfigContext} must be {@code abstract} for this to
 * work properly due to type erasure.
 */
@SuppressWarnings("unchecked")
private Class<ConfigT> configClass() {
    return (Class<ConfigT>) TypeResolver.resolveRawArgument(YamlConfigContext.class, getClass());
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:9,代码来源:YamlConfigContext.java

示例14: configClass

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Returns the {@link Class} for the app's config. {@link MockConfigContext} must be {@code abstract} for this to
 * work properly due to type erasure.
 */
@SuppressWarnings("unchecked")
private Class<ConfigT> configClass() {
    return (Class<ConfigT>) TypeResolver.resolveRawArgument(MockConfigContext.class, getClass());
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:9,代码来源:MockConfigContext.java

示例15: getGenericClass

import net.jodah.typetools.TypeResolver; //导入方法依赖的package包/类
/**
 * Returns the {@link Class} for the generic type {@code T}.
 */
@SuppressWarnings("unchecked")
public Class<T> getGenericClass() {
    return (Class<T>) TypeResolver.resolveRawArgument(GenericClass.class, getClass());
}
 
开发者ID:joeyb,项目名称:undercarriage,代码行数:8,代码来源:GenericClass.java


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