|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcz.zcu.fav.kiv.jsim.random.JSimUserObjectStream
public class JSimUserObjectStream
A stream generating user-defined objects according to their corresponding user-defined absolute rates. The probability that a certain object will be returned by the getNext() method is equal to the ratio its_absolute_rate / sum_of_all_absolute_rates. All objects specified by the user must be non-null, all absolute rates must be non-negative. An initial seed can be specified, which allows you to generate the same sequence of user objects several times.
Field Summary | |
---|---|
private double[] |
cumulativeRates
Cumulative rates of object occurence. |
private java.lang.Object[] |
objects
The objects specified by the user and returned by getNext(). |
private double[] |
rates
The absolute rates of object occurence. |
protected java.util.Random |
stream
An internal stream from which random numbers are taken to compute an object. |
private double |
sumOfRates
The sum of all rates. |
Constructor Summary | |
---|---|
JSimUserObjectStream(java.lang.Object[] objects,
double[] rates)
Creates a new user object stream. |
|
JSimUserObjectStream(java.lang.Object[] objects,
double[] rates,
long seed)
Creates a new user object stream. |
Method Summary | |
---|---|
java.lang.Object |
getNext()
Returns a randomly selected user object. |
java.lang.Object[] |
getObjects()
Returns a copy of user objects returned by getNext(). |
double[] |
getRates()
Returns a copy of rates used by the generator. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.util.Random stream
private java.lang.Object[] objects
private double[] rates
private double[] cumulativeRates
private double sumOfRates
Constructor Detail |
---|
public JSimUserObjectStream(java.lang.Object[] objects, double[] rates) throws JSimInvalidParametersException
objects
- User objects to be returned by getNext(). No object of the array can be null. The length of the array must be positive and
equal to the lenght of rates.rates
- The absolute rates of occurence of user-defined objects. Every rate must be non-negative. The length of the array must be
positive and equal to the lenght of objects.
JSimInvalidParametersException
- This exception is thrown out if the arrays of objects and rates are null, have zero length, have different lengths, or
an item of the arrays is null or less than zero, respectively.public JSimUserObjectStream(java.lang.Object[] objects, double[] rates, long seed) throws JSimInvalidParametersException
objects
- User objects to be returned by getNext(). No object of the array can be null. The length of the array must be positive and
equal to the lenght of rates.rates
- The absolute rates of occurence of user-defined objects. Every rate must be non-negative. The length of the array must be
positive and equal to the lenght of objects.seed
- A seed that will initialize the generator.
JSimInvalidParametersException
- This exception is thrown out if the arrays of objects and rates are null, have zero length, have different lengths, or
an item of the arrays is null or less than zero, respectively.Method Detail |
---|
public java.lang.Object getNext()
public java.lang.Object[] getObjects()
public double[] getRates()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |