List of usage examples for java.lang Class equals
public boolean equals(Object obj)
From source file:com.parse.simple.SimpleParse.java
public synchronized static <T> T load(T from, ParseObject to) { for (Map.Entry<SimpleField, SimpleParseColumn> fieldEntry : SimpleParseCache.get() .getColumnFields(from.getClass()).entrySet()) { final SimpleField field = fieldEntry.getKey(); final SimpleParseColumn column = fieldEntry.getValue(); final String columnName = SimpleParseCache.get().getColumnName(field, column); if (TextUtils.isEmpty(columnName)) continue; Bundle icicle = SimpleParseCache.get().columnDataCache.get(columnName); if (icicle == null) { icicle = new Bundle(); SimpleParseCache.get().columnDataCache.put(columnName, icicle); }// www . ja v a 2 s . c o m Class<?> fieldType = field.getType(); field.setAccessible(true); try { Class<? extends Filter> filterClass = column.filter(); Filter filter = null; if (!OptionalFilter.class.equals(filterClass)) { filter = SimpleParseCache.get().getFilter(column.filter()); } boolean filtered = false; Object saveValue = null; if (!Optional.class.equals(column.loader())) { filtered = true; saveValue = ((Value) SimpleParseCache.get().getObject(column.loader())).value(); } else if (NullValue.class.equals(column.loader())) { continue; } else if (filter != null) { Class<?> saveType = filter.getSaveType(); if (!saveType.equals(fieldType)) { filtered = true; if (column.self() && saveType.isAssignableFrom(ParseObject.class)) { saveValue = (ParseObject) to; saveValue = (ParseObject) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Byte.class) || saveType.equals(byte.class)) { saveValue = (byte) to.getInt(columnName); saveValue = (byte) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Short.class) || saveType.equals(short.class)) { saveValue = (short) to.getInt(columnName); saveValue = (short) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Integer.class) || saveType.equals(int.class)) { saveValue = to.getInt(columnName); saveValue = (int) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Long.class) || saveType.equals(long.class)) { saveValue = to.getLong(columnName); saveValue = (long) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Float.class) || saveType.equals(float.class)) { saveValue = (float) to.getDouble(columnName); saveValue = (float) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Double.class) || saveType.equals(double.class)) { saveValue = to.getDouble(columnName); saveValue = (double) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Boolean.class) || saveType.equals(boolean.class)) { saveValue = to.getBoolean(columnName); saveValue = (boolean) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Character.class) || saveType.equals(char.class)) { saveValue = to.getString(columnName); saveValue = (String) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(String.class)) { if (SimpleParseObject.OBJECT_ID.equals(columnName)) { saveValue = to.getObjectId(); } else { saveValue = to.getString(columnName); } saveValue = (String) filter.onLoad(saveValue, icicle, from, to); String prefix = column.prefix(); Class<?> prefixClass = column.prefixClass(); if (!Optional.class.equals(prefixClass)) { prefix = (String) ((Value) SimpleParseCache.get().getObject(prefixClass)).value(); } String suffix = column.suffix(); Class<?> suffixClass = column.suffixClass(); if (!Optional.class.equals(suffixClass)) { suffix = (String) ((Value) SimpleParseCache.get().getObject(suffixClass)).value(); } saveValue = prefix + saveValue + suffix; } else if (saveType.equals(Byte[].class) || saveType.equals(byte[].class)) { saveValue = to.getString(columnName); saveValue = (String) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(JSONObject.class)) { saveValue = to.getJSONObject(columnName); saveValue = (JSONObject) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(List.class)) { saveValue = to.getList(columnName); saveValue = (List) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(Date.class)) { saveValue = to.getDate(columnName); saveValue = (Date) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(ParseUser.class)) { saveValue = to.getParseUser(columnName); saveValue = (ParseUser) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(ParseGeoPoint.class)) { saveValue = to.getParseGeoPoint(columnName); saveValue = (ParseGeoPoint) filter.onLoad(saveValue, icicle, from, to); } else if (saveType.equals(ParseObject.class)) { saveValue = to.getParseObject(columnName); saveValue = (ParseObject) filter.onLoad(saveValue, icicle, from, to); } } } if (column.self() && fieldType.isAssignableFrom(ParseObject.class)) { ParseObject value = (ParseObject) (filtered ? saveValue : to); field.set(from, value); } else if (fieldType.equals(Byte.class) || fieldType.equals(byte.class)) { byte value = (byte) (filtered ? saveValue : to.getInt(columnName)); field.setByte(from, value); } else if (fieldType.equals(Short.class) || fieldType.equals(short.class)) { short value = (short) (filtered ? saveValue : to.getInt(columnName)); field.setShort(from, value); } else if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) { int value = (int) (filtered ? saveValue : to.getInt(columnName)); field.setInt(from, value); } else if (fieldType.equals(Long.class) || fieldType.equals(long.class)) { long value = (long) (filtered ? saveValue : to.getLong(columnName)); field.setLong(from, value); } else if (fieldType.equals(Float.class) || fieldType.equals(float.class)) { float value = (float) (filtered ? saveValue : to.getDouble(columnName)); field.setFloat(from, value); } else if (fieldType.equals(Double.class) || fieldType.equals(double.class)) { double value = (double) (filtered ? saveValue : to.getDouble(columnName)); field.setDouble(from, value); } else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) { boolean value = (boolean) (filtered ? saveValue : to.getBoolean(columnName)); field.setBoolean(from, value); } else if (fieldType.equals(Character.class) || fieldType.equals(char.class)) { String value = (String) (filtered ? saveValue : to.getString(columnName)); field.set(from, value); } else if (fieldType.equals(String.class)) { String value = null; if (filtered) { value = (String) saveValue; } else { if (SimpleParseObject.OBJECT_ID.equals(columnName)) { value = to.getObjectId(); } else { value = to.getString(columnName); } String prefix = column.prefix(); Class<?> prefixClass = column.prefixClass(); if (!Optional.class.equals(prefixClass)) { prefix = (String) ((Value) SimpleParseCache.get().getObject(prefixClass)).value(); } String suffix = column.suffix(); Class<?> suffixClass = column.suffixClass(); if (!Optional.class.equals(suffixClass)) { suffix = (String) ((Value) SimpleParseCache.get().getObject(suffixClass)).value(); } value = prefix + value + suffix; } field.set(from, value); } else if (fieldType.equals(Byte[].class) || fieldType.equals(byte[].class)) { String value = (String) (filtered ? saveValue : to.getString(columnName)); field.set(from, value); } else if (fieldType.equals(JSONObject.class)) { JSONObject value = (JSONObject) (filtered ? saveValue : to.getJSONObject(columnName)); field.set(from, value); } else if (fieldType.equals(List.class)) { List value = (List) (filtered ? saveValue : to.getList(columnName)); field.set(from, value); } else if (fieldType.equals(Date.class)) { Date value = (Date) (filtered ? saveValue : to.getDate(columnName)); field.set(from, value); } else if (fieldType.equals(ParseUser.class)) { ParseUser value = (ParseUser) (filtered ? saveValue : to.getParseUser(columnName)); field.set(from, value); } else if (fieldType.equals(ParseGeoPoint.class)) { ParseGeoPoint value = (ParseGeoPoint) (filtered ? saveValue : to.getParseGeoPoint(columnName)); field.set(from, value); } else if (fieldType.equals(ParseObject.class)) { ParseObject value = (ParseObject) (filtered ? saveValue : to.getParseObject(columnName)); field.set(from, value); } //else if (ReflectionUtils.isSubclassOf(fieldType, Enum.class)) { //to.put(columnName, ((Enum<?>) value).name()); //} } catch (IllegalArgumentException e) { } catch (IllegalAccessException e) { } } SimpleParseCache.get().columnDataCache.clear(); return from; }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * Creates a concrete collection for the suppied interface * @param interfaceType The interface// ww w .j a v a 2s . c o m * @return ArrayList for List, TreeSet for SortedSet, HashSet for Set etc. */ public static Collection createConcreteCollection(Class interfaceType) { Collection elements; if (interfaceType.equals(List.class)) { elements = new ArrayList(); } else if (interfaceType.equals(SortedSet.class)) { elements = new TreeSet(); } else { elements = new HashSet(); } return elements; }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
private static boolean isTypeInstanceOfPropertyType(Class type, Class propertyType) { return propertyType.isAssignableFrom(type) && !propertyType.equals(Object.class); }
From source file:com.erudika.para.utils.Utils.java
/** * Checks if a class is primitive, String or a primitive wrapper. * * @param clazz a class//from w w w. java 2 s . c om * @return true if primitive or wrapper */ public static boolean isBasicType(Class<?> clazz) { return (clazz == null) ? false : (clazz.isPrimitive() || clazz.equals(String.class) || clazz.equals(Long.class) || clazz.equals(Integer.class) || clazz.equals(Boolean.class) || clazz.equals(Byte.class) || clazz.equals(Short.class) || clazz.equals(Float.class) || clazz.equals(Double.class) || clazz.equals(Character.class)); }
From source file:org.codehaus.griffon.commons.GriffonClassUtils.java
/** * * Returns true if the specified property in the specified class is of the specified type * * @param clazz The class which contains the property * @param propertyName The property name * @param type The type to check//from w w w . j ava 2 s .c o m * * @return A boolean value */ public static boolean isPropertyOfType(Class clazz, String propertyName, Class type) { try { Class propType = getPropertyType(clazz, propertyName); return propType != null && propType.equals(type); } catch (Exception e) { return false; } }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Given a method, which may come from an interface, and a target class used * in the current reflective invocation, find the corresponding target method * if there is one. E.g. the method may be <code>IFoo.bar()</code> and the * target class may be <code>DefaultFoo</code>. In this case, the method may be * <code>DefaultFoo.bar()</code>. This enables attributes on that method to be found. * <p><b>NOTE:</b> In contrast to {@link org.springframework.aop.support.AopUtils#getMostSpecificMethod}, * this method does <i>not</i> resolve Java 5 bridge methods automatically. * Call {@link org.springframework.core.BridgeMethodResolver#findBridgedMethod} * if bridge method resolution is desirable (e.g. for obtaining metadata from * the original method definition)./*from w ww . j a v a2s.c o m*/ * @param method the method to be invoked, which may come from an interface * @param targetClass the target class for the current invocation. * May be <code>null</code> or may not even implement the method. * @return the specific target method, or the original method if the * <code>targetClass</code> doesn't implement it or is <code>null</code> * @see org.springframework.aop.support.AopUtils#getMostSpecificMethod */ public static Method getMostSpecificMethod(Method method, Class targetClass) { if (method != null && targetClass != null && !targetClass.equals(method.getDeclaringClass())) { try { method = targetClass.getMethod(method.getName(), method.getParameterTypes()); } catch (NoSuchMethodException ex) { // Perhaps the target class doesn't implement this method: // that's fine, just use the original method. } } return method; }
From source file:dk.netarkivet.archive.webinterface.BatchGUI.java
/** * Finds a constructor which either does not take any arguments, or does only takes string arguments. Any * constructor which does has other arguments than string is ignored. * * @param c The class to retrieve the constructor from. * @return The string argument based constructor of the class. * @throws UnknownID If no valid constructor can be found. *//* w w w .j a va 2 s. c o m*/ @SuppressWarnings("rawtypes") private static Constructor findStringConstructor(Class c) throws UnknownID { for (Constructor con : c.getConstructors()) { boolean valid = true; // validate the parameter classes. Ignore if not string. for (Class cl : con.getParameterTypes()) { if (!cl.equals(java.lang.String.class)) { valid = false; break; } } if (valid) { return con; } } // throw an exception if no valid constructor can be found. throw new UnknownID("No valid constructor can be found for class '" + c.getName() + "'."); }
From source file:com.springframework.core.annotation.AnnotationUtils.java
/** * Perform the search algorithm for {@link #findAnnotation(Class, Class)}, * avoiding endless recursion by tracking which annotations have already * been <em>visited</em>.// w w w . j a va2 s. c o m * @param clazz the class to look for annotations on * @param annotationType the type of annotation to look for * @param visited the set of annotations that have already been visited * @return the matching annotation, or {@code null} if not found */ @SuppressWarnings("unchecked") private static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType, Set<Annotation> visited) { Assert.notNull(clazz, "Class must not be null"); try { Annotation[] anns = clazz.getDeclaredAnnotations(); for (Annotation ann : anns) { if (ann.annotationType().equals(annotationType)) { return (A) ann; } } for (Annotation ann : anns) { if (!isInJavaLangAnnotationPackage(ann) && visited.add(ann)) { A annotation = findAnnotation(ann.annotationType(), annotationType, visited); if (annotation != null) { return annotation; } } } } catch (Exception ex) { // Assuming nested Class values not resolvable within annotation attributes... logIntrospectionFailure(clazz, ex); return null; } for (Class<?> ifc : clazz.getInterfaces()) { A annotation = findAnnotation(ifc, annotationType, visited); if (annotation != null) { return annotation; } } Class<?> superclass = clazz.getSuperclass(); if (superclass == null || superclass.equals(Object.class)) { return null; } return findAnnotation(superclass, annotationType, visited); }
From source file:adalid.commons.util.TimeUtils.java
public static java.util.Date toJavaDate(Object object, Class<? extends java.util.Date> targetClass) { if (object == null) { return null; }//from www .j av a 2s. c om Class<?> sourceClass = object.getClass(); if (targetClass == null || targetClass.isAssignableFrom(sourceClass)) { return (java.util.Date) object; } else if (targetClass.equals(Date.class)) { return toDate(object); } else if (targetClass.equals(Time.class)) { return toTime(object); } else if (targetClass.equals(Timestamp.class)) { return toTimestamp(object); } else { return (java.util.Date) object; } }
From source file:org.openmrs.module.restrictbyrole.RoleRestrictionValidator.java
public boolean supports(Class c) { return c.equals(RoleRestriction.class); }