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:fi.foyt.foursquare.api.JSONFieldParser.java

/**
 * Returns whether class is derived from FoursquareEntity interface
 * //from ww w  .  j a v  a 2 s .com
 * @param clazz class
 * @return whether class is derived from FoursquareEntity interface
 */
private static boolean isFoursquareEntity(Class<?> clazz) {
    for (Class<?> intrf : clazz.getInterfaces()) {
        if (intrf.equals(FoursquareEntity.class)) {
            return true;
        }
    }

    Class<?> superClass = clazz.getSuperclass();
    if (!superClass.equals(Object.class)) {
        return isFoursquareEntity(superClass);
    }

    return false;
}

From source file:net.lightbody.bmp.proxy.jetty.util.TypeUtil.java

/** Convert String value to instance.
 * @param type The class of the instance, which may be a primitive TYPE field.
 * @param value The value as a string.//from  www . ja  v a  2s  . c  o m
 * @return The value as an Object.
 */
public static Object valueOf(Class type, String value) {
    try {
        if (type.equals(java.lang.String.class))
            return value;

        Method m = (Method) class2Value.get(type);
        if (m != null)
            return m.invoke(null, new Object[] { value });

        if (type.equals(java.lang.Character.TYPE) || type.equals(java.lang.Character.class))
            return new Character(value.charAt(0));

        Constructor c = type.getConstructor(stringArg);
        return c.newInstance(new Object[] { value });
    } catch (NoSuchMethodException e) {
        LogSupport.ignore(log, e);
    } catch (IllegalAccessException e) {
        LogSupport.ignore(log, e);
    } catch (InstantiationException e) {
        LogSupport.ignore(log, e);
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof Error)
            throw (Error) (e.getTargetException());
        LogSupport.ignore(log, e);
    }
    return null;
}

From source file:com.bloatit.framework.webprocessor.url.Loaders.java

private @SuppressWarnings({ "unchecked", "synthetic-access", "rawtypes" }) static <T> Loader<T> getLoader(
        final Class<T> theClass) {
    if (theClass.equals(Integer.class)) {
        return (Loader<T>) new ToInteger();
    }// www  .ja  v  a2s.c om
    if (theClass.equals(Byte.class)) {
        return (Loader<T>) new ToByte();
    }
    if (theClass.isEnum()) {
        return new ToEnum(theClass);
    }
    if (theClass.equals(Short.class)) {
        return (Loader<T>) new ToShort();
    }
    if (theClass.equals(Long.class)) {
        return (Loader<T>) new ToLong();
    }
    if (theClass.equals(Float.class)) {
        return (Loader<T>) new ToFloat();
    }
    if (theClass.equals(Double.class)) {
        return (Loader<T>) new ToDouble();
    }
    if (theClass.equals(Character.class)) {
        return (Loader<T>) new ToCharacter();
    }
    if (theClass.equals(Boolean.class)) {
        return (Loader<T>) new ToBoolean();
    }
    if (theClass.equals(BigDecimal.class)) {
        return (Loader<T>) new ToBigdecimal();
    }
    if (theClass.equals(String.class)) {
        return (Loader<T>) new ToString();
    }
    if (theClass.equals(Locale.class)) {
        return (Loader<T>) new ToLocale();
    }
    if (theClass.equals(Date.class)) {
        return (Loader<T>) new ToDate();
    }
    if (Commentable.class.equals(theClass)) {
        return (Loader<T>) new ToCommentable();
    }
    if (theClass.equals(DateLocale.class)) {
        return (Loader<T>) new ToBloatitDate();
    }
    if (IdentifiableInterface.class.isAssignableFrom(theClass)) {
        return new ToIdentifiable(theClass);
    }
    if (WebProcess.class.isAssignableFrom(theClass)) {
        return new ToWebProcess();
    }
    throw new NotImplementedException("Cannot find a conversion class for: " + theClass);
}

From source file:com.hazelcast.simulator.test.TestContainer.java

private static void assertFieldType(Class fieldType, Class expectedFieldType,
        Class<? extends Annotation> annotation) {
    if (!expectedFieldType.equals(fieldType)) {
        throw new IllegalTestException(format("Found %s annotation on field of type %s, but %s is required!",
                annotation.getName(), fieldType.getName(), expectedFieldType.getName()));
    }/*from   ww  w  .  jav a  2  s .  com*/
}

