Java AtomicLong getMeUniqueString(Calendar cal)

Here you can find the source of getMeUniqueString(Calendar cal)

Description

get Me Unique String

License

Open Source License

Declaration

private static String getMeUniqueString(Calendar cal) 

Method Source Code


//package com.java2s;
import java.util.Calendar;

import java.util.concurrent.atomic.AtomicLong;

public class Main {
    private static AtomicLong idCounter = new AtomicLong(0);

    private static String getMeUniqueString(Calendar cal) {
        StringBuilder unq = new StringBuilder();
        //unq.append(RandomStringUtils.randomAlphanumeric(2));
        //unq.append(Character.toString((char) ('A' + (cal.get(Calendar.YEAR) % 100 - 16))));
        unq.append(Character.toString((char) ('n' + (cal.get(Calendar.MONTH) % 100))));
        unq.append(Character.toString((char) ('@' + (cal.get(Calendar.DAY_OF_MONTH) % 100))));
        unq.append(Character.toString((char) ('c' + (cal.get(Calendar.HOUR_OF_DAY) % 100))));
        unq.append(getMeChar(cal.get(Calendar.MINUTE) % 100));
        unq.append(getMeChar(cal.get(Calendar.SECOND) % 100));
        unq.append(getMeChar(idCounter.getAndIncrement()));
        idCounter.compareAndSet(62, 0);/*from  w  ww . j ava 2  s  . co  m*/

        /*
        unq.append(cal.get(Calendar.MILLISECOND));*/
        return unq.toString();
    }

    private static String getMeChar(long l) {
        if (l <= 9) {
            return Character.toString((char) ('0' + l));
        } else if (l >= 10 && l <= 35) {
            return Character.toString((char) ('a' + l - 10));
        } else if (l >= 36 && l <= 61) {
            return Character.toString((char) ('A' + l - 36));
        }
        return String.valueOf(l);
    }
}

Related

  1. getForeverUniqueID()
  2. getGlobalTimeStamp()
  3. getList(AtomicLongArray atomicLongArray)
  4. getMessageId()
  5. getMethodExecuteCount()
  6. getMmapBufferUsage()
  7. getNativeSeed(Random rand)
  8. getNextTestIndexName()
  9. getNowMicrosUtc()