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


Java Type.equals方法代码示例

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


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

示例1: responseType

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public Type responseType() {
    Type rawType = ((ParameterizedType) returnType).getRawType();
    if (rawType.equals(Call.class) || rawType.equals(MockableCall.class) || rawType.equals(com.gabrielsamojlo.offit.Call.class)) {
        Type[] types = ((ParameterizedType) returnType).getActualTypeArguments();
        Type paramType = types[0];
        if (paramType instanceof WildcardType) {
            return ((WildcardType) paramType).getUpperBounds()[0];
        }

        this.type = paramType;

        return paramType;
    } else {
        CallAdapter callAdapter = retrofit.nextCallAdapter(factory, returnType, annotations);
        return callAdapter.responseType();
    }
}
 
开发者ID:GabrielSamojlo,项目名称:OffIt,代码行数:19,代码来源:MockableCallAdapter.java

示例2: deserialize

import java.lang.reflect.Type; //导入方法依赖的package包/类
/**
 * Deserialize the given JSON string to Java object.
 *
 * @param <T> Type
 * @param body The JSON string
 * @param returnType The type to deserialize into
 * @return The deserialized Java object
 */
@SuppressWarnings("unchecked")
public <T> T deserialize(String body, Type returnType) {
    try {
        if (apiClient.isLenientOnJson()) {
            JsonReader jsonReader = new JsonReader(new StringReader(body));
            // see https://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/stream/JsonReader.html#setLenient(boolean)
            jsonReader.setLenient(true);
            return gson.fromJson(jsonReader, returnType);
        } else {
            return gson.fromJson(body, returnType);
        }
    } catch (JsonParseException e) {
        // Fallback processing when failed to parse JSON form response body:
        //   return the response body string directly for the String return type;
        //   parse response body into date or datetime for the Date return type.
        if (returnType.equals(String.class))
            return (T) body;
        else if (returnType.equals(Date.class))
            return (T) apiClient.parseDateOrDatetime(body);
        else throw(e);
    }
}
 
开发者ID:hermannpencole,项目名称:nifi-swagger-client,代码行数:31,代码来源:JSON.java

示例3: getRequest

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public <P> P getRequest(Type requestType) throws IOException {
	if (requestType.equals(BinaryFile.class)) {
		InputStream is = iRequest.getInputStream();
		ByteArrayOutputStream buffer = new ByteArrayOutputStream();
		int read;
		byte[] data = new byte[16384];
		while ((read = is.read(data, 0, data.length)) != -1)
			buffer.write(data, 0, read);
		buffer.flush();
		BinaryFile output = new BinaryFile(buffer.toByteArray(), iRequest.getContentType(), getFileName());
		return (P)output;
	} else {
		return super.getRequest(requestType);
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:17,代码来源:BinaryFileApiHelper.java

示例4: getInjectable

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public Injectable<AuthenticationVO> getInjectable(ComponentContext ic, Context a, Type c) {
	if (c.equals(AuthenticationVO.class)) {
		return this;
	}
	return null;
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:8,代码来源:BasicAuthenticationProvider.java

示例5: matches

import java.lang.reflect.Type; //导入方法依赖的package包/类
/**
 * Checks if two types are the same or are equivalent under a variable mapping
 * given in the type map that was provided.
 */
private static boolean matches(Type from, Type to, Map<String, Type> typeMap) {
  return to.equals(from)
      || (from instanceof TypeVariable
      && to.equals(typeMap.get(((TypeVariable<?>) from).getName())));

}
 
开发者ID:odoo-mobile-intern,项目名称:odoo-work,代码行数:11,代码来源:TypeToken.java

示例6: responseBodyConverter

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    //不能直接用type==new TypeToken<List<Contributor>>(){}.getType()),将会得到false
    //因为==是用于判断两个引用变量是否相等,但是这里的==右边是new的一个新的,所以肯定是“不==”的
    Log.d("测试---》",""+(type==new TypeToken<List<Contributor>>(){}.getType()));
    if (type.equals(new TypeToken<List<Contributor>>(){}.getType())) {
        return CustomConverter.INSTANCE;
    }
    //其它类型我们不处理,返回null就行
    return null;
}
 
开发者ID:374901588,项目名称:Retrofit2Demo,代码行数:12,代码来源:Example2Activity.java

示例7: getNativeClass

import java.lang.reflect.Type; //导入方法依赖的package包/类
default Class<T> getNativeClass() {
    Type[] genericInterfaces = getClass().getGenericInterfaces();
    for (int i=0; i<genericInterfaces.length; i++) {
        Type t = genericInterfaces[i];
        if (t instanceof ParameterizedType) {
            Type rt = ((ParameterizedType) t).getRawType();
            if (rt.equals(ASTObject.class)) {
                return (Class<T>) ((ParameterizedType) t).getActualTypeArguments()[0];
            }
        }
    }
    return null;
}
 
开发者ID:lorislab,项目名称:clingo4j,代码行数:14,代码来源:ASTObject.java

示例8: httpSuccess

import java.lang.reflect.Type; //导入方法依赖的package包/类
public <T> void httpSuccess(String data) {
    if (peck.isResponseTypeStream()) {
        peck.getResponse().onSuccess(peck.getResponseStream());
        try {
            peck.getResponseStream().close();
        } catch (IOException e) {

        }
        return;
    }

    if (data == null) {
        peck.getResponse().onError(new WoodpeckerException(""));
    } else {
        WoodpeckerResponse response = peck.getResponse();
        T t;
        try {
            Type type = response.getType();
            if (type.equals(String.class) || peck.getType() == RequestType.HEAD) {
                response.onSuccess(data);
            } else {
                t = new Gson().fromJson(data, response.getType());
                response.onSuccess(t);
            }
        } catch (JsonSyntaxException jse) {
            response.onError(new WoodpeckerException(data, jse));
        }
    }
}
 
开发者ID:AviranAbady,项目名称:woodpecker,代码行数:30,代码来源:WoodpeckerHttpResponse.java

示例9: responseBodyConverter

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
    if (type != null && type.equals(String.class)) {
        return new JsonResponseBodyConverter<>();
    }
    TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type != null ? type : null));
    return new GsonResponseBodyConverter<>(gson, adapter);
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:9,代码来源:GsonConverterFactory.java

