Example usage for java.lang Object hashCode

List of usage examples for java.lang Object hashCode

Introduction

In this page you can find the example usage for java.lang Object hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:org.codehaus.wadi.core.contextualiser.HashingCollapser.java

public Lock getLock(Object id) {
    // Jetty seems to generate negative session id hashcodes...
    int index = Math.abs(id.hashCode() % locks.length);
    if (_log.isTraceEnabled()) {
        _log.trace("collapsed " + id + " to index: " + index);
    }//  w  w  w .j  av  a  2s. c o m
    return locks[index];
}

From source file:com.autentia.tnt.util.GenericEnumUserType.java

public int hashCode(Object x) throws HibernateException {
    return x.hashCode();
}

From source file:ca.oson.json.util.ObjectUtil.java

public static int hashCode(Object obj, Class valueType) {
    int hash = 7;

    try {// w  w  w.  j  a v a2s .c o m
        if (obj == null) {
            hash = valueType.hashCode();
        } else {
            hash = obj.hashCode();
        }

    } catch (Exception ex) {
    }

    if (obj != null && Math.abs(hash) < 100) {
        String str = obj.toString();
        hash += str.hashCode();
    }

    return hash;
}

From source file:nl.strohalm.cyclos.utils.hibernate.AbstractEnumType.java

public int hashCode(final Object x) throws HibernateException {
    return x == null ? -1 : x.hashCode();
}

From source file:org.smallmind.persistence.orm.hibernate.LongArrayUserType.java

@Override
public int hashCode(final Object o) throws HibernateException {

    return o == null ? 0 : o.hashCode();
}

From source file:edu.cornell.med.icb.ip.IpAddress.java

/**
 * Equals.//from  www. j  a  va  2 s . c o  m
 * @param obj the object to compare to.
 * @return true if the two objects are equal.
 */
@Override
public boolean equals(final Object obj) {
    return ((obj != null) && (obj instanceof IpAddress) && this.hashCode == obj.hashCode());
}

From source file:org.openmrs.module.odkconnector.api.db.hibernate.type.CohortDefinitionType.java

/**
 * @see org.hibernate.usertype.UserType#hashCode(Object)
 *///from  www  .  ja va 2s .c o  m
@Override
public int hashCode(final Object x) throws HibernateException {
    return x.hashCode();
}

From source file:nl.strohalm.cyclos.utils.hibernate.AmountType.java

public int hashCode(final Object arg0) throws HibernateException {
    return arg0.hashCode();
}

From source file:eu.crisis_economics.abm.model.ModelUtils.java

/**
  * A depth-first recursive parameter search tool. This function accepts an object
  * ({@code X}) and a {@link String} ID ({@code P}) of a parameter to search for.<br><br>
  * /*from  w w w. ja  v a 2  s. c  o  m*/
  * Any object {@code O} in the configuration hierarchy of {@code X} which possesses a field with
  * a) the appropriate annotation and b) parameter ID is identified and returned.
  * This method will search for member fields {@code F} (with any modifer) which satisfy:
  * 
  * <ul>
  *   <li> {@code F} carries a {@link Parameter} {@link Annotation}.
  *   <li> The {@code ID} of this {@link Parameter} is equal to {@code P}.
  *   <li> {@code F} does not itself belongs to a {@link Submodel} field that satisfies the
  *        above two conditions.
  * </ul>
  * 
  * This search operates as follows:<br><br>
  * 
  * <ul>
  *   <li> If {@code X} contains a member field {@code F} satisfying the above conditions, 
  *        {@code F} is accepted and returned.
  *   <li> Otherwise, each supertype in the inheritance hierarchy of {@code X} is searched.
  *   <li> Apply the above steps recursively (depth-first) to every field {@code F}
  *        in {@code X} annotated with {@link Submodel}, unless {@code F} itself
  *        satisfies the above conditions, in which case {@code F} is accepted and returned.
  * </ul>
  * 
  * This method returns a {@link List} of {@link ConfigurationModifier} objects. Each element
  * in this list corresponds to a field {@code F} somewhere in the inheritance hierarchy of
  * {@code X} which satisfied the above search conditions. {@link ConfigurationModifier}
  * objects facilitate direct changes to the value of each such {@code F}.<br><br>
  * 
  * @param on (<code>X</code>) <br>
  *        The object to search.
  * @param parameterIdToFind on (<code>P</code>) <br>
  *        The ID of the {@link Parameter} to search for.
  */
