1 package net.sf.dexterim.oscar.client; 2 3 import java.util.Random; 4 5 /*** 6 * @author christoph 7 * 8 */ 9 public class FlapSequencer { 10 private static FlapSequencer instance; 11 private static final int BOUNDS = 0x0800; 12 13 private int id; 14 15 protected FlapSequencer() { 16 this.id = first(); 17 } 18 19 public int next() { 20 if (++id >= BOUNDS) { 21 id = reset(); 22 } 23 24 return id; 25 } 26 27 public int current() { 28 return id; 29 } 30 31 protected final int first() { 32 Random rand = new Random(); 33 return rand.nextInt(BOUNDS); 34 } 35 36 protected int reset() { 37 return 0; 38 } 39 40 public static synchronized FlapSequencer getInstance() { 41 if (instance == null) { 42 instance = new FlapSequencer(); 43 } 44 45 return instance; 46 } 47 }