| @@ -12,13 +12,13 @@ | |||||
| ``` | ``` | ||||
| // 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置) | // 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置) | ||||
| var options = new IdGeneratorOptions(){ WorkerId = 1}; | var options = new IdGeneratorOptions(){ WorkerId = 1}; | ||||
| IdHelper.SetIdGenerator(options); | |||||
| YitIdHelper.SetIdGenerator(options); | |||||
| // 初始化以后,就可以在需要的地方调用方法生成ID。 | // 初始化以后,就可以在需要的地方调用方法生成ID。 | ||||
| var newId = IdHelper.NextId(); | |||||
| var newId = YitIdHelper.NextId(); | |||||
| ``` | ``` | ||||
| 如果基于DI框架集成,可以参考 IdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。 | |||||
| 如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。 | |||||
| ## options 默认值及说明 | ## options 默认值及说明 | ||||
| @@ -45,8 +45,8 @@ namespace Yitter.OrgSystem.TestA | |||||
| GenTest genTest = new GenTest(IdGen, genIdCount, options.WorkerId); | GenTest genTest = new GenTest(IdGen, genIdCount, options.WorkerId); | ||||
| // 首先测试一下 IdHelper 方法,获取单个Id | // 首先测试一下 IdHelper 方法,获取单个Id | ||||
| IdHelper.SetIdGenerator(options); | |||||
| long newId = IdHelper.NextId(); | |||||
| YitIdHelper.SetIdGenerator(options); | |||||
| long newId = YitIdHelper.NextId(); | |||||
| Console.WriteLine("====================================="); | Console.WriteLine("====================================="); | ||||
| Console.WriteLine("这是用方法 " + method + " 生成的 Id:" + newId); | Console.WriteLine("这是用方法 " + method + " 生成的 Id:" + newId); | ||||
| @@ -14,9 +14,9 @@ using System.Text; | |||||
| namespace Yitter.IdGenerator | namespace Yitter.IdGenerator | ||||
| { | { | ||||
| /// <summary> | /// <summary> | ||||
| /// 这是一个调用的例子,默认情况下,单机集成者可以直接使用 NewId()。 | |||||
| /// 这是一个调用的例子,默认情况下,单机集成者可以直接使用 NextId()。 | |||||
| /// </summary> | /// </summary> | ||||
| public class IdHelper | |||||
| public class YitIdHelper | |||||
| { | { | ||||
| private static IIdGenerator _IdGenInstance = null; | private static IIdGenerator _IdGenInstance = null; | ||||
| @@ -13,13 +13,13 @@ JDK 1.8+ | |||||
| // 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置) | // 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置) | ||||
| IdGeneratorOptions options = new IdGeneratorOptions(); | IdGeneratorOptions options = new IdGeneratorOptions(); | ||||
| options.WorkerId = 1; | options.WorkerId = 1; | ||||
| IdHelper.setIdGenerator(options); | |||||
| YitIdHelper.setIdGenerator(options); | |||||
| // 初始化以后,就可以在需要的地方调用方法生成ID。 | // 初始化以后,就可以在需要的地方调用方法生成ID。 | ||||
| long newId = IdHelper.nextId(); | |||||
| long newId = YitIdHelper.nextId(); | |||||
| ``` | ``` | ||||
| 如果基于DI框架集成,可以参考 IdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。 | |||||
| 如果基于DI框架集成,可以参考 YitIdHelper 去管理 IdGenerator 对象,必须使用**单例**模式。 | |||||
| ## options 默认值及说明 | ## options 默认值及说明 | ||||
| @@ -9,9 +9,9 @@ import com.yitter.contract.IdGeneratorOptions; | |||||
| import com.yitter.contract.IIdGenerator; | import com.yitter.contract.IIdGenerator; | ||||
| /** | /** | ||||
| * 这是一个调用的例子,默认情况下,单机集成者可以直接使用 NewId()。 | |||||
| * 这是一个调用的例子,默认情况下,单机集成者可以直接使用 nextId()。 | |||||
| */ | */ | ||||
| public class IdHelper { | |||||
| public class YitIdHelper { | |||||
| private static IIdGenerator idGenInstance = null; | private static IIdGenerator idGenInstance = null; | ||||
| @@ -3,7 +3,7 @@ package com.yitter.test; | |||||
| import com.yitter.contract.IdGeneratorOptions; | import com.yitter.contract.IdGeneratorOptions; | ||||
| import com.yitter.contract.IIdGenerator; | import com.yitter.contract.IIdGenerator; | ||||
| import com.yitter.idgen.DefaultIdGenerator; | import com.yitter.idgen.DefaultIdGenerator; | ||||
| import com.yitter.idgen.IdHelper; | |||||
| import com.yitter.idgen.YitIdHelper; | |||||
| public class StartUp { | public class StartUp { | ||||
| @@ -38,8 +38,8 @@ public class StartUp { | |||||
| GenTest genTest = new GenTest(IdGen, genIdCount, options.WorkerId); | GenTest genTest = new GenTest(IdGen, genIdCount, options.WorkerId); | ||||
| // 首先测试一下 IdHelper 方法,获取单个Id | // 首先测试一下 IdHelper 方法,获取单个Id | ||||
| IdHelper.setIdGenerator(options); | |||||
| long newId = IdHelper.nextId(); | |||||
| YitIdHelper.setIdGenerator(options); | |||||
| long newId = YitIdHelper.nextId(); | |||||
| System.out.println("====================================="); | System.out.println("====================================="); | ||||
| System.out.println("这是用方法 " + method + " 生成的 Id:" + newId); | System.out.println("这是用方法 " + method + " 生成的 Id:" + newId); | ||||