1 package org.paneris.bibliomania.loadtest; 2 3 import java.io.Serializable; 4 import java.util.Enumeration; 5 import java.util.Vector; 6 7 class DiscreteDistribution implements Serializable { 8 private static final long serialVersionUID = -3646912334575385881L; 9 10 private Vector<Object> elements = new Vector<Object>(); 11 private Vector<Object> cumulative = new Vector<Object>(); 12 13 public DiscreteDistribution() {} 14 15 public void add(Object o, int n) { 16 for (int i = 0; i < n; ++i) 17 cumulative.addElement(o); 18 elements.addElement(o); 19 } 20 21 public void add(Object o) { 22 add(o, 1); 23 } 24 25 public Object sample() { 26 return cumulative.elementAt(LoadTest.random.nextInt(cumulative.size())); 27 } 28 29 public Enumeration<Object> elements() { 30 return elements.elements(); 31 } 32 }