1 18 19 package sync4j.framework.tools; 20 21 import sync4j.framework.tools.IdGenerator; 22 import sync4j.framework.tools.SimpleIdGenerator; 23 import sync4j.framework.core.CmdID; 24 25 35 public class CommandIdGenerator 36 implements java.io.Serializable { 37 38 40 43 private IdGenerator idGenerator = null; 44 45 48 private CmdID currentId = null; 49 50 52 53 public CommandIdGenerator() { 54 this(new SimpleIdGenerator()); 55 56 } 57 58 63 public CommandIdGenerator(IdGenerator idGenerator) { 64 if (idGenerator == null) { 65 throw new NullPointerException ("idGenerator cannot be null!"); 66 } 67 this.idGenerator = idGenerator; 68 } 69 70 72 77 public synchronized CmdID next() { 78 return (currentId = new CmdID(idGenerator.next())); 79 } 80 81 84 public synchronized void reset() { 85 idGenerator.reset(); 86 } 87 88 93 public synchronized CmdID current() { 94 return currentId; 95 } 96 } | Popular Tags |