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.cuubez.visualizer.resource.ResourceMetaDataScanner.java

public static boolean isResource(Class<?> clazz) {

    if (Modifier.isInterface(clazz.getModifiers()) || Modifier.isAbstract(clazz.getModifiers())) {
        return false;
    }//from   ww w  .  j  av a  2s. com

    if (clazz.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) {
        return true;
    }

    Class<?> declaringClass = clazz;

    while (!declaringClass.equals(Object.class)) {
        // try a superclass
        Class<?> superclass = declaringClass.getSuperclass();
        if (superclass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) {
            return true;
        }

        // try interfaces
        Class<?>[] interfaces = declaringClass.getInterfaces();
        for (Class<?> interfaceClass : interfaces) {
            if (interfaceClass.getAnnotation(Path.class) != null && clazz.getAnnotation(Group.class) != null) {
                return true;
            }
        }
        declaringClass = declaringClass.getSuperclass();
    }
    return false;
}

From source file:com.github.rvesse.airline.model.OptionMetadata.java

/**
 * Tries to merge the option metadata together such that the child metadata
 * takes precedence. Not all options can be successfully overridden and an
 * error may be thrown in cases where merging is not possible
 * <p>/* w ww  .  j  a v  a 2s  .c o  m*/
 * The following pieces of metadata may be overridden:
 * </p>
 * <ul>
 * <li>Title</li>
 * <li>Description</li>
 * <li>Required</li>
 * <li>Hidden</li>
 * </ul>
 * 
 * @param parent
 *            Parent
 * @param child
 *            Child
 * @return Merged metadata
 */
public static OptionMetadata override(Set<String> names, OptionMetadata parent, OptionMetadata child) {
    // Cannot change option type, arity or names
    if (parent.optionType != child.optionType)
        throw new IllegalArgumentException(
                String.format("Cannot change optionType when overriding option %s", names));
    if (parent.arity != child.arity)
        throw new IllegalArgumentException(
                String.format("Cannot change arity when overriding option %s", names));
    if (!parent.options.equals(child.options))
        throw new IllegalArgumentException(
                String.format("Cannot change option names when overriding option %s", names));

    // Also cannot change the type of the option unless the change is a
    // narrowing conversion
    Class<?> parentType = parent.getJavaType();
    Class<?> childType = child.getJavaType();
    if (!parentType.equals(childType)) {
        if (!parentType.isAssignableFrom(childType)) {
            if (childType.isAssignableFrom(parentType)) {
                // A widening conversion exists but this is illegal however
                // we can give a slightly more informative error in this
                // case
                throw new IllegalArgumentException(String.format(
                        "Cannot change the Java type from %s to %s when overriding option %s as this is a widening type change - only narrowing type changes are permitted",
                        parentType, childType, names));
            } else {
                // No conversion exists
                throw new IllegalArgumentException(String.format(
                        "Cannot change the Java type from %s to %s when overriding option %s - only narrowing type changes where a valid cast exists are permitted",
                        parentType, childType, names));
            }
        }
    }

    // Check for duplicates
    boolean isDuplicate = parent == child || parent.equals(child);

    // Parent must not state it is sealed UNLESS it is a duplicate which can
    // happen when using @Inject to inject options via delegates
    if (parent.sealed && !isDuplicate)
        throw new IllegalArgumentException(
                String.format("Cannot override option %s as parent option declares it to be sealed", names));

    // Child must explicitly state that it overrides otherwise we cannot
    // override UNLESS it is the case that this is a duplicate which
    // can happen when using @Inject to inject options via delegates
    if (!child.overrides && !isDuplicate)
        throw new IllegalArgumentException(
                String.format("Cannot override option %s unless child option sets overrides to true", names));

    OptionMetadata merged;
    //@formatter:off
    merged = new OptionMetadata(child.optionType, child.options,
            child.title != null ? child.title : parent.title,
            child.description != null ? child.description : parent.description, child.arity, child.hidden,
            child.overrides, child.sealed,
            child.restrictions.size() > 0 ? child.restrictions : parent.restrictions, null);
    //@formatter:on

    // Combine both child and parent accessors - this is necessary so the
    // parsed value propagates to all classes in the hierarchy
    Set<Accessor> accessors = new LinkedHashSet<>(child.accessors);
    accessors.addAll(parent.accessors);
    merged.accessors = AirlineUtils.unmodifiableSetCopy(accessors);
    return merged;
}

From source file:org.synyx.hades.util.ClassUtils.java

/**
 * Returns the number of occurences of the given type in the given
 * {@link Method}s parameters.//w  w  w.j  a  v  a  2 s. co  m
 * 
 * @param method
 * @param type
 * @return
 */
public static int getNumberOfOccurences(Method method, Class<?> type) {

    int result = 0;
    for (Class<?> clazz : method.getParameterTypes()) {
        if (type.equals(clazz)) {
            result++;
        }
    }

    return result;
}

From source file:com.googlecode.jmapper.util.GeneralUtility.java

/**
 * @param clazz class to analyze/*from   w  ww .j a va2  s. c om*/
 * @return true if this class is of Object type, false otherwise.
 */
public static boolean isObject(Class<?> clazz) {
    return clazz.equals(Object.class);
}

From source file:com.evolveum.midpoint.schema.util.ObjectTypeUtil.java

public static void assertConcreteType(Class<? extends Objectable> type) {
    // The abstract object types are enumerated here. It should be switched to some flag later on
    if (type.equals(ObjectType.class)) {
        throw new IllegalArgumentException("The type " + type.getName() + " is abstract");
    }//from w  w  w  . j  ava 2s  . c o  m
}