From source file:fi.foyt.foursquare.api.JSONFieldParser.java

/**
 * Returns field of class//from www .  ja v  a  2s  .c o m
 * 
 * @param entityClass class
 * @param fieldName field
 * @return Field
 */
private static Field getField(Class<?> entityClass, String fieldName) {
    try {
        Field field = entityClass.getDeclaredField(fieldName);
        field.setAccessible(true);
        return field;
    } catch (SecurityException e) {
        return null;
    } catch (NoSuchFieldException e) {
        Class<?> superClass = entityClass.getSuperclass();
        if (superClass.equals(Object.class)) {
            return null;
        } else {
            return getField(superClass, fieldName);
        }
    }
}

From source file:com.jilk.ros.rosbridge.implementation.JSON.java

public static Object convertJSONPrimitiveToPrimitive(Object o, Class c) {
    Object result = o;//from   w  ww. j  ava 2s.  co  m
    if (c.isPrimitive() || Number.class.isAssignableFrom(c)) {
        if (c.equals(double.class) || c.equals(Double.class))
            result = new Double(((Number) o).doubleValue());
        else if (c.equals(float.class) || c.equals(Float.class))
            result = new Float(((Number) o).floatValue());
        else if (c.equals(long.class) || c.equals(Long.class))
            result = new Long(((Number) o).longValue());
        else if (int.class.equals(c) || c.equals(Integer.class))
            result = new Integer(((Number) o).intValue());
        else if (c.equals(short.class) || c.equals(Short.class))
            result = new Short(((Number) o).shortValue());
        else if (c.equals(byte.class) || c.equals(Byte.class))
            result = new Byte(((Number) o).byteValue());
    }
    return result;
}

From source file:com.expressui.core.util.SpringApplicationContext.java

/**
 * Finds a single bean of a given type and whose class is declared with given generic argument type.
 *
 * @param type                type to search for
 * @param genericArgumentType generic argument type declared on the bean
 * @param <T>                 type to query
 * @return found bean or null if not found
 *//*from   w  w w  .ja va  2  s  .  com*/
public static <T> T getBeanByTypeAndGenericArgumentType(Class<T> type, Class genericArgumentType) {
    Set<T> beans = getBeansByType(type);

    T foundBean = null;
    for (T bean : beans) {
        Class argType = ReflectionUtil.getGenericArgumentType(bean.getClass());
        if (argType != null && genericArgumentType.equals(argType)) {
            if (foundBean == null) {
                foundBean = bean;
            } else {
                return null;
            }
        }
    }

    return foundBean;
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

/**
 * @param value/*  w  w w.  ja v a 2  s.co  m*/
 * @param f
 * @return
 */
public static ByteBuffer toBytes(Object value, Class<?> clazz) {
    if (clazz.isAssignableFrom(String.class)) {
        return UTF8Type.instance.decompose((String) value);
    } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) {
        return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
    } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) {
        return LongType.instance.decompose(Long.parseLong(value.toString()));
    } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) {
        return BooleanType.instance.decompose(Boolean.valueOf(value.toString()));
    } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) {
        return DoubleType.instance.decompose(Double.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(java.util.UUID.class)) {
        return UUIDType.instance.decompose(UUID.fromString(value.toString()));
    } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) {
        return FloatType.instance.decompose(Float.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(Date.class)) {
        DateAccessor dateAccessor = new DateAccessor();
        return DateType.instance.decompose((Date) value);
    } else {
        if (value.getClass().isAssignableFrom(String.class)) {
            value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString());
        }
        return BytesType.instance
                .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(value)));
    }
}

From source file:kelly.util.BeanUtils.java

/**
 * Check if the given type represents a "simple" value type:
 * a primitive, a String or other CharSequence, a Number, a Date,
 * a URI, a URL, a Locale or a Class./*from   ww  w.ja va 2  s.c o  m*/
 * @param clazz the type to check
 * @return whether the given type represents a "simple" value type
 */
