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.aosa.main.utils.tools.AOSACopyUtil.java

/**
 * Description<code>Copy properties of orig to dest Exception the Entity and Collection Type</code>      <br>
 * By mutou at 2011-8-30 ?11:35:29   <br>
 * Object      <br>/*ww w. jav a2s.c om*/
 * @param dest
 * @param orig
 * @return the dest bean
 * @throws
 */
@SuppressWarnings("rawtypes")
public static Object copyProperties(Object dest, Object orig) {
    if (dest == null || orig == null) {
        return dest;
    }
    PropertyDescriptor[] destDesc = PropertyUtils.getPropertyDescriptors(dest);
    try {
        for (int i = 0; i < destDesc.length; i++) {
            Class destType = destDesc[i].getPropertyType();
            Class origType = PropertyUtils.getPropertyType(orig, destDesc[i].getName());
            if (destType != null && destType.equals(origType) && !destType.equals(Class.class)) {
                if (!Collection.class.isAssignableFrom(origType)) {
                    try {
                        Object value = PropertyUtils.getProperty(orig, destDesc[i].getName());
                        PropertyUtils.setProperty(dest, destDesc[i].getName(), value);
                    } catch (Exception ex) {
                    }
                }
            }
        }
        return dest;
    } catch (Exception ex) {
        throw new AOSARuntimeException(ex);
    }
}

From source file:com.aosa.main.utils.tools.AOSACopyUtil.java

/**
 * Description<code>Copy properties of orig to dest Exception the Entity and Collection Type</code>      <br>
 * By mutou at 2011-8-30 ?11:36:11   <br>
 * Object      <br>/*from  w  w  w  .j  ava  2s . c  o  m*/
 * @param dest
 * @param orig
 * @param ignores
 * @return the dest bean
 * @throws
 */
@SuppressWarnings("rawtypes")
public static Object copyProperties(Object dest, Object orig, String[] ignores) {
    if (dest == null || orig == null) {
        return dest;
    }

    PropertyDescriptor[] destDesc = PropertyUtils.getPropertyDescriptors(dest);
    try {
        for (int i = 0; i < destDesc.length; i++) {
            if (contains(ignores, destDesc[i].getName())) {
                continue;
            }
            Class destType = destDesc[i].getPropertyType();
            Class origType = PropertyUtils.getPropertyType(orig, destDesc[i].getName());
            if (destType != null && destType.equals(origType) && !destType.equals(Class.class)) {
                if (!Collection.class.isAssignableFrom(origType)) {
                    Object value = PropertyUtils.getProperty(orig, destDesc[i].getName());
                    PropertyUtils.setProperty(dest, destDesc[i].getName(), value);
                }
            }
        }
        return dest;
    } catch (Exception ex) {
        throw new AOSARuntimeException(ex);
    }
}

From source file:org.geoserver.wps.process.GeoServerProcessors.java

/**
 * Returns the process factory instance corresponding to the specified class. 
 * @param factoryClass The factory to look for
 * @param applyFilters Whether to apply the registered {@link ProcessFilter} instances, or not
 * @return//from   w w  w. j  ava  2  s  . c o m
 */
public static ProcessFactory getProcessFactory(Class factoryClass, boolean applyFilters) {
    Set<ProcessFactory> factories = Processors.getProcessFactories();
    for (ProcessFactory pf : factories) {
        if (factoryClass.equals(pf.getClass())) {
            if (!applyFilters) {
                return pf;
            } else {
                // scan filters and let them wrap as necessary
                pf = applyFilters(pf);

                return pf;
            }
        }
    }

    // not found
    return null;
}

From source file:nz.co.senanque.validationengine.ConvertUtils.java

public static Object convertToObject(Class<?> clazz) {
    if (clazz.isPrimitive()) {
        if (clazz.equals(Long.TYPE)) {
            return new Long(0L);
        } else if (clazz.equals(Integer.TYPE)) {
            return new Integer(0);
        } else if (clazz.equals(Float.TYPE)) {
            return new Float(0F);
        } else if (clazz.equals(Double.TYPE)) {
            return new Double(0D);
        } else if (clazz.equals(Boolean.TYPE)) {
            return new Boolean(false);
        }//from w w  w. j  av  a 2s.  c om
    }
    return null;

}

From source file:GenericsUtil.java

/**
 * Returns the class defined for the type variable
 * of the given name. /*from w  w w  .  ja  v  a  2  s  . c o  m*/
 * @param clazz the class
 * @param genericClazz the generic class or interface to check the type for
 * @param name the name of the type variable
 * @param recursive whether or not to recurse up the
 * object's inheritance hierarchy.
 * @return the class
 */
