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:HashCode.java

/**
 * Generate a hash code for an object./*  w ww.j  a va 2  s  .  c o  m*/
 * 
 * @param obj
 *          Object to generate hashcode for.
 * @return Hash code.
 */
public static int generate(final Object obj) {
    if (obj != null) {
        return obj.hashCode();
    }

    return NULL_HASHCODE;
}

From source file:org.apache.axis2.jaxws.client.async.CallbackFuture.java

public static String displayHandle(Object obj) {
    return obj.getClass().getName() + '@' + Integer.toHexString(obj.hashCode());
}

From source file:org.chtijbug.drools.runtime.DroolsFactObjectFactory.java

public static DroolsFactObject createFactObject(Object o, int version) {
    logger.debug(">> createFactObject", o, version);
    DroolsFactObject createFactObject = null;
    try {/*from   w w  w .ja  va2s .co  m*/
        if (o != null) {
            createFactObject = new DroolsFactObject(o, version);
            createFactObject.setFullClassName(o.getClass().getCanonicalName());
            createFactObject.setHashCode(o.hashCode());

            BeanMap m = new BeanMap(o);
            for (Object para : m.keySet()) {
                if (!para.toString().equals("class")) {
                    if (m.get(para) != null) {
                        DroolsFactObjectAttribute attribute = new DroolsFactObjectAttribute(para.toString(),
                                m.get(para).toString(), m.get(para).getClass().getSimpleName());
                        createFactObject.getListfactObjectAttributes().add(attribute);
                    } else {
                        DroolsFactObjectAttribute attribute = new DroolsFactObjectAttribute(para.toString(),
                                "null", "null");
                        createFactObject.getListfactObjectAttributes().add(attribute);
                    }

                }

            }
        }
        return createFactObject;
    } catch (Exception e) {
        logger.error("Not possible to introspect {} for reason {}", o, e);
        throw Throwables.propagate(e);
    } finally {
        logger.debug("<< createFactObject", createFactObject);
    }
}

From source file:com.anhth12.lambda.app.serving.als.model.ALSServingModel.java

private static int partition(Object o) {
    return (o.hashCode() & 0x7FFFFFFF) % PARTITIONS;
}

From source file:HashCode.java

/**
 * Calculates hash code for Objects. Object is a possibly-null object field, and possibly an array.
 * <p>/*  ww  w  .ja v  a2  s.  c o  m*/
 * If <code>aObject</code> is an array, then each element may be a primitive
 * or a possibly-null object.
 */
public static int hash(int seed, Object aObject) {
    int result = seed;
    if (aObject == null) {
        result = hash(result, 0);
    } else if (aObject.getClass().isArray() == false) {
        result = hash(result, aObject.hashCode());
    } else {
        Object[] objects = (Object[]) aObject;
        int length = objects.length;
        for (int idx = 0; idx < length; ++idx) {
            result = hash(result, objects[idx]);
        }
    }
    return result;
}

From source file:org.ldaptive.LdapUtils.java

/**
 * Determines equality of the supplied objects by delegating to their hashCode
 * methods./*from  w  w w  .  ja va2 s.c  o m*/
 *
 * @param  o1  to test equality of
 * @param  o2  to test equality of
 *
 * @return  whether o1 equals o2
 */
public static boolean areEqual(final Object o1, final Object o2) {
    if (o1 == null) {
        return o2 == null;
    }
    return o2 != null && (o1 == o2 || o1.getClass() == o2.getClass() && o1.hashCode() == o2.hashCode());
}

From source file:edu.vt.middleware.ldap.LdapUtil.java

/**
 * Computes a hash code for the supplied object. Checks for arrays of type
 * byte[] and Object[] and delegates to the {@link Arrays} class. Otherwise
 * {@link Object#hashCode()} is invoked.
 *
 * @param  object  to calculate hash code for
 *
 * @return  hash code//from   w  ww.j a  v  a  2  s .c  o  m
 */
private static int computeHashCode(final Object object) {
    int hc = 0;
    if (object instanceof byte[]) {
        hc += Arrays.hashCode((byte[]) object);
    } else if (object instanceof Object[]) {
        hc += Arrays.hashCode((Object[]) object);
    } else {
        hc += object.hashCode();
    }
    return hc;
}

From source file:com.qwazr.utils.StringUtils.java

public static int compareNullHashCode(Object o1, Object o2) {
    if (o1 == null) {
        if (o2 == null)
            return 0;
        return -1;
    }// ww w  .  j  a v  a 2  s .  c om
    if (o2 == null)
        return 1;
    return o2.hashCode() - o1.hashCode();
}

From source file:org.seasar.uruma.log.UrumaLogger.java

/**
 * ????<br />//from w  w w  .  ja v  a 2 s .co m
 * 
 * @param obj
 *            
 * @return 
 */
public static final String getObjectDescription(final Object obj) {
    if (obj != null) {
        return obj.getClass().getName() + UrumaConstants.AT_MARK + Integer.toHexString(obj.hashCode());
    } else {
        return "NULL";
    }
}

From source file:org.seasar.dbflute.FunCustodial.java

public static int calculateHashcode(int result, Object value) { // calculateHashcode()
    if (value == null) {
        return result;
    }//from   ww w.  j  a v  a 2 s.c  o  m
    return (31 * result) + (value instanceof byte[] ? ((byte[]) value).length : value.hashCode());
}