Example usage for java.lang System identityHashCode

List of usage examples for java.lang System identityHashCode

Introduction

In this page you can find the example usage for java.lang System identityHashCode.

Prototype

@HotSpotIntrinsicCandidate
public static native int identityHashCode(Object x);

Source Link

Document

Returns the same hash code for the given object as would be returned by the default method hashCode(), whether or not the given object's class overrides hashCode().

Usage

From source file:Uuid32Generator.java

public String generate() {
    StringBuilder strRetVal = new StringBuilder();
    String strTemp;// w  ww. j a  va 2  s . c o m
    try {
        // IPAddress segment
        InetAddress addr = InetAddress.getLocalHost();
        byte[] ipaddr = addr.getAddress();
        for (byte anIpaddr : ipaddr) {
            Byte b = new Byte(anIpaddr);
            strTemp = Integer.toHexString(b.intValue() & 0x000000ff);
            strRetVal.append(ZEROS.substring(0, 2 - strTemp.length()));
            strRetVal.append(strTemp);
        }
        strRetVal.append(':');

        // CurrentTimeMillis() segment
        strTemp = Long.toHexString(System.currentTimeMillis());
        strRetVal.append(ZEROS.substring(0, 12 - strTemp.length()));
        strRetVal.append(strTemp).append(':');

        // random segment
        SecureRandom prng = SecureRandom.getInstance("SHA1PRNG");
        strTemp = Integer.toHexString(prng.nextInt());
        while (strTemp.length() < 8) {
            strTemp = '0' + strTemp;
        }
        strRetVal.append(strTemp.substring(4)).append(':');

        // IdentityHash() segment
        strTemp = Long.toHexString(System.identityHashCode(this));
        strRetVal.append(ZEROS.substring(0, 8 - strTemp.length()));
        strRetVal.append(strTemp);
    } catch (UnknownHostException uhex) {
        throw new RuntimeException("Unknown host.", uhex);
    } catch (NoSuchAlgorithmException nsaex) {
        throw new RuntimeException("Algorithm 'SHA1PRNG' is unavailiable.", nsaex);
    }
    return strRetVal.toString().toUpperCase();
}

From source file:org.mariotaku.twidere.util.ActivityTracker.java

@Override
public void onActivityStarted(final Activity activity) {
    mInternalStack.add(System.identityHashCode(activity));
    if (activity instanceof HomeActivity) {
        mHomeActivityStarted = true;/*from www.ja  v a 2  s.c  om*/
    }
    // BEGIN HotMobi
    if (mSessionEvent == null) {
        mSessionEvent = SessionEvent.create(activity);
    }
    // END HotMobi
}

From source file:org.stem.domain.topology.TopologyCoderTest.java

@Test
public void jsonPackAndUnpackEquality() throws Exception {
    DataMapping mapping = prepareMapping(100000, 1);

    REST.Mapping original = RestUtils.packMapping(mapping);
    String encoded = JsonUtils.encode(original);
    REST.Mapping decoded = JsonUtils.decode(encoded, REST.Mapping.class);

    // Assert//w  ww  .  ja  v  a 2  s.  c om
    Set<Integer> diskObjIds = new HashSet<>();
    for (Long bucket : decoded.getBuckets()) {
        REST.ReplicaSet originalReplicas = original.getReplicaSet(bucket);
        REST.ReplicaSet decodedReplicas = decoded.getReplicaSet(bucket);
        for (REST.Disk disk : decodedReplicas.getReplicas()) {
            int originalId = System.identityHashCode(disk);
            diskObjIds.add(originalId);
        }

        validateReplicasEquality(originalReplicas, decodedReplicas);
    }

    System.out.println("Length of encoded json: " + encoded.length() + " symbols");
    // Validate we have only 3 unique disk objects
    Assert.assertEquals(3, diskObjIds.size());
}

From source file:org.diorite.impl.scheduler.DioriteFuture.java

DioriteFuture(final Callable<T> callable, final DioritePlugin dioritePlugin, final Synchronizable sync,
        final int id) {
    super(callable.getClass().getName() + "@" + System.identityHashCode(callable), dioritePlugin, null, sync,
            false, id, STATE_SINGLE);/*w w  w . j  av  a 2 s .  c  om*/
    this.callable = callable;
}

From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReferenceHashmap.java

@SuppressWarnings("unchecked")
@Override//from  w w  w.ja  v  a2s  .c o  m
public V get(Object key) {
    List<Entry<WeakReference<K>, V>> _pairs = values.get(System.identityHashCode(key));
    if (_pairs == null)
        return null;
    return getKeyInPair(_pairs, (K) key);
}

From source file:org.eclipse.gemini.blueprint.compendium.internal.cm.DefaultManagedServiceBeanManager.java

public Object register(Object bean) {
    int hashCode = System.identityHashCode(bean);
    if (log.isTraceEnabled())
        log.trace("Start tracking instance " + bean.getClass().getName() + "@" + hashCode);
    instanceRegistry.put(Integer.valueOf(hashCode), bean);
    applyInitialInjection(bean, cam.getConfiguration());
    return bean;//w  ww. java 2  s .  c  om
}

From source file:com.biglakesystems.biglib.quality.Exceptions.java

/**
 * Generate a unique identifier for an exception. Combines the exception class name, identity hash code, and an
 * ever-incrementing sequence value into a string and then performs a SHA-1 hash of that string, returning the hex
 * hash./*from  w  w  w.j  a va  2s . co  m*/
 *
 * @param exception the exception.
 * @return {@link String} unique identifier.
 */
private static String newUniqueId(final Throwable exception) {
    final String content = String.format("%s_%08x_%08x", exception.getClass().getName(),
            System.identityHashCode(exception), s_nextIdSequence.getAndIncrement());
    return DigestUtils.sha1Hex(content);
}

From source file:net.lightbody.bmp.proxy.jetty.http.MultiPartResponse.java

private MultiPartResponse() {
    try {//from  w  w  w .ja  v  a 2  s.c  om
        boundary = "jetty" + System.identityHashCode(this) + Long.toString(System.currentTimeMillis(), 36);
        boundaryBytes = boundary.getBytes(StringUtil.__ISO_8859_1);
    } catch (Exception e) {
        log.fatal(e);
        System.exit(1);
    }
}

From source file:io.druid.storage.s3.S3StorageDruidModule.java

@Override
public List<? extends Module> getJacksonModules() {
    return ImmutableList.of(new Module() {
        @Override//  w  w  w . j  a  v  a  2 s. c  o m
        public String getModuleName() {
            return "DruidS3-" + System.identityHashCode(this);
        }

        @Override
        public Version version() {
            return Version.unknownVersion();
        }

        @Override
        public void setupModule(SetupContext context) {
            context.registerSubtypes(S3LoadSpec.class);
        }
    });
}

From source file:com.brienwheeler.lib.db.domain.GeneratedIdEntityBaseTest.java

@Test
public void testHashCodeUnpersisted() {
    SimpleEntity entity = new SimpleEntity();
    Assert.assertEquals(System.identityHashCode(entity), entity.hashCode());
}