Class Distribution<O>
java.lang.Object
org.opentrafficsim.core.distributions.Distribution<O>
- Type Parameters:
O
- Type of the object returned by the draw method
- All Implemented Interfaces:
Serializable
,Generator<O>
Generic implementation of a set of objects that have a draw method with corresponding probabilities / frequencies.
Copyright (c) 2013-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
- Author:
- Peter Knoppers
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDistribution
(List<FrequencyAndObject<O>> generators, nl.tudelft.simulation.jstats.streams.StreamInterface stream) Construct a new Distribution.Distribution
(nl.tudelft.simulation.jstats.streams.StreamInterface stream) Construct a new Distribution with no generators. -
Method Summary
Modifier and TypeMethodDescriptionfinal Distribution<O>
add
(int index, FrequencyAndObject<O> generator) Insert a generator at the specified position in the internally stored list.final Distribution<O>
add
(FrequencyAndObject<O> generator) Append a generator to the internally stored list.final Distribution<O>
clear()
Empty the internally stored list.final O
draw()
Generate the next object.final boolean
final FrequencyAndObject<O>
get
(int index) Retrieve one of the internally stored generators.final int
hashCode()
final Distribution<O>
modifyFrequency
(int index, double frequency) Alter the frequency (or probability) of one of the stored generators.final Distribution<O>
remove
(int index) Remove the generator at the specified position from the internally stored list.final Distribution<O>
set
(int index, FrequencyAndObject<O> generator) Replace the generator at the specified position.final int
size()
Report the number of generators.final String
toString()
-
Constructor Details
-
Distribution
public Distribution(List<FrequencyAndObject<O>> generators, nl.tudelft.simulation.jstats.streams.StreamInterface stream) Construct a new Distribution.- Parameters:
generators
- the generators and their frequencies (or probabilities)stream
- source for randomness- Throws:
NullPointerException
- when generators is null or stream is nullIllegalArgumentException
- when a frequency (or probability) is negative
-
Distribution
public Distribution(nl.tudelft.simulation.jstats.streams.StreamInterface stream) Construct a new Distribution with no generators.- Parameters:
stream
- source for randomness- Throws:
NullPointerException
- when generators is null or stream is null
-
-
Method Details
-
draw
Description copied from interface:Generator
Generate the next object. -
add
Append a generator to the internally stored list.- Parameters:
generator
- the generator to add- Returns:
- this
- Throws:
NullPointerException
- when generator is null
-
add
Insert a generator at the specified position in the internally stored list.- Parameters:
index
- position to store the generatorgenerator
- the generator to add- Returns:
- this
- Throws:
IndexOutOfBoundsException
- when index is < 0 or >= sizeNullPointerException
- when generator is null
-
remove
Remove the generator at the specified position from the internally stored list.- Parameters:
index
- the position- Returns:
- this
- Throws:
IndexOutOfBoundsException
- when index is < 0 or >= size
-
set
Replace the generator at the specified position.- Parameters:
index
- the position of the generator that must be replacedgenerator
- the new generator and the frequency (or probability)- Returns:
- this
- Throws:
IndexOutOfBoundsException
- when index is < 0 or >= sizeNullPointerException
- when generator is null
-
modifyFrequency
Alter the frequency (or probability) of one of the stored generators.- Parameters:
index
- index of the stored generatorfrequency
- new frequency (or probability)- Returns:
- this
- Throws:
IndexOutOfBoundsException
- when index is < 0 or >= sizeIllegalArgumentException
- when the frequency (or probability) < 0
-
clear
Empty the internally stored list.- Returns:
- this
-
get
Retrieve one of the internally stored generators.- Parameters:
index
- the index of the FrequencyAndObject to retrieve- Returns:
- the generator stored at position index
- Throws:
IndexOutOfBoundsException
- when index < 0 or >= size()
-
size
public final int size()Report the number of generators.- Returns:
- the number of generators
-
hashCode
public final int hashCode() -
equals
-
toString
-