Java AtomicInteger createIdentifier(Class clazz)

Here you can find the source of createIdentifier(Class clazz)

Description

Creates a unique identifier for the given class.

License

Open Source License

Declaration

final public static String createIdentifier(Class<?> clazz) 

Method Source Code

//package com.java2s;

import java.util.Map;

import java.util.WeakHashMap;
import java.util.concurrent.atomic.AtomicInteger;

public class Main {
    /**/* w w  w  .  j  a va2s  .c o m*/
     * A mapping of classes to unique identifier counters.
     */
    final protected static Map<Class<?>, AtomicInteger> counterMap = new WeakHashMap<Class<?>, AtomicInteger>();

    /**
     * Creates a unique identifier for the given class.
     */
    final public static String createIdentifier(Class<?> clazz) {

        synchronized (counterMap) {

            AtomicInteger counter = counterMap.get(clazz);

            if (counter == null) {

                counter = new AtomicInteger(0);
                counterMap.put(clazz, counter);
            }

            return String.format("%08x", counter.getAndIncrement());
        }
    }
}

Related

  1. count()
  2. count(byte[] array, byte value)
  3. countDownToZero(AtomicInteger counter)
  4. countOccurrences(final Collection collection)
  5. create()
  6. createNewTestNamespace( Map environmentProperties)
  7. createThreadFactory(final String prefix)
  8. decrementStoredNoOfParts()
  9. decrementVxlanGpeRefCnt(final String vxlanGpePortKey, final String vppNode)