idgenerator.java
来自「发布/订阅系统路由重配算法,可应用于ad hoc环境」· Java 代码 · 共 67 行
JAVA
67 行
/* * project: RebecaSim * package: util * file: IDGenerator.java * version: 0.1 * date: 31.03.2005 * * This software is part of the diploma thesis "Ein adaptives Brokernetz * für Publish/Subscribe Systeme". */package util;/** * An <code>IDGenerator</code> provides <code>long</code> values * convenient to build (unique) identifiers on. * As long as the value range is not exhausted all returned values are unique. * A new id-value is obtained by incrementing the last returned one. * @version 0.1 31.03.2005 * @author Helge Parzyjegla */public class IDGenerator { /** All new ID values are created incrementally based on this counter. */ private static long id; /** * Creates a new <code>IDGenerator</code> instance with the first * (returned) id-value initialized to <code>0</code>. */ public IDGenerator() { id = 0; } /** * Creates a new <code>IDGenerator</code> instance with the first * (returned) id-value initialized to <code>value</code>. * @param value value of the first returned id */ public IDGenerator(long value) { id = value; } /** * Returns the next id-value, needed by the <code>ID</code> class to * create a new <code>ID</code> object. * @return the next id-value */ public synchronized long getId(){ return id++; } /** * Resets the <code>IDGenerator</code> instance to <code>0</code>. */ public synchronized void reset() { id = 0; } /** * Resets the <code>IDGenerator</code> instance to <code>value</code>. * @param value value of the next id after reset */ public synchronized void reset(long value) { id = value; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?