List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.github.abel533.mapperhelper.EntityHelper.java
/** * ?Field/*from w w w . j a va2 s .co m*/ * * @param entityClass * @param fieldList * @return */ private static List<Field> getAllField(Class<?> entityClass, List<Field> fieldList) { if (fieldList == null) { fieldList = new ArrayList<Field>(); } if (entityClass.equals(Object.class)) { return fieldList; } Field[] fields = entityClass.getDeclaredFields(); for (Field field : fields) { //??bug#2 if (!Modifier.isStatic(field.getModifiers())) { fieldList.add(field); } } Class<?> superClass = entityClass.getSuperclass(); if (superClass != null && !superClass.equals(Object.class) && (superClass.isAnnotationPresent(Entity.class) || (!Map.class.isAssignableFrom(superClass) && !Collection.class.isAssignableFrom(superClass)))) { return getAllField(entityClass.getSuperclass(), fieldList); } return fieldList; }
From source file:net.jodah.typetools.TypeResolver.java
/** * Returns the generic {@code type} using type variable information from the {@code subType} else {@code null} if the * generic type cannot be resolved.// w ww .j a va2 s .c om * * @param type to resolve generic type for * @param subType to extract type variable information from * @return generic {@code type} else {@code null} if it cannot be resolved */ public static Type resolveGenericType(Class<?> type, Type subType) { Class<?> rawType; if (subType instanceof ParameterizedType) rawType = (Class<?>) ((ParameterizedType) subType).getRawType(); else rawType = (Class<?>) subType; if (type.equals(rawType)) return subType; Type result; if (type.isInterface()) { for (Type superInterface : rawType.getGenericInterfaces()) if (superInterface != null && !superInterface.equals(Object.class)) if ((result = resolveGenericType(type, superInterface)) != null) return result; } Type superClass = rawType.getGenericSuperclass(); if (superClass != null && !superClass.equals(Object.class)) if ((result = resolveGenericType(type, superClass)) != null) return result; return null; }
From source file:com.ms.commons.summer.web.util.json.JsonBeanUtils.java
private static Object convertPropertyValueToArray(String key, Object value, Class targetType, JsonConfig jsonConfig, Map classMap) { Class innerType = JSONUtils.getInnerComponentType(targetType); Class targetInnerType = findTargetClass(key, classMap); if (innerType.equals(Object.class) && targetInnerType != null && !targetInnerType.equals(Object.class)) { innerType = targetInnerType;//from www . jav a 2s .c o m } JsonConfig jsc = jsonConfig.copy(); jsc.setRootClass(innerType); jsc.setClassMap(classMap); Object array = JSONArray.toArray((JSONArray) value, jsc); if (innerType.isPrimitive() || JSONUtils.isNumber(innerType) || Boolean.class.isAssignableFrom(innerType) || JSONUtils.isString(innerType)) { array = JSONUtils.getMorpherRegistry().morph(Array.newInstance(innerType, 0).getClass(), array); } else if (!array.getClass().equals(targetType)) { if (!targetType.equals(Object.class)) { Morpher morpher = JSONUtils.getMorpherRegistry() .getMorpherFor(Array.newInstance(innerType, 0).getClass()); if (IdentityObjectMorpher.getInstance().equals(morpher)) { ObjectArrayMorpher beanMorpher = new ObjectArrayMorpher( new BeanMorpher(innerType, JSONUtils.getMorpherRegistry())); JSONUtils.getMorpherRegistry().registerMorpher(beanMorpher); } array = JSONUtils.getMorpherRegistry().morph(Array.newInstance(innerType, 0).getClass(), array); } } return array; }
From source file:at.treedb.backup.Export.java
/** * Ignore abstract and some special class for default dump. * /*w w w . j a va 2s . c o m*/ * @param clazz * @return {@code */ private static boolean isIgnoreClass(Class<?> clazz) { if (Modifier.isAbstract(clazz.getModifiers()) || clazz.equals(DBFSblock.class) || clazz.equals(DBinfo.class)) { return true; } return false; }
From source file:com.github.valdr.thirdparty.spring.AnnotationUtils.java
/** * Get a single {@link java.lang.annotation.Annotation} of {@code annotationType} from the supplied {@link java.lang.reflect.Method}, * traversing its super methods if no annotation can be found on the given method itself. * <p>Annotations on methods are not inherited by default, so we need to handle this explicitly. * @param method the method to look for annotations on * @param annotationType the annotation class to look for * @return the annotation found, or {@code null} if none found *///from w w w.ja v a2s. co m public static <A extends Annotation> A findAnnotation(Method method, Class<A> annotationType) { A annotation = getAnnotation(method, annotationType); Class<?> clazz = method.getDeclaringClass(); if (annotation == null) { annotation = searchOnInterfaces(method, annotationType, clazz.getInterfaces()); } while (annotation == null) { clazz = clazz.getSuperclass(); if (clazz == null || clazz.equals(Object.class)) { break; } try { Method equivalentMethod = clazz.getDeclaredMethod(method.getName(), method.getParameterTypes()); annotation = getAnnotation(equivalentMethod, annotationType); } catch (NoSuchMethodException ex) { // No equivalent method found } if (annotation == null) { annotation = searchOnInterfaces(method, annotationType, clazz.getInterfaces()); } } return annotation; }
From source file:foundation.stack.datamill.configuration.impl.Classes.java
public static boolean isAssignable(Class<?> clazz, final Class<?> toClass) { if (toClass == null) { return false; }// w w w . jav a 2 s.c om if (clazz == null) { return !toClass.isPrimitive(); } if (clazz.isPrimitive() && !toClass.isPrimitive()) { clazz = primitiveToWrapper(clazz); if (clazz == null) { return false; } } if (toClass.isPrimitive() && !clazz.isPrimitive()) { clazz = wrapperToPrimitive(clazz); if (clazz == null) { return false; } } if (clazz.equals(toClass)) { return true; } if (clazz.isPrimitive()) { if (!toClass.isPrimitive()) { return false; } if (Integer.TYPE.equals(clazz)) { return Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Long.TYPE.equals(clazz)) { return Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Boolean.TYPE.equals(clazz)) { return false; } if (Double.TYPE.equals(clazz)) { return false; } if (Float.TYPE.equals(clazz)) { return Double.TYPE.equals(toClass); } if (Character.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Short.TYPE.equals(clazz)) { return Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } if (Byte.TYPE.equals(clazz)) { return Short.TYPE.equals(toClass) || Integer.TYPE.equals(toClass) || Long.TYPE.equals(toClass) || Float.TYPE.equals(toClass) || Double.TYPE.equals(toClass); } // should never get here return false; } return toClass.isAssignableFrom(clazz); }
From source file:org.apache.brooklyn.rest.client.BrooklynApi.java
public static <T> T getEntity(Response response, Class<T> type) { if (response instanceof ClientResponse) { ClientResponse<?> clientResponse = (ClientResponse<?>) response; return clientResponse.getEntity(type); } else if (response instanceof BuiltResponse) { // Handle BuiltResponsePreservingError turning objects into Strings if (response.getEntity() instanceof String && !type.equals(String.class)) { return new Gson().fromJson(response.getEntity().toString(), type); }// w w w. j a v a 2 s . c o m } // Last-gasp attempt. return type.cast(response.getEntity()); }
From source file:com.amalto.workbench.utils.HttpClientUtil.java
private static <T> T readResponse(HttpResponse response, Class<T> clz) throws ParseException, IOException { HttpEntity content = response.getEntity(); if (null != clz && content != null && content.isStreaming()) { if (clz.equals(byte[].class)) { InputStream instream = content.getContent(); try { return (T) IOUtils.toByteArray(instream); } finally { IOUtils.closeQuietly(instream); }//from ww w . j a v a2 s.c o m } if (clz.equals(String.class)) { return (T) EntityUtils.toString(content, DEFAULT_CHARSET); } } return null; }
From source file:com.impetus.kundera.metadata.MetadataUtils.java
/** * Gets the embedded collection instance. * // w ww . j av a 2 s . c om * @param embeddedCollectionField * the embedded collection field * @return the embedded collection instance */ public static Collection getEmbeddedCollectionInstance(Field embeddedCollectionField) { Collection embeddedCollection = null; Class embeddedCollectionFieldClass = embeddedCollectionField.getType(); if (embeddedCollection == null || embeddedCollection.isEmpty()) { if (embeddedCollectionFieldClass.equals(List.class)) { embeddedCollection = new ArrayList<Object>(); } else if (embeddedCollectionFieldClass.equals(Set.class)) { embeddedCollection = new HashSet<Object>(); } else { throw new InvalidEntityDefinitionException( "Field " + embeddedCollectionField.getName() + " must be either instance of List or Set"); } } return embeddedCollection; }
From source file:com.github.strawberry.redis.RedisLoader.java
private static Option loadFromRedis(JedisPool pool, final Field field, final Redis annotation) { return using(pool)._do(new F<Jedis, Option>() { @Override//from w w w . j a va2 s .c om public Option f(Jedis jedis) { Object value = null; Class<?> fieldType = field.getType(); String pattern = annotation.value(); boolean allowNull = annotation.allowNull(); Set<String> redisKeys = Sets.newTreeSet(jedis.keys(pattern)); if (redisKeys.size() == 1) { String redisKey = Iterables.getOnlyElement(redisKeys); if (fieldType.equals(char[].class)) { value = jedis.get(redisKey).toCharArray(); } else if (fieldType.equals(Character[].class)) { value = ArrayUtils.toObject(jedis.get(redisKey).toCharArray()); } else if (fieldType.equals(char.class) || fieldType.equals(Character.class)) { String toConvert = jedis.get(redisKey); if (toConvert.length() == 1) { value = jedis.get(redisKey).charAt(0); } else { throw ConversionException.of(toConvert, redisKey, fieldType); } } else if (fieldType.equals(String.class)) { value = jedis.get(redisKey); } else if (fieldType.equals(byte[].class)) { value = jedis.get(redisKey.getBytes()); } else if (fieldType.equals(Byte[].class)) { value = ArrayUtils.toObject(jedis.get(redisKey.getBytes())); } else if (fieldType.equals(boolean.class) || fieldType.equals(Boolean.class)) { String toConvert = jedis.get(redisKey); if (BOOLEAN.matcher(toConvert).matches()) { value = TRUE.matcher(toConvert).matches(); } else { throw ConversionException.of(toConvert, redisKey, fieldType); } } else if (Map.class.isAssignableFrom(fieldType)) { value = mapOf(field, jedis, redisKey); } else if (Collection.class.isAssignableFrom(fieldType)) { value = collectionOf(field, jedis, redisKey); } else { String toConvert = jedis.get(redisKey); try { if (fieldType.equals(byte.class) || fieldType.equals(Byte.class)) { value = Byte.parseByte(jedis.get(redisKey)); } else if (fieldType.equals(short.class) || fieldType.equals(Short.class)) { value = Short.parseShort(toConvert); } else if (fieldType.equals(int.class) || fieldType.equals(Integer.class)) { value = Integer.parseInt(toConvert); } else if (fieldType.equals(long.class) || fieldType.equals(Long.class)) { value = Long.parseLong(toConvert); } else if (fieldType.equals(BigInteger.class)) { value = new BigInteger(toConvert); } else if (fieldType.equals(float.class) || fieldType.equals(Float.class)) { value = Float.parseFloat(toConvert); } else if (fieldType.equals(double.class) || fieldType.equals(Double.class)) { value = Double.parseDouble(toConvert); } else if (fieldType.equals(BigDecimal.class)) { value = new BigDecimal(toConvert); } } catch (NumberFormatException exception) { throw ConversionException.of(exception, toConvert, redisKey, fieldType); } } } else if (redisKeys.size() > 1) { if (Map.class.isAssignableFrom(fieldType)) { value = nestedMapOf(field, jedis, redisKeys); } else if (Collection.class.isAssignableFrom(fieldType)) { value = nestedCollectionOf(field, jedis, redisKeys); } } else { if (!allowNull) { value = nonNullValueOf(fieldType); } } return Option.fromNull(value); } }); }