- All Implemented Interfaces:
Cloneable,RandomVariableOps<Integer>
- Direct Known Subclasses:
BinomialIntegerRV,DetermIntegerRV,FixedIntegerRV,PoissonIntegerRV,UniformIntegerRV
Base class for Integer-valued random numbers.
Implements the tightenMinimumS, tighenMaximumS, setRequiredMininum,
setRequiredMaximum setMinimum, setMaximum, tightenMinimum, and
tightenMaximum methods from the RandomVariable interface, and
introduces a protected method, rangeTestFailed, for use by
subclasses.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAssert that a range test is no longer needed.final IntegerGet the upper bound on the values that can be generated.final BooleanDetermine if a random variable's upper bound can be generated.final IntegerGet the lower bound on the values that can be generated.final BooleanDetermine if a random variable's lower bound can be generated.Get an infinite parallel stream of integer values.parallelStream(long size) Get a fixed-length parallel stream of integer values.protected final booleanrangeTestFailed(int value) Range test.protected final booleanDetermine if a range test is needed.voidsetMaximum(Integer max, boolean closed) Set the maximum value for a random variable.voidsetMinimum(Integer min, boolean closed) Set the minimum value for a random variable.protected voidsetRequiredMaximum(Integer max, boolean closed) Set the required maximum value for a random variable.protected voidsetRequiredMinimum(Integer min, boolean closed) Set a required minimum value for a random variable.Get a spliterator for an infinite number of values.spliterator(long size) Get a spliterator for a specified number of values.stream()Get an infinie stream of integer values.stream(long size) Get a fixed-length stream of integer values.voidtightenMaximum(Integer max, boolean closed) Tighten the maximum value for a random variable.voidtightenMaximumS(String s, boolean closed) Tighten the maximum value for a random variable given a string.voidtightenMinimum(Integer min, boolean closed) Tighten the minimum value for a random variable.voidtightenMinimumS(String s, boolean closed) Tighten the minimum value for a random variable given a string.Methods inherited from class org.bzdev.math.rv.RandomVariable
clone, getCharacteristics, next
-
Constructor Details
-
IntegerRandomVariable
public IntegerRandomVariable()
-
-
Method Details
-
setMinimum
public void setMinimum(Integer min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableSet the minimum value for a random variable.- Specified by:
setMinimumin interfaceRandomVariableOps<Integer>- Overrides:
setMinimumin classRandomVariable<Integer>- Parameters:
min- minimum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
setRequiredMinimum
protected void setRequiredMinimum(Integer min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableSet a required minimum value for a random variable. Normally this is called by a constructor to prevent a random variable from having values outside a range that makes sense.- Overrides:
setRequiredMinimumin classRandomVariable<Integer>- Parameters:
min- minimum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
tightenMinimumS
public void tightenMinimumS(String s, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableTighten the minimum value for a random variable given a string. If there is no minimum value, it will be set. Otherwise the minimum of the allowed range will not decrease. The string argument is a number in a format acceptable to the constructors for Integer, Long, or Double as appropriate.- Specified by:
tightenMinimumSin interfaceRandomVariableOps<Integer>- Specified by:
tightenMinimumSin classRandomVariable<Integer>- Parameters:
s- minimum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
tightenMinimum
public void tightenMinimum(Integer min, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableTighten the minimum value for a random variable. If there is no minimum value, it will be set. Otherwise the minimum of the allowed range will not decrease.- Specified by:
tightenMinimumin interfaceRandomVariableOps<Integer>- Overrides:
tightenMinimumin classRandomVariable<Integer>- Parameters:
min- minimum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
setMaximum
public void setMaximum(Integer max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableSet the maximum value for a random variable.- Specified by:
setMaximumin interfaceRandomVariableOps<Integer>- Overrides:
setMaximumin classRandomVariable<Integer>- Parameters:
max- maximum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
setRequiredMaximum
protected void setRequiredMaximum(Integer max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableSet the required maximum value for a random variable. Normally this is called by a constructor to prevent a random variable from having values outside a range that makes sense.- Overrides:
setRequiredMaximumin classRandomVariable<Integer>- Parameters:
max- maximum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
tightenMaximumS
public void tightenMaximumS(String s, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableTighten the maximum value for a random variable given a string. If there is no maximum value, it will be set. Otherwise the maximum of the allowed range will not increase. The string argument is a number in a format acceptable to the constructors for Integer, Long, or Double as appropriate.- Specified by:
tightenMaximumSin interfaceRandomVariableOps<Integer>- Specified by:
tightenMaximumSin classRandomVariable<Integer>- Parameters:
s- maximum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
tightenMaximum
public void tightenMaximum(Integer max, boolean closed) throws UnsupportedOperationException, IllegalArgumentException Description copied from class:RandomVariableTighten the maximum value for a random variable. If there is no maximum value, it will be set. Otherwise the maximum of the allowed range will not increase.- Specified by:
tightenMaximumin interfaceRandomVariableOps<Integer>- Overrides:
tightenMaximumin classRandomVariable<Integer>- Parameters:
max- maximum value.closed- true if the minimum value is part of the range; false if it is a lower bound on the range- Throws:
UnsupportedOperationException- the random variable's type does not have an order imposed on it or the operation is not supported for implementation reasonsIllegalArgumentException- an argument is out of range
-
rangeTestNeeded
protected final boolean rangeTestNeeded()Determine if a range test is needed.- Returns:
- true if a range test is needed; false if the range check would always succeed
-
clearRangeTest
protected void clearRangeTest()Assert that a range test is no longer needed. This should be called only if a subclass can ensure that calls to next() will always be in the specified range. The range test may be reset if setMinimum, setMaximum, tightenMinimum, tightenMaximum, setRequiredMinimum, setRequiredMaximum, tightenMinimumS, or tightenMaximumS are called. -
rangeTestFailed
protected final boolean rangeTestFailed(int value) Range test. Subclasses implementing next() should call this method to ensure that a randomly generated value is in the range set by calls to setMinimum and setMaximum.- Parameters:
value- the value to test- Returns:
- true if the range-test failed; false otherwise
-
getMinimum
Description copied from class:RandomVariableGet the lower bound on the values that can be generated. Some random numbers do not have an ordering, so that null will always be returned in that case.- Specified by:
getMinimumin interfaceRandomVariableOps<Integer>- Overrides:
getMinimumin classRandomVariable<Integer>- Returns:
- the lower bound; null if there is none
-
getMinimumClosed
Description copied from class:RandomVariableDetermine if a random variable's lower bound can be generated.- Specified by:
getMinimumClosedin interfaceRandomVariableOps<Integer>- Overrides:
getMinimumClosedin classRandomVariable<Integer>- Returns:
- true if it can be generated; false if it cannot be generated; null if this cannot be determined
-
getMaximum
Description copied from class:RandomVariableGet the upper bound on the values that can be generated. Some random numbers do not have an ordering, so that null will always be returned in that case.- Specified by:
getMaximumin interfaceRandomVariableOps<Integer>- Overrides:
getMaximumin classRandomVariable<Integer>- Returns:
- the upper bound; null if there is none
-
getMaximumClosed
Description copied from class:RandomVariableDetermine if a random variable's upper bound can be generated.- Specified by:
getMaximumClosedin interfaceRandomVariableOps<Integer>- Overrides:
getMaximumClosedin classRandomVariable<Integer>- Returns:
- true if it can be generated; false if it cannot be generated; null if this cannot be determined
-
spliterator
Description copied from class:RandomVariableGet a spliterator for a specified number of values.- Overrides:
spliteratorin classRandomVariable<Integer>- Parameters:
size- the number of random values to provide- Returns:
- the spliterator
-
spliterator
Description copied from class:RandomVariableGet a spliterator for an infinite number of values.- Overrides:
spliteratorin classRandomVariable<Integer>- Returns:
- the spliterator
-
stream
Get a fixed-length stream of integer values.- Parameters:
size- the number of random values to provide- Returns:
- the stream
-
parallelStream
Get a fixed-length parallel stream of integer values.- Parameters:
size- the number of random values to provide- Returns:
- the stream
-
stream
Get an infinie stream of integer values.- Returns:
- the stream
-
parallelStream
Get an infinite parallel stream of integer values.- Returns:
- the stream
-