Example usage for java.lang Class equals

List of usage examples for java.lang Class equals

Introduction

In this page you can find the example usage for java.lang Class 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.jsen.javascript.java.HostedJavaObject.java

public static Object wrap(Class<?> type, Object value) {
    if (type.equals(JsCallback.class) && value instanceof Function) {
        value = new FunctionJsCallbackAdapter((Function) value);
    } /* else if (type.equals(EventHandler.class) && value instanceof Function) {
        value = new FunctionEventHandlerAdapter((Function)value);
      } else if (type.equals(OnErrorEventHandler.class) && value instanceof Function) {
        value = new FunctionOnErrorEventHandlerAdapter((Function)value);
      } else if (type.equals(StateObject.class) && value instanceof Object) {
        value = new StateObject(value);/*from www .j  a  va2s.c o  m*/
      }*/

    return value;
}

From source file:Main.java

public static long JavaToUnoType(Object obj, long fallbackTypePtr, boolean typeHasFallbackClass)
        throws ClassNotFoundException {
    Class<?> firstCls = obj.getClass();
    Long unoTypePtr = unoTypes.get(firstCls.getName());
    if (unoTypePtr != null) {
        return (long) unoTypePtr;
    } else {/*from  ww w  .ja v a 2s . c om*/
        if (typeHasFallbackClass) {
            Class<?> itf = unoFallbacks.get(fallbackTypePtr);
            if (itf == null) {
                throw new ClassNotFoundException(
                        "BINDING CLASS NOT FOUND (unoFallbacks): Not found for unoTypePtr:" + fallbackTypePtr);
            }
            Class<?> currentCls = firstCls;
            while (true) {
                if ((!itf.equals(currentCls)) && itf.isAssignableFrom(currentCls)) {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        unoTypes.put(firstCls.getName(), potential);
                        return (long) potential;
                    }
                } else {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                }
            }
        } else {
            Class<?> currentCls = firstCls;
            while (true) {
                currentCls = currentCls.getSuperclass();
                if (currentCls == null) {
                    unoTypes.put(firstCls.getName(), fallbackTypePtr);
                    return fallbackTypePtr;
                } else {
                    Long potential = unoTypes.get(currentCls.getName());
                    if (potential != null) {
                        if (Modifier.isAbstract(currentCls.getModifiers())) {
                            Long fallbackClassPtr = unoFallbacksClassToPtr.get(currentCls);
                            if (fallbackClassPtr != null) {
                                unoTypes.put(firstCls.getName(), fallbackClassPtr);
                                return fallbackClassPtr;
                            }
                        } else {
                            unoTypes.put(firstCls.getName(), potential);
                            return (long) potential;
                        }
                    }
                }
            }
        }
    }
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }/*www  .  j a  v a 2  s .co m*/
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:at.treedb.backup.Import.java

private static boolean ignoreClass(Class<?> c) {
    if (Modifier.isAbstract(c.getModifiers()) || c.equals(DBFSblock.class) || c.equals(DBinfo.class)) {
        return true;
    }//  ww w .j av  a  2 s  . c  o  m
    return false;
}

From source file:Main.java

public static Type[] getGenericType(Class<?> clazz, Class<?> interfaceClazz) {
    Type st = clazz.getGenericSuperclass();
    Type[] ret = getActualTypeArguments(interfaceClazz, st);

    if (ret != null)
        return ret;

    for (Type t : clazz.getGenericInterfaces()) {
        ret = getActualTypeArguments(interfaceClazz, t);
        if (ret != null)
            return ret;
    }/*from  ww w.  j  a  v a 2 s .  c om*/

    Class<?> s = clazz.getSuperclass();
    if (s == null || clazz.equals(s.getClass()))
        return new Type[0];

    return getGenericType(s, interfaceClazz);
}

From source file:com.opensource.frameworks.processframework.utils.MethodInvoker.java

/**
 * Algorithm that judges the match between the declared parameter types of a candidate method
 * and a specific list of arguments that this method is supposed to be invoked with.
 * <p>Determines a weight that represents the class hierarchy difference between types and
 * arguments. A direct match, i.e. type Integer -> arg of class Integer, does not increase
 * the result - all direct matches means weight 0. A match between type Object and arg of
 * class Integer would increase the weight by 2, due to the superclass 2 steps up in the
 * hierarchy (i.e. Object) being the last one that still matches the required type Object.
 * Type Number and class Integer would increase the weight by 1 accordingly, due to the
 * superclass 1 step up the hierarchy (i.e. Number) still matching the required type Number.
 * Therefore, with an arg of type Integer, a constructor (Integer) would be preferred to a
 * constructor (Number) which would in turn be preferred to a constructor (Object).
 * All argument weights get accumulated.
 * @param paramTypes the parameter types to match
 * @param args the arguments to match/*www.  j  a  v a 2s  .  c o m*/
 * @return the accumulated weight for all arguments
 */
