1 18 19 package sync4j.framework.tools; 20 21 import sync4j.framework.tools.IdGenerator; 22 23 31 public final class SimpleIdGenerator 32 implements IdGenerator, java.io.Serializable { 33 34 36 39 private long counter = 0; 40 41 public long getCounter() 42 { 43 return counter; 44 } 45 46 49 public void setCounter(long counter) 50 { 51 this.counter = counter; 52 } 53 54 57 private int increment = 1; 58 59 public int getIncrement() 60 { 61 return increment; 62 } 63 64 67 public void setIncrement(int increment) 68 { 69 this.increment = increment; 70 } 71 72 74 80 public SimpleIdGenerator(long counter, int increment) 81 { 82 this.counter = counter; 83 this.increment = increment; 84 } 85 86 91 public SimpleIdGenerator(int counter) 92 { 93 this(counter, 1); 94 } 95 96 99 public void reset() 100 { 101 this.counter = 0; 102 } 103 104 107 public SimpleIdGenerator() 108 { 109 this(0, 1); 110 } 111 112 118 public synchronized String next() 119 { 120 counter += increment; 121 122 return String.valueOf(counter); 123 } 124 125 130 public synchronized String current() 131 { 132 return String.valueOf(counter); 133 } 134 } | Popular Tags |