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


Java Type类代码示例

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


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

示例1: isAssignable

import java.lang.reflect.Type; //导入依赖的package包/类
private static boolean isAssignable(ParameterizedType lhsType, ParameterizedType rhsType){
    if (lhsType.equals(rhsType)) {
        return true;
    }

    Type[] lhsTypeArguments = lhsType.getActualTypeArguments();
    Type[] rhsTypeArguments = rhsType.getActualTypeArguments();

    if (lhsTypeArguments.length != rhsTypeArguments.length) {
        return false;
    }

    for (int size = lhsTypeArguments.length, i = 0; i < size; ++i) {
        Type lhsArg = lhsTypeArguments[i];
        Type rhsArg = rhsTypeArguments[i];

        if (!lhsArg.equals(rhsArg) &&
                !(lhsArg instanceof WildcardType && isAssignable((WildcardType) lhsArg, rhsArg))) {
            return false;
        }
    }

    return true;
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:25,代码来源:TypeUtils.java

示例2: getUserPermissions

import java.lang.reflect.Type; //导入依赖的package包/类
/**
 * A utility used to get permissions for selected namespace.
 * <p>
 * It's also called by the shell, in case you want to find references.
 *
 * @param protocol the AccessControlService protocol proxy
 * @param namespace name of the namespace
 * @throws ServiceException
 */
public static List<UserPermission> getUserPermissions(RpcController controller,
    AccessControlService.BlockingInterface protocol,
    byte[] namespace) throws ServiceException {
  AccessControlProtos.GetUserPermissionsRequest.Builder builder =
    AccessControlProtos.GetUserPermissionsRequest.newBuilder();
  if (namespace != null) {
    builder.setNamespaceName(ByteStringer.wrap(namespace));
  }
  builder.setType(AccessControlProtos.Permission.Type.Namespace);
  AccessControlProtos.GetUserPermissionsRequest request = builder.build();
  AccessControlProtos.GetUserPermissionsResponse response =
    protocol.getUserPermissions(controller, request);
  List<UserPermission> perms = new ArrayList<UserPermission>(response.getUserPermissionCount());
  for (AccessControlProtos.UserPermission perm: response.getUserPermissionList()) {
    perms.add(ProtobufUtil.toUserPermission(perm));
  }
  return perms;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:ProtobufUtil.java

示例3: deserialize

import java.lang.reflect.Type; //导入依赖的package包/类
@Override
public WxMpMaterialNewsBatchGetResult deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
  WxMpMaterialNewsBatchGetResult wxMpMaterialNewsBatchGetResult = new WxMpMaterialNewsBatchGetResult();
  JsonObject json = jsonElement.getAsJsonObject();
  if (json.get("total_count") != null && !json.get("total_count").isJsonNull()) {
    wxMpMaterialNewsBatchGetResult.setTotalCount(GsonHelper.getAsInteger(json.get("total_count")));
  }
  if (json.get("item_count") != null && !json.get("item_count").isJsonNull()) {
    wxMpMaterialNewsBatchGetResult.setItemCount(GsonHelper.getAsInteger(json.get("item_count")));
  }
  if (json.get("item") != null && !json.get("item").isJsonNull()) {
    JsonArray item = json.getAsJsonArray("item");
    List<WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem> items = new ArrayList<>();
    for (JsonElement anItem : item) {
      JsonObject articleInfo = anItem.getAsJsonObject();
      items.add(WxMpGsonBuilder.create().fromJson(articleInfo, WxMpMaterialNewsBatchGetResult.WxMaterialNewsBatchGetNewsItem.class));
    }
    wxMpMaterialNewsBatchGetResult.setItems(items);
  }
  return wxMpMaterialNewsBatchGetResult;
}
 
开发者ID:11590692,项目名称:Wechat-Group,代码行数:22,代码来源:WxMpMaterialNewsBatchGetGsonAdapter.java

示例4: requestBodyConverter

import java.lang.reflect.Type; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Converter<?, RequestBody> requestBodyConverter(Type type,
                                                      Annotation[] parameterAnnotations,
                                                      Annotation[] methodAnnotations,
                                                      Retrofit retrofit) {
    if (!(type instanceof Class<?>)) {
        return null;
    }
    Class<?> c = (Class<?>) type;
    if (!Struct.class.isAssignableFrom(c)) {
        return null;
    }
    Adapter adapter = getAdapter(c);
    return new ThriftyRequestBodyConverter<>(protocolType, adapter);
}
 
开发者ID:infinum,项目名称:thrifty-retrofit-converter,代码行数:17,代码来源:ThriftyConverterFactory.java

示例5: getGenericParameterStrategy

import java.lang.reflect.Type; //导入依赖的package包/类
private static DetailFieldStrategy getGenericParameterStrategy(Type type, Optional<Class<?>> parametrizableClass) {
	DetailFieldStrategy strategy = null;
	// es un tipo generico y tengo que obtener la info de la clasex
	Optional<Type> genericType = Optional.empty();
	if (parametrizableClass.isPresent())
		genericType = ReflectionUtils.getRealType(type, parametrizableClass.get());

	LOGGER.debug("Clase generica : {}, para la clase:{}, del tipo: {}", parametrizableClass.orElse(null),
			genericType, type);
	// si la clase contenedora del parametro es collection
	if (Iterable.class.isAssignableFrom(ReflectionUtils.getClass(type).orElse(null))) {
		if (parametrizableClass.isPresent()) {
			strategy = new CollectionStrategy(genericType.orElse(null));
		} else {
			strategy = new ModelStrategy(genericType.orElse(null));
		}
	} else {
		strategy = new ModelStrategy(genericType.orElse(null));
	}
	return strategy;
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:22,代码来源:DetailFieldCreatedStrategyFactory.java

示例6: getClass

import java.lang.reflect.Type; //导入依赖的package包/类
/**
 * Get the underlying class for a type.
 * <p>
 * @param type
 *          the type to get class from
 * @return 
 * 			the underlying class, or <tt>null</tt> if the type is a variable type
 */
private static Class<?> getClass(Type type) {
	if (type instanceof Class) {
		return (Class<?>) type;
	} else if (type instanceof ParameterizedType) {
		return getClass(((ParameterizedType) type).getRawType());
	} else if (type instanceof GenericArrayType) {
		Type componentType = ((GenericArrayType) type)
				.getGenericComponentType();
		Class<?> componentClass = getClass(componentType);
		if (componentClass != null) {
			return Array.newInstance(componentClass, 0).getClass();
		} else {
			return null;
		}
	} else {
		return null;
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:27,代码来源:ReflectionUtils.java

示例7: initSuperGenericClasses

import java.lang.reflect.Type; //导入依赖的package包/类
private void initSuperGenericClasses() throws Exception
{

    Type superclassType = clazz.getGenericSuperclass();
    if (!ParameterizedType.class.isAssignableFrom(superclassType.getClass()))
    {
        return;
    }

    List<Class> list = new ArrayList<>();

    Type[] types = ((ParameterizedType) superclassType).getActualTypeArguments();
    ClassLoader classLoader = autoSetHandle.getInnerContextBridge().classLoader;
    for (Type type : types)
    {
        String className = getClassName(type);
        if (className == null)
        {
            continue;
        }
        list.add(PackageUtil.newClass(className, classLoader));
    }
    superGenericClasses = list.toArray(new Class[0]);
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:25,代码来源:Porter.java

示例8: readFrom

import java.lang.reflect.Type; //导入依赖的package包/类
@Override
public Object readFrom(
    Class<Object> type,
    Type genericType,
    Annotation[] annotations,
    MediaType mediaType,
    MultivaluedMap<String, String> httpHeaders,
    InputStream entityStream)
    throws IOException,
      WebApplicationException {
  try {
    return streamer.read(gson, genericType, entityStream);
  } catch (IOException ex) {
    exceptionHandler.onRead(gson, ex);
    throw ex;
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:GsonMessageBodyProvider.java

示例9: responseType

import java.lang.reflect.Type; //导入依赖的package包/类
@Test public void responseType() {
  Type bodyClass = new TypeToken<Future<String>>() {}.getType();
  assertThat(factory.get(bodyClass, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
  Type bodyWildcard = new TypeToken<Future<? extends String>>() {}.getType();
  assertThat(factory.get(bodyWildcard, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
  Type bodyGeneric = new TypeToken<Future<List<String>>>() {}.getType();
  assertThat(factory.get(bodyGeneric, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(new TypeToken<List<String>>() {}.getType());
  Type responseClass = new TypeToken<Future<Response<String>>>() {}.getType();
  assertThat(factory.get(responseClass, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
  Type responseWildcard = new TypeToken<Future<Response<? extends String>>>() {}.getType();
  assertThat(factory.get(responseWildcard, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
  Type resultClass = new TypeToken<Future<Response<String>>>() {}.getType();
  assertThat(factory.get(resultClass, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
  Type resultWildcard = new TypeToken<Future<Response<? extends String>>>() {}.getType();
  assertThat(factory.get(resultWildcard, NO_ANNOTATIONS, retrofit).responseType())
      .isEqualTo(String.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ScalaCallAdapterFactoryTest.java

示例10: getGenericType

import java.lang.reflect.Type; //导入依赖的package包/类
private Class<? extends Throwable> getGenericType(Class<? extends JsonApiExceptionMapper> mapper) {
	Type[] types = mapper.getGenericInterfaces();
	if (null == types || 0 == types.length) {
		types = new Type[]{mapper.getGenericSuperclass()};
	}

	for (Type type : types) {
		Class<?> rawType = ClassUtils.getRawType(type);
		if (type instanceof ParameterizedType && JsonApiExceptionMapper.class.isAssignableFrom(rawType))
		{
			//noinspection unchecked
			return (Class<? extends Throwable>) ((ParameterizedType) type).getActualTypeArguments()[0];
		}
	}

	if(isProxy(mapper)){
		return getGenericType((Class<? extends JsonApiExceptionMapper>) mapper.getSuperclass());
	}

	//Won't get in here
	throw new IllegalStateException("unable to discover exception class for " + mapper.getName());
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:23,代码来源:ExceptionMapperRegistryBuilder.java

示例11: formatTypeWithoutSpecialCharacter

import java.lang.reflect.Type; //导入依赖的package包/类
private static String formatTypeWithoutSpecialCharacter(Type type) {
    if (type instanceof Class) {
        Class clazz = (Class) type;
        return clazz.getCanonicalName();
    }
    if (type instanceof ParameterizedType) {
        ParameterizedType pType = (ParameterizedType) type;
        String typeName = formatTypeWithoutSpecialCharacter(pType.getRawType());
        for (Type typeArg : pType.getActualTypeArguments()) {
            typeName += "_";
            typeName += formatTypeWithoutSpecialCharacter(typeArg);
        }
        return typeName;
    }
    if (type instanceof GenericArrayType) {
        GenericArrayType gaType = (GenericArrayType) type;
        return formatTypeWithoutSpecialCharacter(gaType.getGenericComponentType()) + "_array";
    }
    throw new AJsoupReaderException("unsupported type: " + type + ", of class " + type.getClass());
}
 
开发者ID:zdongcoding,项目名称:jsouplib,代码行数:21,代码来源:TypeLiteral.java

示例12: execute

import java.lang.reflect.Type; //导入依赖的package包/类
@Override
protected <T> Observable<T> execute(Type type) {
    if (stringBuilder.length() > 0) {
        suffixUrl = suffixUrl + stringBuilder.toString();
    }
    if (params != null && params.size() > 0) {
        Iterator<Map.Entry<String, String>> entryIterator = params.entrySet().iterator();
        Map.Entry<String, String> entry;
        while (entryIterator.hasNext()) {
            entry = entryIterator.next();
            if (entry != null) {
                multipartBodyParts.add(MultipartBody.Part.createFormData(entry.getKey(), entry.getValue()));
            }
        }
    }
    return apiService.uploadFiles(suffixUrl, multipartBodyParts).compose(this.<T>norTransformer(type));
}
 
开发者ID:xiaoyaoyou1212,项目名称:XSnow,代码行数:18,代码来源:UploadRequest.java

示例13: responseConverterFactoryQueried

import java.lang.reflect.Type; //导入依赖的package包/类
@Test public void responseConverterFactoryQueried() {
  Type type = String.class;
  Annotation[] annotations = new Annotation[0];

  Converter<ResponseBody, ?> expectedAdapter = mock(Converter.class);
  Converter.Factory factory = mock(Converter.Factory.class);

  Retrofit retrofit = new Retrofit.Builder()
      .baseUrl("http://example.com/")
      .addConverterFactory(factory)
      .build();

  doReturn(expectedAdapter).when(factory).responseBodyConverter(type, annotations, retrofit);

  Converter<ResponseBody, ?> actualAdapter = retrofit.responseBodyConverter(type, annotations);
  assertThat(actualAdapter).isSameAs(expectedAdapter);

  verify(factory).responseBodyConverter(type, annotations, retrofit);
  verifyNoMoreInteractions(factory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RetrofitTest.java

示例14: deserialize

import java.lang.reflect.Type; //导入依赖的package包/类
@Override
public VKApiComment deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject root = json.getAsJsonObject();
    VKApiComment dto = new VKApiComment();

    dto.id = optInt(root, "id");
    dto.from_id = optInt(root, "from_id");

    if(dto.from_id == 0){
        dto.from_id = optInt(root, "owner_id");
    }

    dto.date = optLong(root, "date");
    dto.text = optString(root, "text");
    dto.reply_to_user = optInt(root, "reply_to_user");
    dto.reply_to_comment = optInt(root, "reply_to_comment");

    if(root.has("attachments")){
        dto.attachments = context.deserialize(root.get("attachments"), VkApiAttachments.class);
    }

    if(root.has("likes")){
        JsonObject likesRoot = root.getAsJsonObject("likes");
        dto.likes = optInt(likesRoot, "count");
        dto.user_likes = optIntAsBoolean(likesRoot, "user_likes");
        dto.can_like = optIntAsBoolean(likesRoot, "can_like");
    }

    dto.can_edit = optIntAsBoolean(root, "can_edit");
    return dto;
}
 
开发者ID:PhoenixDevTeam,项目名称:Phoenix-for-VK,代码行数:32,代码来源:CommentDtoAdapter.java

示例15: inferIndexType

import java.lang.reflect.Type; //导入依赖的package包/类
/**
 * Given a type, infer the {@link IndexType} that is used to store and query a field.
 *
 * @param type
 * @return
 */
protected IndexType inferIndexType(Type type) {
    // we go a direct get first
    IndexType indexType = indexTypeMappingCache.get(type);
    if (indexType == null) {
        if (TypeIntrospector.isACollection(type)) {
            type = TypeIntrospector.getCollectionType(type);
        }
        Class<?> classType = TypeIntrospector.asClass(type);
        // if not present, we find the first match in the cache
        for (Map.Entry<Class<?>, IndexType> entry : indexTypeMappingCache.entrySet()) {
            if (entry.getKey().isAssignableFrom(classType)) {
                indexType = entry.getValue();
                // put the matching type back into the cache to speed up subsequent inference
                indexTypeMappingCache.put(classType, indexType);
                break;
            }
        }
    }
    if (indexType == null) {
        throw new SearchException("Unable to infer an %s for the type %s - you should add a mapping using the %s", IndexTypeLookup.class.getSimpleName(), type,
                IndexTypeLookup.class.getSimpleName());
    }
    return indexType;
}
 
开发者ID:monPlan,项目名称:AppleSeed,代码行数:31,代码来源:IndexTypeLookup.java


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