public static Class<?> getTypeVariableClassByName(Class<?> clazz, Type genericClazz, String name,
        Boolean recursive) {

    // we hit the end of the line here :)
    if (clazz == null || clazz.equals(Object.class)) {
        return null;
    }

    // loop through all of the types implemented
    for (ParameterizedType pType : getGenericTypes(clazz)) {

        // do all of them, or one of them
        if (genericClazz == null || genericClazz.equals(pType.getRawType())) {

            // get super class type variables
            TypeVariable<?>[] typeVars = getGenericTypeParameters(clazz, pType.getRawType());
            for (int i = 0; i < typeVars.length; i++) {
                if ((genericClazz == null || genericClazz.equals(typeVars[i].getGenericDeclaration()))
                        && typeVars[i].getName().equals(name)) {

                    // get the type
                    Type type = pType.getActualTypeArguments()[i];

                    if (Class.class.isAssignableFrom(type.getClass())) {
                        return (Class<?>) type;
                    } else if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
                        return (Class<?>) ((ParameterizedType) type).getRawType();
                    }
                }
            }

        }

    }

    // none found
    return (recursive) ? getTypeVariableClassByName(clazz.getSuperclass(), genericClazz, name, recursive)
            : null;
}

From source file:io.orchestrate.client.ResponseConverterUtil.java

@SuppressWarnings("unchecked")
public static <T> T jsonToDomainObject(ObjectMapper mapper, JsonNode json, Class<T> clazz) throws IOException {
    if (clazz == null || clazz == Void.class || json == null || json.isNull()) {
        return null;
    }/*from w w  w.  j  a v a2 s. c  o  m*/

    if (clazz.equals(String.class)) {
        return (T) mapper.writeValueAsString(json);
    }
    return mapper.treeToValue(json, clazz);
}

From source file:Main.java

/**
 * Reads a <code>Paint</code> object that has been serialised by the
 * {@link SerialUtilities#writePaint(Paint, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The paint object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 *///from w  w w .  j  av a2 s.c o  m
public static Paint readPaint(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Paint result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (isSerializable(c)) {
            result = (Paint) stream.readObject();
        } else if (c.equals(GradientPaint.class)) {
            final float x1 = stream.readFloat();
            final float y1 = stream.readFloat();
            final Color c1 = (Color) stream.readObject();
            final float x2 = stream.readFloat();
            final float y2 = stream.readFloat();
            final Color c2 = (Color) stream.readObject();
            final boolean isCyclic = stream.readBoolean();
            result = new GradientPaint(x1, y1, c1, x2, y2, c2, isCyclic);
        }
    }
    return result;

}

From source file:net.mojodna.sprout.support.SproutUtils.java

/**
 * Gets a collection of methods declared in a specified range of a given
 * class' hierarchy.// w w w .  j av a2 s .  co  m
 * 
 * @param clazz Class to inspect.
 * @param upto Methods declared in this class and its subclasses will be
 * included.  Any methods declared in superclasses will be ignored.
 * @return Collection of methods declared within the specified range.
 */
public static Collection<Method> getDeclaredMethods(Class clazz, final Class upto) {
    // collect methods to register (include methods for all classes up to and including this one)
    final Collection<Method> methods = new ArrayList();
    while (!clazz.equals(upto.getSuperclass())) {
        methods.addAll(Arrays.asList(clazz.getDeclaredMethods()));
        clazz = clazz.getSuperclass();
    }

    return methods;
}

From source file:de.dfki.iui.mmds.dialogue.SiamContext.java

static boolean areMatchingClassTypes(Class clazz1, Class clazz2) {
    clazz1 = wrap(clazz1);//  w ww .ja  va  2 s .  c  o  m
    clazz2 = wrap(clazz2);
    return clazz1.equals(clazz2);
}

From source file:hu.bme.mit.sette.tools.spf.SpfGenerator.java

static String getParameterLiteral(Class<?> javaClass) {
    if (javaClass.isPrimitive()) {
        javaClass = ClassUtils.primitiveToWrapper(javaClass);
    }// ww w.j av  a2 s.c  o  m

    if (javaClass.equals(Byte.class)) {
        return "(byte) 1";
    } else if (javaClass.equals(Short.class)) {
        return "(short) 1";
    } else if (javaClass.equals(Integer.class)) {
        return "1";
    } else if (javaClass.equals(Long.class)) {
        return "1L";
    } else if (javaClass.equals(Float.class)) {
        return "1.0f";
    } else if (javaClass.equals(Double.class)) {
        return "1.0";
    } else if (javaClass.equals(Boolean.class)) {
        return "false";
    } else if (javaClass.equals(Character.class)) {
        return "' '";
    } else {
        return "null";
    }
}