| 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 | 0 | private Vector<Object> elements = new Vector<Object>(); |
| 11 | 0 | private Vector<Object> cumulative = new Vector<Object>(); |
| 12 | |
|
| 13 | 0 | public DiscreteDistribution() {} |
| 14 | |
|
| 15 | |
public void add(Object o, int n) { |
| 16 | 0 | for (int i = 0; i < n; ++i) |
| 17 | 0 | cumulative.addElement(o); |
| 18 | 0 | elements.addElement(o); |
| 19 | 0 | } |
| 20 | |
|
| 21 | |
public void add(Object o) { |
| 22 | 0 | add(o, 1); |
| 23 | 0 | } |
| 24 | |
|
| 25 | |
public Object sample() { |
| 26 | 0 | return cumulative.elementAt(LoadTest.random.nextInt(cumulative.size())); |
| 27 | |
} |
| 28 | |
|
| 29 | |
public Enumeration<Object> elements() { |
| 30 | 0 | return elements.elements(); |
| 31 | |
} |
| 32 | |
} |