Example usage for java.lang.reflect Type equals

List of usage examples for java.lang.reflect Type equals

Introduction

In this page you can find the example usage for java.lang.reflect Type equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:com.CodeSeance.JSeance2.CodeGenXML.TemplateElements.Node.java

private void setFieldValue(Field field, Object value) throws IllegalAccessException {
    // TODO: Detect when value types match and throw more descriptive error
    field.setAccessible(true);/*from  w w  w .  j a  v a2 s . c  o m*/
    Type type = field.getType();
    if (type.equals(boolean.class)) {
        field.set(this, value.toString().toLowerCase().equals("true"));
    } else if (type.equals(String.class)) {
        field.set(this, value.toString());
    } else {
        field.set(this, value);
    }
}

From source file:com.fitbur.jestify.junit.spring.injector.IndexMockInjector.java

@Override
public void inject() {
    Map<DescriptorKey, ParameterDescriptor> parameterDescriptors = context.getParamaterDescriptors();
    Field field = fieldDescriptor.getField();

    Mock mock = fieldDescriptor.getMock().get();
    Integer index = mock.index();
    Optional<ParameterDescriptor> optional = parameterDescriptors.values().parallelStream()
            .filter(p -> index.equals(p.getIndex())).findFirst();

    ParameterDescriptor parameterDescriptor = optional.get();
    Parameter parameter = parameterDescriptor.getParameter();

    Type fieldType = field.getGenericType();
    Type parameterType = parameter.getParameterizedType();

    checkArgument(fieldType.equals(parameterType),
            "Can not mock field '%s'. Test class field type '%s' and class under test "
                    + "constructor parameter type '%s' at '%d' index do not match.",
            field.getName(), field.getGenericType(), parameterType, index);

    ResolvableType resolver = ResolvableType.forType(parameterType);

    Class rawType;/* w  w w .  ja  va 2s  .c o  m*/

    if (resolver.hasGenerics()) {
        if (resolver.isAssignableFrom(Provider.class) || resolver.isAssignableFrom(Optional.class)) {
            rawType = resolver.getRawClass();
        } else {
            rawType = resolver.resolve();
        }
    } else {
        rawType = (Class) parameterType;
    }

    checkArgument(arguments[index] == null,
            "Can not mock field '%s'. Multipe test class fields have the same index of '%d'", field.getName(),
            index);

    Object instance = testReifier.reifyField(fieldDescriptor, parameterDescriptor);
    arguments[index] = instance;
}

From source file:com.redhat.rhn.frontend.xmlrpc.api.ApiHandler.java

private String getType(Type classType, boolean firstParam) {
    if (classType.equals(String.class)) {
        return "string";
    } else if ((classType.equals(Integer.class)) || (classType.equals(int.class))) {
        return "int";
    } else if (classType.equals(Date.class)) {
        return "date";
    } else if (classType.equals(Boolean.class) || classType.equals(boolean.class)) {
        return "boolean";
    } else if (classType.equals(Map.class)) {
        return "struct";
    } else if ((classType.equals(List.class)) || (classType.equals(Set.class))
            || (classType.toString().contains("class [L")) || (classType.toString().contains("class [I"))) {
        return "array";
    } else if (classType.toString().contains("class [B")) {
        return "base64";
    } else if (classType.equals(com.redhat.rhn.domain.user.User.class) && firstParam) {
        // this is a workaround needed due to ef911709..2765f023bd
        return "string";
    } else {/*  www . j  a va 2s .  c  o  m*/
        return "struct";
    }
}

From source file:de.hoegertn.demo.cxfsimple.JacksonProvider.java

@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, String> httpHeaders, InputStream entityStream)
        throws IOException, WebApplicationException {
    if (genericType.equals(null)) {
        return this.mapper.readValue(entityStream, type);
    }/*from   w  ww  .  j a  va 2  s .  c  o m*/
    return this.mapper.readValue(entityStream, TypeFactory.defaultInstance().constructType(genericType));
}

From source file:com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.java

private void validateParametrizedType(Type commandReturnType, Type fallbackReturnType, Method commandMethod,
        Method fallbackMethod) {// w w w  .j  a v a  2s.  c  o  m
    if (!commandReturnType.equals(fallbackReturnType)) {
        throw new FallbackDefinitionException(createErrorMsg(commandMethod, fallbackMethod, "Fallback method '"
                + fallbackMethod + "' must return: " + commandReturnType + " or its subclass"));
    }
}