From source file:cn.fql.utility.ClassUtility.java

/**
 * Return is one class implements a class or extends a class
 *
 * @param currClass  current class//w  w w.j  ava 2 s  . c o m
 * @param superClass the super class or interface
 * @return the result
 */
public static boolean isRelationClass(Class currClass, Class superClass) {
    boolean result = false;
    if (currClass != null) {
        if (currClass.equals(superClass)) {
            result = true;
        } else {
            // find in interface
            Class[] interfaces = currClass.getInterfaces();
            for (int i = 0; i < interfaces.length; i++) {
                Class currInterface = interfaces[i];
                if (currInterface.equals(superClass)) {
                    result = true;
                }
            }

            if (!result) {
                //find in superclass
                if (currClass.equals(Object.class)) {
                    result = false;
                } else {
                    List superClasses = ClassUtils.getAllSuperclasses(currClass);
                    if (!CollectionUtils.isEmpty(superClasses)) {
                        Class currSuperClass = (Class) superClasses.get(0);
                        if (currSuperClass == null) {
                            System.out.println("Super Class is null");
                            result = false;
                        } else {
                            result = isRelationClass(currSuperClass, superClass);
                        }
                    }
                }
            }
        }
    }
    return result;
}

From source file:com.github.fcannizzaro.prefs.Prefs.java

/**
 * Iterate a kind of values (String, Boolean , Integer ..)
 *//*from   ww w.  j  a v  a  2  s  .  c o  m*/
public static <T> Iterator<Item<T>> iterator(Class c) {

    JSONObject obj = objects;

    if (c.equals(Integer.class))
        obj = integers;
    else if (c.equals(Float.class))
        obj = floats;
    else if (c.equals(Boolean.class))
        obj = booleans;
    else if (c.equals(String.class))
        obj = strings;
    else if (c.equals(Double.class))
        obj = doubles;

    final Iterator<String> keys = obj.keys();
    final JSONObject finalObj = obj;

    return new Iterator<Item<T>>() {

        @Override
        public boolean hasNext() {
            return keys.hasNext();
        }

        @Override
        public Item<T> next() {
            String key = keys.next();
            return new Item(key, finalObj.get(key));
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}

From source file:com.dosport.system.utils.ReflectionUtils.java

public static List<Class<?>> getAllAssignedClass(Class<?> cls) throws IOException, ClassNotFoundException {
    List<Class<?>> classes = new ArrayList<Class<?>>();
    for (Class<?> c : getClasses(cls)) {
        if (cls.isAssignableFrom(c) && !cls.equals(c)) {
            classes.add(c);/*from w  w  w  . ja  v  a 2  s.  c  o  m*/
        }
    }
    return classes;
}

From source file:com.stratio.deep.commons.utils.CellsUtils.java

private static DataType getDataType(Object value) {
    Class cls = value.getClass();
    DataType dataType;/* w w w .  j a va2 s. co  m*/
    if (cls.equals(String.class)) {
        dataType = DataType.StringType;
    } else if (cls.equals(Byte[].class)) {
        dataType = DataType.BinaryType;
    } else if (cls.equals(Boolean.class)) {
        dataType = DataType.BooleanType;
    } else if (cls.equals(Timestamp.class)) {
        dataType = DataType.TimestampType;
    } else if (cls.equals(Double.class)) {
        dataType = DataType.DoubleType;
    } else if (cls.equals(Float.class)) {
        dataType = DataType.FloatType;
    } else if (cls.equals(Byte.class)) {
        dataType = DataType.ByteType;
    } else if (cls.equals(Integer.class)) {
        dataType = DataType.IntegerType;
    } else if (cls.equals(Long.class)) {
        dataType = DataType.LongType;
    } else if (cls.equals(Short.class)) {
        dataType = DataType.ShortType;
    } else if (value instanceof List) {
        List listValue = (List) value;
        if (listValue.isEmpty()) {
            dataType = DataType.createArrayType(DataType.StringType);
        } else {
            dataType = DataType.createArrayType(getDataType(listValue.get(0)));
        }
    } else if (value instanceof Map) {
        Map mapValue = (Map) value;
        if (mapValue.isEmpty()) {
            dataType = DataType.createMapType(DataType.StringType, DataType.StringType);
        } else {
            Map.Entry entry = (Map.Entry) mapValue.entrySet().iterator().next();
            dataType = DataType.createMapType(getDataType(entry.getKey()), getDataType(entry.getValue()));
        }
    } else {
        dataType = DataType.StringType;
    }
    return dataType;
}

From source file:io.fabric8.forge.rest.dto.UICommands.java

protected static boolean isJsonObject(Object value) {
    if (value != null) {
        Class<?> aClass = value.getClass();
        while (aClass != null && !aClass.equals(Object.class)) {
            Annotation[] annotations = aClass.getAnnotations();
            if (annotations != null) {
                for (Annotation annotation : annotations) {
                    String annotationClassName = annotation.getClass().getName();
                    if (annotationClassName != null
                            && annotationClassName.startsWith("com.fasterxml.jackson.")) {
                        // lets assume its a JSON DTO!
                        return true;
                    } else {
                        String text = annotation.toString();
                        // because of the Forge proxying we can't just use the actual class here...
                        if (text.indexOf("com.fasterxml.jackson.") >= 0) {
                            return true;
                        }/*from  www.j  a  v a  2s  .  c om*/
                    }
                }
            }
            aClass = aClass.getSuperclass();
        }
    }
    return false;
}