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


Java TypeToken.isAssignableFrom方法代码示例

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


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

示例1: isConvertibleForInvocation

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
/**
 * Test if an invocation conversion can be applied to the given types.
 *
 * https://docs.oracle.com/javase/specs/jls/se8/html/jls-5.html#jls-5.3
 */
public static boolean isConvertibleForInvocation(TypeToken<?> to, TypeToken<?> from) {
    if(to.isPrimitive()) {
        // Assigning to a primitive allows for both unboxing and primitive widening
        Class<?> fromRaw = from.getRawType();
        if(!fromRaw.isPrimitive()) {
            fromRaw = BOXINGS.inverse().get(fromRaw);
            if(fromRaw == null) return false;
        }
        return isPromotable(to.getRawType(), fromRaw);
    } else if(from.isPrimitive()) {
        // Assigning to an object from a primitive allows boxing and reference widening
        return to.isAssignableFrom(box(from.getRawType()));
    } else {
        return to.isAssignableFrom(from);
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:22,代码来源:Types.java

示例2: getMessageType

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private TypeToken<? extends Message> getMessageType(TypeToken decl, Method method) {
    if(method.getParameterTypes().length < 1 || method.getParameterTypes().length > 3) {
        throw new IllegalStateException("Message handler method must take 1 to 3 parameters");
    }

    final TypeToken<Message> base = new TypeToken<Message>(){};

    for(Type param : method.getGenericParameterTypes()) {
        final TypeToken paramToken = decl.resolveType(param);
        Types.assertFullySpecified(paramToken);
        if(base.isAssignableFrom(paramToken)) {
            messageRegistry.typeName(paramToken.getRawType()); // Verify message type is registered
            return paramToken;
        }
    }

    throw new IllegalStateException("Message handler has no message parameter");
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:19,代码来源:Queue.java

示例3: prune

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
@Override
protected boolean prune(TypeToken<? super T> adding) {
    for(Iterator<TypeToken<? super T>> iterator = iterator(); iterator.hasNext(); ) {
        final TypeToken<? super T> existing = iterator.next();
        if(adding.isAssignableFrom(existing)) return false;
        if(existing.isAssignableFrom(adding)) iterator.remove();
    }
    return true;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:10,代码来源:MinimalSupertypeSet.java

示例4: assignableTo

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public static Predicate<? super Type> assignableTo(final Type to) {
    final TypeToken<?> toToken = TypeToken.of(to);
    return from -> from != null && toToken.isAssignableFrom(from);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:5,代码来源:Types.java

示例5: assertAssignableTo

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private static Field assertAssignableTo(Field field, TypeToken<?> type) {
    if(!type.isAssignableFrom(TypeToken.of(field.getGenericType()))) {
        throw new NoSuchFieldError("Field " + field.getName() + " is not of type " + type);
    }
    return field;
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:7,代码来源:Fields.java

示例6: assignableTo

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
public static Predicate<Field> assignableTo(TypeToken<?> type) {
    return field -> type.isAssignableFrom(field.getGenericType());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:4,代码来源:Fields.java

示例7: Transaction

import com.google.common.reflect.TypeToken; //导入方法依赖的package包/类
private Transaction(Exchange.Direct exchange,
                    final Queue replyQueue,
                    Message request,
                    @Nullable Metadata requestProps,
                    @Nullable Publish publish,
                    TypeToken<T> replyType,
                    @Nullable Duration timeout) {

    super(timeout != null ? timeout : DEFAULT_TIMEOUT);

    checkNotNull(request, "request");
    checkNotNull(replyType, "replyType");

    this.callSite = new Exception().getStackTrace();
    this.replyQueue = replyQueue;

    final Metadata finalRequestProps = requestProps = replyQueue.client().getProperties(request, requestProps);
    finalRequestProps.setReplyTo(this.replyQueue.name());

    this.requestId = checkNotNull(finalRequestProps.getMessageId());
    this.requestType = request.getClass();

    this.messageHandler = new MessageHandler<Message>() {
        @Override public void handleDelivery(Message message, TypeToken<? extends Message> type, Metadata replyProps, Delivery delivery) {
            if(requestId.equals(replyProps.getCorrelationId())) {
                Transaction.this.replyQueue.unsubscribe(messageHandler);

                if(replyProps.protocolVersion() != finalRequestProps.protocolVersion()) {
                    setException(new ApiException("Received a protocol " + replyProps.protocolVersion() +
                                                  " reply to a protocol " + finalRequestProps.protocolVersion() + " request",
                                                  callSite));
                } else {
                    final Reply reply = message instanceof Reply ? (Reply) message : null;
                    if(reply != null && !reply.success()) {
                        setException(new ApiException(reply.error() != null ? reply.error()
                                                                            : "Generic failure reply to request " + requestId,
                                                      callSite));
                    } else if(!replyType.isAssignableFrom(type)) {
                        setException(new ApiException("Wrong reply type to request " + requestId +
                                                      ", expected a " + replyType +
                                                      ", received a " + type,
                                                      callSite));
                    } else {
                        set((T) message);
                    }
                }
            }
        }
    };

    this.replyQueue.subscribe(Message.class, messageHandler, null);

    exchange.publishAsync(request, finalRequestProps, publish);
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:55,代码来源:Transaction.java


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