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

/**
 * Reads a <code>Stroke</code> object that has been serialised by the
 * {@link SerialUtilities#writeStroke(Stroke, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The stroke object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 */// w w w . java2s .co  m
public static Stroke readStroke(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Stroke result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(BasicStroke.class)) {
            final float width = stream.readFloat();
            final int cap = stream.readInt();
            final int join = stream.readInt();
            final float miterLimit = stream.readFloat();
            final float[] dash = (float[]) stream.readObject();
            final float dashPhase = stream.readFloat();
            result = new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
        } else {
            result = (Stroke) stream.readObject();
        }
    }
    return result;

}

From source file:Main.java

/**
 * Searches for ofClass in the inherited classes and interfaces of inClass. If ofClass has been found in the super
 * classes/interfaces of inClass, then the generic type corresponding to inClass and its TypeVariables is returned,
 * otherwise null. For example ://w  w w.  ja v  a  2 s  . co m
 * 
 * <pre>
 * abstract class MyClass implements Serializer&lt;Number&gt; {
 * 
 * }
 * 
 * // type value will be the parameterized type Serializer&lt;Number&gt;
 * Type type = lookupGenericType(Serializer.class, MyClass.class);
 * </pre>
 */
public final static Type lookupGenericType(Class<?> ofClass, Class<?> inClass) {
    if (ofClass == null || inClass == null || !ofClass.isAssignableFrom(inClass))
        return null;
    if (ofClass.equals(inClass))
        return inClass;

    if (ofClass.isInterface()) {
        // lets look if the interface is directly implemented by fromClass
        Class<?>[] interfaces = inClass.getInterfaces();

        for (int i = 0; i < interfaces.length; i++) {
            // do they match?
            if (ofClass.equals(interfaces[i])) {
                return inClass.getGenericInterfaces()[i];
            } else {
                Type superType = lookupGenericType(ofClass, interfaces[i]);
                if (superType != null)
                    return superType;
            }
        }
    }

    // ok it's not one of the directly implemented interfaces, lets try extended class
    Class<?> superClass = inClass.getSuperclass();
    if (ofClass.equals(superClass))
        return inClass.getGenericSuperclass();
    return lookupGenericType(ofClass, inClass.getSuperclass());
}

From source file:io.twipple.springframework.data.clusterpoint.convert.support.ConversionUtils.java

/**
 * Check if the left class is a subtype of the right.
 *
 * @param left  the first class./* w w  w.  j a  v  a2s  . co m*/
 * @param right the second class.
 * @return true if it is a subtype, false otherwise.
 */
public static boolean isSubtype(@NotNull Class<?> left, @NotNull Class<?> right) {

    Assert.notNull(left);
    Assert.notNull(right);

    return left.isAssignableFrom(right) && !left.equals(right);
}

From source file:com.android.volley.VolleyLog.java

/**
 * Formats the caller's provided message and prepends useful info like
 * calling thread ID and method name./*from   w ww  . j a va  2 s  .  co  m*/
 */
private static String buildMessage(String format, Object... args) {
    String msg = (args == null) ? format : String.format(Locale.US, format, args);
    StackTraceElement[] trace = new Throwable().fillInStackTrace().getStackTrace();

    String caller = "<unknown>";
    // Walk up the stack looking for the first caller outside of VolleyLog.
    // It will be at least two frames up, so start there.
    for (int i = 2; i < trace.length; i++) {
        Class<?> clazz = trace[i].getClass();
        if (!clazz.equals(VolleyLog.class)) {
            String callingClass = trace[i].getClassName();
            callingClass = callingClass.substring(callingClass.lastIndexOf('.') + 1);
            callingClass = callingClass.substring(callingClass.lastIndexOf('$') + 1);

            caller = callingClass + "." + trace[i].getMethodName();
            break;
        }
    }
    return String.format(Locale.US, "[%d] %s: %s", Thread.currentThread().getId(), caller, msg);
}

From source file:com.hybris.mobile.utility.JsonUtils.java

/**
 * Return the Type associated to the Class
 * /*from   w  ww. j a  v  a 2  s . c  o m*/
 * @param <T>
 * 
 * @param className
 * @return
 */
private static <T> Type getAssociatedTypeFromClass(Class<T> className) {
    Type listType = null;

    if (className.equals(CartEntry.class)) {
        listType = new TypeToken<List<CartEntry>>() {
        }.getType();
    } else if (className.equals(Facet.class)) {
        listType = new TypeToken<List<Facet>>() {
        }.getType();
    } else if (className.equals(GenericNameCode.class)) {
        listType = new TypeToken<List<GenericNameCode>>() {
        }.getType();
    } else if (className.equals(GenericValue.class)) {
        listType = new TypeToken<List<GenericValue>>() {
        }.getType();
    } else if (className.equals(CartDeliveryMode.class)) {
        listType = new TypeToken<List<CartDeliveryMode>>() {
        }.getType();
    } else if (className.equals(CartPaymentInfo.class)) {
        listType = new TypeToken<List<CartPaymentInfo>>() {
        }.getType();
    } else if (className.equals(CartDeliveryAddress.class)) {
        listType = new TypeToken<List<CartDeliveryAddress>>() {
        }.getType();
    }

    return listType;
}