public static boolean isSimpleValueType(Class<?> clazz) {
    return isPrimitiveOrWrapper(clazz) || clazz.isEnum() || CharSequence.class.isAssignableFrom(clazz)
            || Number.class.isAssignableFrom(clazz) || Date.class.isAssignableFrom(clazz)
            || clazz.equals(URI.class) || clazz.equals(URL.class) || clazz.equals(Locale.class)
            || clazz.equals(Class.class);
}

From source file:com.marklogic.mapreduce.utilities.InternalUtilities.java

/**
 * Assign value in Writable type from XCC result item.
 * @param <VALUEIN>//w  ww .  j  a  v a 2s  . co m
 * @param valueClass
 * @param result
 * @param value
 */
public static <VALUEIN> void assignResultValue(Class<? extends Writable> valueClass, ResultItem result,
        VALUEIN value) {
    if (valueClass.equals(Text.class)) {
        ((Text) value).set(result.asString());
    } else if (valueClass.equals(IntWritable.class) && result.getValueType() == ValueType.XS_INTEGER) {
        XSInteger intItem = (XSInteger) result.getItem();
        ((IntWritable) value).set(intItem.asPrimitiveInt());
    } else if (valueClass.equals(VIntWritable.class) && result.getValueType() == ValueType.XS_INTEGER) {
        XSInteger intItem = (XSInteger) result.getItem();
        ((VIntWritable) value).set(intItem.asPrimitiveInt());
    } else if (valueClass.equals(LongWritable.class) && result.getValueType() == ValueType.XS_INTEGER) {
        XSInteger intItem = (XSInteger) result.getItem();
        ((LongWritable) value).set(intItem.asLong());
    } else if (valueClass.equals(VLongWritable.class) && result.getValueType() == ValueType.XS_INTEGER) {
        XSInteger intItem = (XSInteger) result.getItem();
        ((VLongWritable) value).set(intItem.asLong());
    } else if (valueClass.equals(BooleanWritable.class) && result.getValueType() == ValueType.XS_BOOLEAN) {
        XSBoolean boolItem = (XSBoolean) result.getItem();
        ((BooleanWritable) value).set(boolItem.asPrimitiveBoolean());
    } else if (valueClass.equals(FloatWritable.class) && result.getValueType() == ValueType.XS_FLOAT) {
        XSFloat floatItem = (XSFloat) result.getItem();
        ((FloatWritable) value).set(floatItem.asPrimitiveFloat());
    } else if (valueClass.equals(DoubleWritable.class) && result.getValueType() == ValueType.XS_DOUBLE) {
        XSDouble doubleItem = (XSDouble) result.getItem();
        ((DoubleWritable) value).set(doubleItem.asPrimitiveDouble());
    } else if (valueClass.equals(BytesWritable.class) && result.getValueType() == ValueType.XS_HEX_BINARY) {
        XSHexBinary binItem = (XSHexBinary) result.getItem();
        byte[] bytes = binItem.asBinaryData();
        ((BytesWritable) value).set(bytes, 0, bytes.length);
    } else if (valueClass.equals(BytesWritable.class) && result.getValueType() == ValueType.XS_BASE64_BINARY) {
        XSBase64Binary binItem = (XSBase64Binary) result.getItem();
        byte[] bytes = binItem.asBinaryData();
        ((BytesWritable) value).set(bytes, 0, bytes.length);
    } else if (valueClass.equals(BytesWritable.class) && result.getValueType() == ValueType.BINARY) {
        byte[] bytes = ((XdmBinary) result.getItem()).asBinaryData();
        ((BytesWritable) value).set(bytes, 0, bytes.length);
    } else if (valueClass.equals(MarkLogicNode.class) && (result.getValueType() == ValueType.NODE
            || result.getValueType() == ValueType.ELEMENT || result.getValueType() == ValueType.DOCUMENT
            || result.getValueType() == ValueType.ATTRIBUTE || result.getValueType() == ValueType.TEXT)) {
        ((MarkLogicNode) value).set(result);
    } else if (valueClass.equals(DatabaseDocument.class)) {
        ((DatabaseDocument) value).set(result);
    } else {
        throw new UnsupportedOperationException(
                "Value " + valueClass + " is unsupported for result type: " + result.getValueType());
    }
}