- 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 void
Assert that a range test is no longer needed.final Integer
Get the upper bound on the values that can be generated.final Boolean
Determine if a random variable's upper bound can be generated.final Integer
Get the lower bound on the values that can be generated.final Boolean
Determine 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 boolean
rangeTestFailed
(int value) Range test.protected final boolean
Determine if a range test is needed.void
setMaximum
(Integer max, boolean closed) Set the maximum value for a random variable.void
setMinimum
(Integer min, boolean closed) Set the minimum value for a random variable.protected void
setRequiredMaximum
(Integer max, boolean closed) Set the required maximum value for a random variable.protected void
setRequiredMinimum
(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.void
tightenMaximum
(Integer max, boolean closed) Tighten the maximum value for a random variable.void
tightenMaximumS
(String s, boolean closed) Tighten the maximum value for a random variable given a string.void
tightenMinimum
(Integer min, boolean closed) Tighten the minimum value for a random variable.void
tightenMinimumS
(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:RandomVariable
Set the minimum value for a random variable.- Specified by:
setMinimum
in interfaceRandomVariableOps<Integer>
- Overrides:
setMinimum
in 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:RandomVariable
Set 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:
setRequiredMinimum
in 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:RandomVariable
Tighten 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:
tightenMinimumS
in interfaceRandomVariableOps<Integer>
- Specified by:
tightenMinimumS
in 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:RandomVariable
Tighten 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:
tightenMinimum
in interfaceRandomVariableOps<Integer>
- Overrides:
tightenMinimum
in 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:RandomVariable
Set the maximum value for a random variable.- Specified by:
setMaximum
in interfaceRandomVariableOps<Integer>
- Overrides:
setMaximum
in 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:RandomVariable
Set 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:
setRequiredMaximum
in 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:RandomVariable
Tighten 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:
tightenMaximumS
in interfaceRandomVariableOps<Integer>
- Specified by:
tightenMaximumS
in 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:RandomVariable
Tighten 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:
tightenMaximum
in interfaceRandomVariableOps<Integer>
- Overrides:
tightenMaximum
in 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:RandomVariable
Get 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:
getMinimum
in interfaceRandomVariableOps<Integer>
- Overrides:
getMinimum
in classRandomVariable<Integer>
- Returns:
- the lower bound; null if there is none
-
getMinimumClosed
Description copied from class:RandomVariable
Determine if a random variable's lower bound can be generated.- Specified by:
getMinimumClosed
in interfaceRandomVariableOps<Integer>
- Overrides:
getMinimumClosed
in 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:RandomVariable
Get 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:
getMaximum
in interfaceRandomVariableOps<Integer>
- Overrides:
getMaximum
in classRandomVariable<Integer>
- Returns:
- the upper bound; null if there is none
-
getMaximumClosed
Description copied from class:RandomVariable
Determine if a random variable's upper bound can be generated.- Specified by:
getMaximumClosed
in interfaceRandomVariableOps<Integer>
- Overrides:
getMaximumClosed
in 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:RandomVariable
Get a spliterator for a specified number of values.- Overrides:
spliterator
in classRandomVariable<Integer>
- Parameters:
size
- the number of random values to provide- Returns:
- the spliterator
-
spliterator
Description copied from class:RandomVariable
Get a spliterator for an infinite number of values.- Overrides:
spliterator
in 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
-