From source file:org.datalorax.populace.core.util.TypeResolver.java

private Type resolveGenericArray(final GenericArrayType type, final TypeToken<?> assigningType) {
    final Type resolvedComponentType = resolve(type.getGenericComponentType(), assigningType);
    if (resolvedComponentType.equals(type.getGenericComponentType())) {
        return type;
    }//  w ww . j  a  v  a  2 s . c om
    return TypeUtils.genericArrayType(resolvedComponentType);
}

From source file:org.springframework.kafka.listener.adapter.MessagingMessageListenerAdapter.java

private boolean eligibleParameter(MethodParameter methodParameter) {
    Type parameterType = methodParameter.getGenericParameterType();
    if (parameterType.equals(Acknowledgment.class) || parameterType.equals(ConsumerRecord.class)) {
        return false;
    }/*from  ww  w .j a v a2 s  .c  o m*/
    if (parameterType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) parameterType;
        if (parameterizedType.getRawType().equals(Message.class)) {
            return !(parameterizedType.getActualTypeArguments()[0] instanceof WildcardType);
        }
    }
    return !parameterType.equals(Message.class); // could be Message without a generic type
}

From source file:com.github.wnameless.tagwall.aop.TagwallAspectConfig.java

@Bean
public Advisor crudRepositoryDeleteIdOrEntityAdvisor() {
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(/*from w w  w. jav  a 2  s.c o m*/
            "execution(public void org.springframework.data.repository.CrudRepository+.delete(!Iterable))");

    return new DefaultPointcutAdvisor(pointcut, new MethodInterceptor() {

        @Override
        public Object invoke(MethodInvocation invocation) throws Throwable {
            Type genericType = invocation.getMethod().getGenericParameterTypes()[0];
            Object entity;
            Serializable id;
            if (genericType.equals(crudRepositoryGenericIdType)) {
                id = (Serializable) invocation.getArguments()[0];
                Method m = CrudRepository.class.getMethod("findOne", Serializable.class);
                entity = m.invoke(invocation.getThis(), id);
            } else {
                entity = invocation.getArguments()[0];
                id = getId(entity);
            }

            invocation.proceed();

            removeTags(entity.getClass().getName(), Arrays.asList(id));

            return null;
        }

    });
}

From source file:dstrelec.nats.listener.adapter.MessagingMessageListenerAdapter.java

private boolean eligibleParameter(MethodParameter methodParameter) {
    Type parameterType = methodParameter.getGenericParameterType();
    if (parameterType.equals(io.nats.client.Message.class)) {
        return false;
    }/*from w  w w .  ja  v  a2  s  .co  m*/
    if (parameterType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) parameterType;
        if (parameterizedType.getRawType().equals(Message.class)) {
            return !(parameterizedType.getActualTypeArguments()[0] instanceof WildcardType);
        }
    }
    return !parameterType.equals(Message.class); // could be Message without a generic type
}

From source file:com.netflix.hystrix.contrib.javanica.utils.FallbackMethod.java

private List<String> equalsParametrizedTypes(List<Type> commandParametrizedTypes,
        List<Type> fallbackParametrizedTypes) {
    List<String> msg = Collections.emptyList();
    if (commandParametrizedTypes.size() != fallbackParametrizedTypes.size()) {
        return Collections.singletonList("a different set of parametrized types, command: "
                + commandParametrizedTypes.size() + " fallback: " + fallbackParametrizedTypes.size());
    }//from  w w w  . j a  va 2 s  . c o m

    for (int i = 0; i < commandParametrizedTypes.size(); i++) {
        Type commandParametrizedType = commandParametrizedTypes.get(i);
        Type fallbackParametrizedType = fallbackParametrizedTypes.get(i);
        if (!commandParametrizedType.equals(fallbackParametrizedType)) {
            if (Collections.<String>emptyList() == msg) {
                msg = new ArrayList<String>();
            }
            msg.add("wrong parametrized type. Expected: '" + commandParametrizedType + "' but in fallback '"
                    + fallbackParametrizedType + "', position: " + i);
            return msg;
        }
    }

    return msg;
}