public static int getTypeDifferenceWeight(Class[] paramTypes, Object[] args) {
    int result = 0;
    for (int i = 0; i < paramTypes.length; i++) {
        if (!ClassUtils.isAssignableValue(paramTypes[i], args[i])) {
            return Integer.MAX_VALUE;
        }
        if (args[i] != null) {
            Class paramType = paramTypes[i];
            Class superClass = args[i].getClass().getSuperclass();
            while (superClass != null) {
                if (paramType.equals(superClass)) {
                    result = result + 2;
                    superClass = null;
                } else if (ClassUtils.isAssignable(paramType, superClass)) {
                    result = result + 2;
                    superClass = superClass.getSuperclass();
                } else {
                    superClass = null;
                }
            }
            if (paramType.isInterface()) {
                result = result + 1;
            }
        }
    }
    return result;
}

From source file:org.fastmongo.odm.util.ReflectionUtils.java

/**
 * Attempt to find a {@link Field field} on the supplied {@link Class} with the
 * supplied {@code name} and/or {@link Class type}. Searches all superclasses
 * up to {@link Object}./*from  w  w w .  ja  va 2s.co m*/
 *
 * @param clazz the class to introspect
 * @param name  the name of the field (may be {@code null} if type is specified)
 * @param type  the type of the field (may be {@code null} if name is specified)
 * @return the corresponding Field object, or {@code null} if not found
 */
public static Field findField(Class<?> clazz, String name, Class<?> type) {
    Class<?> searchType = clazz;
    while (!Object.class.equals(searchType) && searchType != null) {
        Field[] fields = searchType.getDeclaredFields();
        for (Field field : fields) {
            if ((name == null || name.equals(field.getName()))
                    && (type == null || type.equals(field.getType()))) {
                return field;
            }
        }
        searchType = searchType.getSuperclass();
    }
    return null;
}

From source file:at.alladin.rmbt.shared.hstoreparser.HstoreParser.java

/**
 * //  ww w  .j a  v a2  s  .  c o m
 * @param json
 * @param key
 * @param toField
 * @return
 * @throws JSONException
 */
public static Object getFromJsonByField2(JSONObject json, String key, Field toField) throws JSONException {
    final Object o = json.get(key);
    final Class<?> fieldType = toField.getType();
    if (o != JSONObject.NULL) {
        if (fieldType.equals(Integer.class) || fieldType.equals(Integer.TYPE)) {
            return json.getInt(key);
        } else if (fieldType.equals(String.class)) {
            return o;
        } else if (fieldType.equals(Long.class) || fieldType.equals(Long.TYPE)) {
            return json.getLong(key);
        } else if (fieldType.equals(Boolean.class) || fieldType.equals(Boolean.TYPE)) {
            return json.getBoolean(key);
        } else if (fieldType.equals(Float.class) || fieldType.equals(Float.TYPE)) {
            return (float) json.getDouble(key);
        } else if (fieldType.equals(Double.class) || fieldType.equals(Double.TYPE)) {
            return json.getDouble(key);
        } else {
            return o;
        }
    }

    return JSONObject.NULL;
}

From source file:com.none.tom.simplerssreader.utils.SharedPrefUtils.java

@SuppressWarnings("unchecked")
public static <T> T get(final Context context, final String key, final Class<T> clazz) {
    if (clazz.equals(String.class)) {
        return (T) getSharedPreferences(context).getString(key, null);
    }/*  www.j av a2  s.c o  m*/
    return (T) (Integer) getSharedPreferences(context).getInt(key, 0);
}

From source file:com.github.valdr.thirdparty.spring.AnnotationUtils.java

/**
 * Find the first {@link Class} in the inheritance hierarchy of the specified {@code clazz}
 * (including the specified {@code clazz} itself) which declares an annotation for the
 * specified {@code annotationType}, or {@code null} if not found. If the supplied
 * {@code clazz} is {@code null}, {@code null} will be returned.
 * <p>If the supplied {@code clazz} is an interface, only the interface itself will be checked;
 * the inheritance hierarchy for interfaces will not be traversed.
 * <p>The standard {@link Class} API does not provide a mechanism for determining which class
 * in an inheritance hierarchy actually declares an {@link java.lang.annotation.Annotation}, so we need to handle
 * this explicitly.//from   w w w .  ja v a  2s .  c o m
 * @param annotationType the Class object corresponding to the annotation type
 * @param clazz the Class object corresponding to the class on which to check for the annotation,
 * or {@code null}
 * @return the first {@link Class} in the inheritance hierarchy of the specified {@code clazz}
 * which declares an annotation for the specified {@code annotationType}, or {@code null}
 * if not found
 * @see Class#isAnnotationPresent(Class)
 * @see Class#getDeclaredAnnotations()
 * @see #findAnnotationDeclaringClassForTypes(java.util.List, Class)
 * @see #isAnnotationDeclaredLocally(Class, Class)
 */
public static Class<?> findAnnotationDeclaringClass(Class<? extends Annotation> annotationType,
        Class<?> clazz) {
    if (clazz == null || clazz.equals(Object.class)) {
        return null;
    }
    return (isAnnotationDeclaredLocally(annotationType, clazz)) ? clazz
            : findAnnotationDeclaringClass(annotationType, clazz.getSuperclass());
}