示例10: returnProperBeanParam

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Test
public void returnProperBeanParam() throws NoSuchMethodException {
    final Method method = getClass().getDeclaredMethod("testRoute", BaseBean.class, ChildBean.class, RefBean.class, EnumBean.class, Integer.class);
    final List<Pair<Type, Annotation[]>> parameters = getParameters(method.getGenericParameterTypes(), method.getParameterAnnotations());

    for (final Pair<Type, Annotation[]> parameter : parameters) {
        final Type parameterType = parameter.first();
        final List<Parameter> swaggerParams = new MinijaxSwaggerExtension().extractParameters(Arrays.asList(parameter.second()),
                parameterType, new HashSet<Type>(), SwaggerExtensions.chain());
        // Ensure proper number of parameters returned
        if (parameterType.equals(BaseBean.class)) {
            assertEquals(2, swaggerParams.size());
        } else if (parameterType.equals(ChildBean.class)) {
            assertEquals(5, swaggerParams.size());
        } else if (parameterType.equals(RefBean.class)) {
            assertEquals(5, swaggerParams.size());
        } else if (parameterType.equals(EnumBean.class)) {
            assertEquals(1, swaggerParams.size());
            final HeaderParameter enumParam = (HeaderParameter) swaggerParams.get(0);
            assertEquals("string", enumParam.getType());
            final List<String> enumValues = new ArrayList<>(Collections2.transform(Arrays.asList(TestEnum.values()), Functions.toStringFunction()));
            assertEquals(enumValues, enumParam.getEnum());
        } else if (parameterType.equals(Integer.class)) {
            assertEquals(0, swaggerParams.size());
        } else {
            fail(String.format("Parameter of type %s was not expected", parameterType));
        }

        // Ensure the proper parameter type and name is returned (The rest is handled by pre-existing logic)
        for (final Parameter param : swaggerParams) {
            assertEquals(param.getClass().getSimpleName().replace("eter", ""), param.getName());
        }
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:35,代码来源:MinijaxSwaggerTest.java

示例11: equals

import java.lang.reflect.Type; //导入方法依赖的package包/类
/**
 * Returns true if {@code a} and {@code b} are equal.
 */
public static boolean equals(Type a, Type b) {
  if (a == b) {
    // also handles (a == null && b == null)
    return true;

  } else if (a instanceof Class) {
    // Class already specifies equals().
    return a.equals(b);

  } else if (a instanceof ParameterizedType) {
    if (!(b instanceof ParameterizedType)) {
      return false;
    }

    // TODO: save a .clone() call
    ParameterizedType pa = (ParameterizedType) a;
    ParameterizedType pb = (ParameterizedType) b;
    return Objects.equal(pa.getOwnerType(), pb.getOwnerType())
        && pa.getRawType().equals(pb.getRawType())
        && Arrays.equals(pa.getActualTypeArguments(), pb.getActualTypeArguments());

  } else if (a instanceof GenericArrayType) {
    if (!(b instanceof GenericArrayType)) {
      return false;
    }

    GenericArrayType ga = (GenericArrayType) a;
    GenericArrayType gb = (GenericArrayType) b;
    return equals(ga.getGenericComponentType(), gb.getGenericComponentType());

  } else if (a instanceof WildcardType) {
    if (!(b instanceof WildcardType)) {
      return false;
    }

    WildcardType wa = (WildcardType) a;
    WildcardType wb = (WildcardType) b;
    return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
        && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());

  } else if (a instanceof TypeVariable) {
    if (!(b instanceof TypeVariable)) {
      return false;
    }
    TypeVariable<?> va = (TypeVariable) a;
    TypeVariable<?> vb = (TypeVariable) b;
    return va.getGenericDeclaration().equals(vb.getGenericDeclaration())
        && va.getName().equals(vb.getName());

  } else {
    // This isn't a type we support. Could be a generic array type, wildcard type, etc.
    return false;
  }
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:58,代码来源:MoreTypes.java

示例12: equals

import java.lang.reflect.Type; //导入方法依赖的package包/类
/** Returns true if {@code a} and {@code b} are equal. */
private static boolean equals(Type a, Type b) {
  if (a == b) {
    return true; // Also handles (a == null && b == null).
  } else if (a instanceof Class) {
    return a.equals(b); // Class already specifies equals().
  } else if (a instanceof ParameterizedType) {
    if (!(b instanceof ParameterizedType)) return false;
    ParameterizedType pa = (ParameterizedType) a;
    ParameterizedType pb = (ParameterizedType) b;
    Type[] aTypeArguments = pa instanceof ParameterizedTypeImpl
      ? ((ParameterizedTypeImpl) pa).typeArguments
      : pa.getActualTypeArguments();
    Type[] bTypeArguments = pb instanceof ParameterizedTypeImpl
      ? ((ParameterizedTypeImpl) pb).typeArguments
      : pb.getActualTypeArguments();
    return equal(pa.getOwnerType(), pb.getOwnerType())
      && pa.getRawType().equals(pb.getRawType())
      && Arrays.equals(aTypeArguments, bTypeArguments);
  } else if (a instanceof GenericArrayType) {
    if (!(b instanceof GenericArrayType)) return false;
    GenericArrayType ga = (GenericArrayType) a;
    GenericArrayType gb = (GenericArrayType) b;
    return equals(ga.getGenericComponentType(), gb.getGenericComponentType());
  } else if (a instanceof WildcardType) {
    if (!(b instanceof WildcardType)) return false;
    WildcardType wa = (WildcardType) a;
    WildcardType wb = (WildcardType) b;
    return Arrays.equals(wa.getUpperBounds(), wb.getUpperBounds())
      && Arrays.equals(wa.getLowerBounds(), wb.getLowerBounds());
  } else if (a instanceof TypeVariable) {
    if (!(b instanceof TypeVariable)) return false;
    TypeVariable<?> va = (TypeVariable<?>) a;
    TypeVariable<?> vb = (TypeVariable<?>) b;
    return va.getGenericDeclaration() == vb.getGenericDeclaration()
      && va.getName().equals(vb.getName());
  } else {
    // This isn't a supported type.
    return false;
  }
}
 
开发者ID:rogues-dev,项目名称:hoard,代码行数:42,代码来源:Types.java

示例13: isMatch

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public boolean isMatch(Type swaggerType, Type producerType) {
  return producerType.equals(Response.class);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:5,代码来源:CseResponseProducerResponseMapperFactory.java

示例14: matches

import java.lang.reflect.Type; //导入方法依赖的package包/类
private static boolean matches(Type from, Type to, Map<String, Type> typeMap) {
    return to.equals(from) || ((from instanceof TypeVariable) && to.equals(typeMap.get(((TypeVariable) from).getName())));
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:4,代码来源:TypeToken.java

示例15: isSameType

import java.lang.reflect.Type; //导入方法依赖的package包/类
@Override
public boolean isSameType(Type t1, Type t2) {
    return t1.equals(t2);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:5,代码来源:ReflectionNavigator.java


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