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:grails.util.GrailsClassUtils.java

/**
 * Creates a concrete collection for the suppied interface
 * @param interfaceType The interface//from w w  w .j  av a 2s  .  co m
 * @return ArrayList for List, TreeSet for SortedSet, HashSet for Set etc.
 */
@SuppressWarnings("rawtypes")
public static Collection createConcreteCollection(Class interfaceType) {
    Collection elements;
    if (interfaceType.equals(List.class) || interfaceType.equals(Collection.class)) {
        elements = new ArrayList();
    } else if (interfaceType.equals(SortedSet.class)) {
        elements = new TreeSet();
    } else {
        elements = new HashSet();
    }
    return elements;
}

From source file:com.hunchee.twist.gae.GaeMarshaller.java

/**
 * Creates a Key from a object instance, the kind is inspected in
 * the process.//from   w  w w . ja v  a  2s  .  c  o  m
 *
 * @param parent key or null
 * @param instance String, Long/long key object
 * @return GAE {@code Key}
 */
public static Key createKeyFrom(Key parent, Object instance) {
    Key key = null;
    Object id = null;
    String kind = getKindOf(instance);
    if (instance instanceof Map) {
        id = ((Map) instance).get(GaeObjectStore.KEY_RESERVED_PROPERTY);
        if (id != null) {
            if (id instanceof Long || instance.getClass().equals(long.class)) {
                key = KeyStructure.createKey(parent, kind, (Long) id);
            } else if (id instanceof String) {
                key = KeyStructure.createKey(parent, kind, (String) id);
            } else {
                throw new RuntimeException(
                        "Unsupported " + GaeObjectStore.KEY_RESERVED_PROPERTY + ". Use String or Long type");
            }
        } else {
            // auto-generate "key" when not supplied
            key = KeyStructure.createKey(parent, kind, KeyStructure.autoLongId(kind));
        }
        return key;
    }

    AnnotationUtil.AnnotatedField ancestorField = AnnotationUtil
            .getFieldWithAnnotation(GaeObjectStore.ancestor(), instance);

    AnnotationUtil.AnnotatedField parentField = AnnotationUtil.getFieldWithAnnotation(GaeObjectStore.parent(),
            instance);

    AnnotationUtil.AnnotatedField idField = AnnotationUtil.getFieldWithAnnotation(GaeObjectStore.key(),
            instance);

    if (ancestorField != null) {
        Class<?> clazz = ancestorField.getFieldType();
        if (clazz.equals(Key.class)) {
            Key ancestor = (Key) ancestorField.getFieldValue();
            // TODO: No use use it seems
        } else {
            throw new RuntimeException("Only " + Key.class + " is supported to be annoated with @Ancestor");
        }
    }

    if (idField != null) {
        if (parentField != null && parentField.getFieldValue() != null) {
            if (parentField.getFieldValue().getClass().equals(Key.class)) {
                parent = (Key) parentField.getFieldValue();
            }
        }
        Class<?> clazz = idField.getFieldType();
        id = idField.getFieldValue();
        if (clazz.equals(String.class)) {
            if (id != null) {
                key = KeyStructure.createKey(parent, kind, (String) id);
            } else {
                Id annotation = (Id) idField.annotation();
                String prefix = annotation.prefix();
                if (prefix != null && !prefix.isEmpty()) {
                    Key auto = KeyStructure.createKey(parent, kind, KeyStructure.autoLongId(kind));
                    Long autoId = auto.getId();
                    key = KeyStructure.createKey(parent, kind, prefix + autoId);
                } else {
                    throw new AutoGenerateStringIdException();
                }
            }
        } else if (clazz.equals(Long.class)) {
            if (id != null) {
                key = KeyStructure.createKey(parent, kind, (Long) id);
            } else { // auto-generate
                key = KeyStructure.createKey(parent, kind, KeyStructure.autoLongId(kind));
            }
        } else if (clazz.equals(long.class)) {
            key = KeyStructure.createKey(parent, kind, (Long) id);
        } else {
            throw new RuntimeException("Unsupported @Id type " + id.getClass() + " Use String or Long type");
        }
    } else {
        throw new RuntimeException(
                "Object does not have id or key. Must put @Id annotation on " + instance.getClass());
    }
    return key;
}

From source file:org.openmrs.logic.token.TokenRegistrationValidator.java

/**
 * @see org.springframework.validation.Validator#supports(java.lang.Class)
 *//*  w  ww.ja va 2 s  .co m*/
@SuppressWarnings("unchecked")
public boolean supports(Class c) {
    return c.equals(TokenRegistration.class);
}

From source file:org.openmrs.module.bahmniexports.example.domain.trade.internal.validator.TradeValidator.java

@Override
public boolean supports(Class<?> clazz) {
    return clazz.equals(Trade.class);
}

From source file:org.oncoblocks.centromere.core.test.EntrezGeneValidator.java

@Override
public boolean supports(Class<?> aClass) {
    return aClass.equals(EntrezGene.class);
}

From source file:net.sourceforge.subsonic.validator.PasswordSettingsValidator.java

public boolean supports(Class clazz) {
    return clazz.equals(PasswordSettingsCommand.class);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ApplyForWritingPermissionValidator.java

public boolean supports(Class clazz) {
    return clazz.equals(ApplyForWritingPermissionCommand.class);
}

From source file:com.apress.progwt.server.web.domain.validation.PasswordChangeCommandValidator.java

public boolean supports(Class clazz) {
    return clazz.equals(PasswordChangeCommand.class);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef.AddExperimentOptParamDefValidator.java

public boolean supports(Class clazz) {
    return clazz.equals(AddExperimentOptParamDefCommand.class);
}

From source file:cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata.AddFileMetadataParamDefValidator.java

public boolean supports(Class clazz) {
    return clazz.equals(AddFileMetadataParamDefCommand.class);
}