O - Type of the object returned by the draw methodpublic class Distribution<O> extends Object implements Generator<O>, Serializable
 Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. 
 BSD-style license. See OpenTrafficSim License.
 
| Modifier and Type | Class and Description | 
|---|---|
| static class  | Distribution.FrequencyAndObject<O>Immutable storage for a frequency (or probability) plus a Generator. | 
| Constructor and Description | 
|---|
| Distribution(List<Distribution.FrequencyAndObject<O>> generators,
            StreamInterface stream)Construct a new Distribution. | 
| Distribution(StreamInterface stream)Construct a new Distribution with no generators. | 
| Modifier and Type | Method and Description | 
|---|---|
| Distribution<O> | add(Distribution.FrequencyAndObject<O> generator)Append a generator to the internally stored list. | 
| Distribution<O> | add(int index,
   Distribution.FrequencyAndObject<O> generator)Insert a generator at the specified position in the internally stored list. | 
| Distribution<O> | clear()Empty the internally stored list. | 
| O | draw()Generate the next object. | 
| boolean | equals(Object obj) | 
| Distribution.FrequencyAndObject<O> | get(int index)Retrieve one of the internally stored generators. | 
| int | hashCode() | 
| Distribution<O> | modifyFrequency(int index,
               double frequency)Alter the frequency (or probability) of one of the stored generators. | 
| Distribution<O> | remove(int index)Remove the generator at the specified position from the internally stored list. | 
| Distribution<O> | set(int index,
   Distribution.FrequencyAndObject<O> generator)Replace the generator at the specified position. | 
| int | size()Report the number of generators. | 
| String | toString() | 
public Distribution(List<Distribution.FrequencyAndObject<O>> generators, StreamInterface stream) throws ProbabilityException
generators - List<FrequencyAndObject<O>>; the generators and their frequencies (or probabilities)stream - StreamInterface; source for randomnessProbabilityException - when a frequency (or probability) is negative, or when generators is null or stream is nullpublic Distribution(StreamInterface stream) throws ProbabilityException
stream - StreamInterface; source for randomnessProbabilityException - when a frequency (or probability) is negative, or when generators is null or stream is nullpublic final O draw() throws ProbabilityException
draw in interface Generator<O>ProbabilityException - if the stored collection is emptypublic final Distribution<O> add(Distribution.FrequencyAndObject<O> generator) throws ProbabilityException
generator - FrequencyAndObject<O>; the generator to addProbabilityException - when frequency less than zeropublic final Distribution<O> add(int index, Distribution.FrequencyAndObject<O> generator) throws ProbabilityException
index - int; position to store the generatorgenerator - FrequencyAndObject<O>; the generator to addProbabilityException - when frequency less than zeropublic final Distribution<O> remove(int index) throws IndexOutOfBoundsException, ProbabilityException
index - int; the positionIndexOutOfBoundsException - when index is < 0 or >= sizeProbabilityException - if the sum of the remaining probabilities or frequencies adds up to 0public final Distribution<O> set(int index, Distribution.FrequencyAndObject<O> generator) throws ProbabilityException
index - int; the position of the generator that must be replacedgenerator - FrequencyAndObject<O>; the new generator and the frequency (or probability)ProbabilityException - when the frequency (or probability) < 0, or when index is < 0 or >= sizepublic final Distribution<O> modifyFrequency(int index, double frequency) throws ProbabilityException
index - int; index of the stored generatorfrequency - double; new frequency (or probability)ProbabilityException - when the frequency (or probability) < 0, or when index is < 0 or >= sizepublic final Distribution<O> clear()
public final Distribution.FrequencyAndObject<O> get(int index) throws ProbabilityException
index - int; the index of the FrequencyAndObject to retrieveProbabilityException - when index < 0 or >= size()public final int size()
Copyright © 2014–2019 Delft University of Technology. All rights reserved.