public static List<ConfigurationModifier> search(final Object on, final String parameterIdToFind) {
    if (on == null)
        throw new IllegalArgumentException("search: object to search is null.");
    if (parameterIdToFind == null || parameterIdToFind.isEmpty())
        throw new IllegalArgumentException("search: parameter name is empty or null.");
    if (VERBOSE_MODE)
        System.out.println("search: searching object " + on.getClass().getSimpleName() + on.hashCode()
                + " for parameters of type " + parameterIdToFind + ".");
    final Class<?> objClass = on.getClass();
    final List<ConfigurationModifier> methodsIdentified = new ArrayList<ConfigurationModifier>();
    for (Class<?> typeToSearch = objClass; typeToSearch != null; typeToSearch = typeToSearch.getSuperclass()) {
        for (final Field field : typeToSearch.getDeclaredFields()) {
            field.setAccessible(true);
            if (VERBOSE_MODE)
                System.out.println("inspecting field with name: " + field.getName() + ".");
            try {
                Annotation drilldownAnnotation = null, modelParameterAnnotation = null;
                for (final Annotation element : field.getAnnotations()) {
                    if (element.annotationType().getName() == Submodel.class.getName()) { // Proxies
                        drilldownAnnotation = element;
                        if (VERBOSE_MODE)
                            System.out.println("field " + field.getName() + " is a subconfiguration.");
                        continue;
                    } else if (element.annotationType().getName() == Parameter.class.getName()) { // Proxies
                        final Class<? extends Annotation> type = element.annotationType();
                        final String id = (String) type.getMethod("ID").invoke(element);
                        if (parameterIdToFind.equals(id)) {
                            modelParameterAnnotation = element;
                            if (VERBOSE_MODE)
                                System.out.println("* field is valid.");
                            continue;
                        } else if (VERBOSE_MODE)
                            System.out.println("field ID [" + id + "] does not match the required ID: "
                                    + parameterIdToFind + ".");
                        continue;
                    } else
                        continue;
                }
                if (modelParameterAnnotation != null) {
                    final ConfigurationModifier fieldWithMutators = findGetterSetterMethods(field, on,
                            parameterIdToFind);
                    methodsIdentified.add(fieldWithMutators);
                    continue;
                } else if (drilldownAnnotation != null) {
                    if (VERBOSE_MODE)
                        System.out.println("descending into subconfiguration: " + field.getName());
                    final Object fieldValue = field.get(on);
                    methodsIdentified.addAll(search(fieldValue, parameterIdToFind));
                    continue;
                }
                if (VERBOSE_MODE)
                    System.out.println("rejecting parameter: " + field.getName());
            } catch (final SecurityException e) {
                throw new IllegalStateException(
                        "search: a security exception was raised when testing a field with name "
                                + field.getName() + " for model parameter annotations. Details follow: "
                                + e.getMessage() + ".");
            } catch (final IllegalArgumentException e) {
                throw new IllegalStateException(
                        "search: an illegal argument exception was raised when testing a field with name "
                                + field.getName() + " for model parameter annotations. Details follow: "
                                + e.getMessage() + ".");
            } catch (final IllegalAccessException e) {
                throw new IllegalStateException(
                        "search: a security exception was raised when testing a field with name "
                                + field.getName() + " for model parameter annotations. Details follow: "
                                + e.getMessage() + ".");
            } catch (final InvocationTargetException e) {
                throw new IllegalStateException(
                        "search: an invokation target exception was raised when testing a field with" + " name "
                                + field.getName() + " for model parameter annotations. Details follow: "
                                + e.getMessage() + ".");
            } catch (final NoSuchMethodException e) {
                throw new IllegalStateException(
                        "search: a missing-method exception was raised when testing a field with name "
                                + field.getName() + " for model parameter annotations. Details follow: "
                                + e.getMessage() + ".");
            }
        }
    }
    if (VERBOSE_MODE)
        System.out.println("searched: " + on.getClass().getSimpleName() + on.hashCode()
                + " for parameters of type " + parameterIdToFind + ".");
    return methodsIdentified;
}

From source file:org.apache.hadoop.hbase.metrics.MetricRegistryInfo.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof MetricRegistryInfo) {
        return this.hashCode() == obj.hashCode();
    } else {/*from  w w w.j a  v  a  2s  . c  o  m*/
        return false;
    }
}