All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.treeleafj.xmax.safe.ID Maven / Gradle / Ivy

The newest version!
package org.treeleafj.xmax.safe;

/**
 * ID工具
 * 

* Created by leaf on 2016/2/19. */ public abstract class ID { private static Sequence sequence = new Sequence(); /** * 生成的ID的后缀 */ private static String SUFFIX = null; /** * 生成一个有序,分布式唯一,且24位长度的id(只包含数字和字母,字母都为小写字母) * * @return */ public static String get() { return org.apache.commons.codec.binary.Hex.encodeHexString(ObjectId.get().toByteArray()); } /** * 生成一个有序,分布式唯一,且16位长度的短id(url安全的,区分大小写,包含"-") * * @return */ public static String getShort() { return Base64.encodeURLSafe(ObjectId.get().toByteArray()); } /** * 18位ID(如果不指定后缀的话) *

*

* 高效GUID产生算法(sequence),基于Snowflake实现64位自增ID算法。
* 优化开源项目 http://git.oschina.net/yu120/sequence *

* * @author hubin */ public static long getSequence() { return sequence.nextId(); } /** * 18位ID *

*

* 高效GUID产生算法(sequence),基于Snowflake实现64位自增ID算法。
* 优化开源项目 http://git.oschina.net/yu120/sequence *

* * @author hubin */ public static String getSequenceString() { if (SUFFIX != null) { return String.valueOf(getSequence()) + SUFFIX; } return String.valueOf(getSequence()); } public static void setSuffix(String suffix) { ID.SUFFIX = suffix; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy