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:Main.java

public static Class getRemoteViewsClass(Class<? extends RemoteViews> clazz) {
    if (clazz.equals(RemoteViews.class))
        return clazz;
    Class superClass = clazz.getSuperclass();
    while (!superClass.equals(RemoteViews.class)) {
        superClass = superClass.getSuperclass();
    }//from   w  ww . j  av a  2s  .  c  om
    return superClass;
}

From source file:Main.java

private static String getTypeByClass(Class<?> type) throws Exception {
    if (type.equals(String.class)) {
        return "TEXT";
    }/*from   w  ww. j a  va 2s  .  c  o m*/
    if (type.equals(Long.class) || type.equals(Integer.class) || type.equals(long.class)
            || type.equals(Date.class)) {
        return "INTEGER";
    }
    if (type.equals(Boolean.class)) {
        return "BOOLEAN";
    }

    Exception exception = new Exception(
            CONVERSION_CLASS_NOT_FOUND_EXCEPTION.concat(" - Class: ").concat(type.toString()));
    throw exception;
}

From source file:Main.java

public static Class<?> getClassByPropertyName(Class<?> clazz, String propertyName) {
    for (Field field : clazz.getDeclaredFields()) {
        if (field.getName().equals(propertyName)) {
            return field.getType();
        }/*from  www  .j  a v a2  s.  co  m*/
    }
    Class<?> superClass = clazz.getSuperclass();
    if (!superClass.equals(Object.class)) {
        return getClassByPropertyName(superClass, propertyName);
    }
    return null;
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class)
            || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class)
            || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(Boolean.class)
            || clazz.equals(Date.class) || clazz.equals(Date.class) || clazz.equals(java.sql.Date.class)
            || clazz.isPrimitive();// www  . ja v a2s .  com
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(String.class) || clazz.equals(Integer.class) || clazz.equals(Byte.class)
            || clazz.equals(Long.class) || clazz.equals(Double.class) || clazz.equals(Float.class)
            || clazz.equals(Character.class) || clazz.equals(Short.class) || clazz.equals(Boolean.class)
            || clazz.equals(Date.class) || clazz.equals(java.util.Date.class)
            || clazz.equals(java.sql.Date.class) || clazz.isPrimitive();
}

From source file:Main.java

public static boolean isImplementInterface(Class<?> interfaceClass, Class<?> implementClass) {
    for (Class<?> subClass : implementClass.getInterfaces()) {
        if (subClass.equals(interfaceClass)) {
            return true;
        }//  w w w.  j  av a  2 s  .  c  o  m
    }
    return false;
}

From source file:Main.java

public static boolean isImplement(Class<?> clazz, Class<?> interfaceClazz) {
    if (clazz.equals(interfaceClazz))
        return true;

    Class<?>[] ifs = clazz.getInterfaces();
    for (Class<?> i : ifs) {
        if (i.equals(interfaceClazz))
            return true;
    }/*from ww  w. j a v  a2 s. c  om*/

    Class<?> s = clazz.getSuperclass();
    if (s == null || clazz.equals(s.getClass()))
        return false;

    return isImplement(s, interfaceClazz);
}

From source file:Main.java

public static boolean isBaseDateType(Field field) {
    Class<?> clazz = field.getType();
    return clazz.equals(Integer.class) || clazz.equals(int.class) || clazz.equals(Byte.class)
            || clazz.equals(byte.class) || clazz.equals(Character.class) || clazz.equals(char.class)
            || clazz.equals(Long.class) || clazz.equals(long.class) || clazz.equals(Double.class)
            || clazz.equals(double.class) || clazz.equals(Float.class) || clazz.equals(float.class)
            || clazz.equals(Short.class) || clazz.equals(short.class) || clazz.equals(Boolean.class)
            || clazz.equals(boolean.class) || clazz.equals(Date.class) || clazz.equals(java.sql.Date.class)
            || clazz.isPrimitive() || clazz.equals(String.class);
}

From source file:Main.java

public static boolean implementsInterface(Class<?> type, Class<?> interfaceType, boolean searchInSuperclasses) {
    boolean found = false;
    for (Class<?> item : type.getInterfaces()) {
        if (item.equals(interfaceType)) {
            found = true;/*from   www  . j a v  a 2 s.c o  m*/
            break;
        }
    }

    if (found) {
        return true;
    } else {
        if (searchInSuperclasses && type.getSuperclass() != null) {
            return implementsInterface(type.getSuperclass(), interfaceType, searchInSuperclasses);
        }
    }

    return false;
}

From source file:Main.java

private static Object getCursorValue(Cursor cursor, Field field, String columnName) {
    Class<?> fieldType = field.getType();

    if (fieldType.equals(int.class) || field.equals(Integer.class)) {
        return cursor.getInt(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(String.class)) {
        return cursor.getString(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(long.class) || field.equals(Long.class)) {
        return cursor.getLong(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(float.class) || field.equals(Float.class)) {
        return cursor.getFloat(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(double.class) || field.equals(Double.class)) {
        return cursor.getDouble(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(long.class) || field.equals(Long.class)) {
        return cursor.getLong(cursor.getColumnIndex(columnName));
    } else if (fieldType.equals(Date.class)) {
        long time = cursor.getLong(cursor.getColumnIndex(columnName));
        Date date = new Date(time);
        return date;
    }/*from   w  ww.j a  v  a 2  s  .c o  m*/
    return cursor.getString(cursor.getColumnIndex(columnName));
}