From source file:com.smartitengineering.util.bean.BeanFactoryRegistrar.java

private static boolean aggregate(Class<? extends Object> aggregatorClass, Object aggregator)
        throws SecurityException {
    if (aggregatorClass.equals(Object.class)) {
        return true;
    }//from  ww  w .  java2 s.  c  o m
    Class<? extends Object> superClass = aggregatorClass.getSuperclass();
    if (superClass != null) {
        aggregate(superClass, aggregator);
    }
    Aggregator aggregatorAnnotation = aggregatorClass.getAnnotation(Aggregator.class);
    if (aggregatorAnnotation == null || StringUtils.isBlank(aggregatorAnnotation.contextName())) {
        return true;
    }
    BeanFactory beanFactory = getBeanFactorForContext(aggregatorAnnotation.contextName());
    if (beanFactory == null) {
        return true;
    }
    Field[] declaredFields = aggregatorClass.getDeclaredFields();
    for (Field declaredField : declaredFields) {
        InjectableField injectableField = declaredField.getAnnotation(InjectableField.class);
        if (injectableField == null) {
            continue;
        }
        String beanName = StringUtils.isBlank(injectableField.beanName()) && beanFactory.isNameMandatory()
                ? declaredField.getName()
                : injectableField.beanName();
        if (StringUtils.isBlank(beanName) && beanFactory.isNameMandatory()) {
            return true;
        }
        try {
            declaredField.setAccessible(true);
            final Class<?> fieldType = declaredField.getType();
            if (beanFactory.containsBean(beanName, fieldType)) {
                declaredField.set(aggregator, beanFactory.getBean(beanName, fieldType));
            }
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch (IllegalAccessException ex) {
            ex.printStackTrace();
        }

    }
    return false;
}

From source file:de.thischwa.pmcms.server.ContextUtil.java

public static String getTypDescriptor(final Class<?> clazz) {
    if (clazz.equals(Page.class))
        return Constants.LINK_TYPE_PAGE;
    if (clazz.equals(Gallery.class))
        return Constants.LINK_TYPE_GALLERY;
    if (clazz.equals(Image.class))
        return Constants.LINK_TYPE_IMAGE;
    if (clazz.equals(Macro.class))
        return Constants.LINK_TYPE_MACRO;
    if (clazz.equals(Template.class))
        return Constants.LINK_TYPE_TEMPLATE;
    throw new IllegalArgumentException("Unknown pojo class: " + clazz.getSimpleName());
}

From source file:ait.ffma.utils.KeyAndFrequency.java

public static KeyAndFrequency fromJson(JSONObject obj, Class clazz) {
    try {/*from w  ww .  ja  va2s.co  m*/
        if (clazz.equals(Integer.class)) {
            KeyAndFrequency kf = new KeyAndFrequency(obj.getInt(KEY_FLD), obj.getInt(FREQ_FLD));
            return kf;
        }
        if (clazz.equals(String.class)) {
            KeyAndFrequency kf = new KeyAndFrequency(obj.get(KEY_FLD), obj.getInt(FREQ_FLD));
            return kf;
        }

        if (clazz.equals(Date.class)) {
            KeyAndFrequency kf = null;
            try {

                kf = new KeyAndFrequency(format.parse(obj.getString(KEY_FLD)), obj.getInt(FREQ_FLD));
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return kf;
        }
    } catch (JSONException e) {

    }
    return null;
}

From source file:bs.java

private static void loadable(String filename) {
    File file = new File(filename);

    JarInputStream is;/*from  w  w w. java  2s  .  com*/
    try {
        ClassLoader loader = URLClassLoader.newInstance(new URL[] { file.toURI().toURL() });
        is = new JarInputStream(new FileInputStream(file));
        JarEntry entry;
        while ((entry = is.getNextJarEntry()) != null) {
            if (entry.getName().endsWith(".class") && !entry.getName().contains("/")) {
                Class<?> cls = Class.forName(FilenameUtils.removeExtension(entry.getName()), false, loader);
                for (Class<?> i : cls.getInterfaces()) {
                    if (i.equals(Loadable.class)) {
                        Loadable l = (Loadable) cls.newInstance();
                        Bs.addModule(l);
                    }
                }
            }
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }

}

From source file:org.grails.datastore.mapping.reflect.ReflectionUtils.java

private static boolean isTypeInstanceOfPropertyType(Class<?> type, Class<?> propertyType) {
    return propertyType.isAssignableFrom(type) && !propertyType.equals(Object.class);
}