Package net.sf.freecol.common.model
Class RandomRange
- java.lang.Object
-
- net.sf.freecol.common.model.RandomRange
-
public final class RandomRange extends java.lang.ObjectA range of numbers, and support routines to make a random choice therefrom.
-
-
Field Summary
Fields Modifier and Type Field Description private intfactorFactor to multiply the final value with.private static java.lang.StringFACTOR_TAGprivate static java.util.logging.Loggerloggerprivate intmaximumThe inclusive upper bound of the range.private static java.lang.StringMAXIMUM_TAGprivate intminimumThe inclusive lower bound of the range.private static java.lang.StringMINIMUM_TAGprivate intprobabilityPercentage probability that the result is not zero.private static java.lang.StringPROBABILITY_TAG
-
Constructor Summary
Constructors Constructor Description RandomRange(int probability, int minimum, int maximum, int factor)Creates a newRandomRangeinstance.RandomRange(FreeColXMLReader xr)Read a newRandomRangeinstance from a stream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetAmount(java.lang.String prefix, java.util.Random random, boolean continuous)Gets a random value from this range.intgetFactor()Get the multiplication factor.intgetMaximum()Get the range upper bound.intgetMinimum()Get the range lower bound.intgetProbability()Get the result probability.voidreadAttributes(FreeColXMLReader xr)Initializes this object from an XML-representation of this object.voidwriteAttributes(FreeColXMLWriter xw)This method writes an XML-representation of this object to the given stream.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
probability
private int probability
Percentage probability that the result is not zero.
-
minimum
private int minimum
The inclusive lower bound of the range.
-
maximum
private int maximum
The inclusive upper bound of the range.
-
factor
private int factor
Factor to multiply the final value with.
-
FACTOR_TAG
private static final java.lang.String FACTOR_TAG
- See Also:
- Constant Field Values
-
MAXIMUM_TAG
private static final java.lang.String MAXIMUM_TAG
- See Also:
- Constant Field Values
-
MINIMUM_TAG
private static final java.lang.String MINIMUM_TAG
- See Also:
- Constant Field Values
-
PROBABILITY_TAG
private static final java.lang.String PROBABILITY_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
RandomRange
public RandomRange(int probability, int minimum, int maximum, int factor)Creates a newRandomRangeinstance.- Parameters:
probability- The probability of this result.minimum- The range inclusive minimum.maximum- The range inclusive maximum.factor- The result multiplier.
-
RandomRange
public RandomRange(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Read a newRandomRangeinstance from a stream.- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
-
Method Detail
-
getProbability
public final int getProbability()
Get the result probability.- Returns:
- The probability.
-
getMinimum
public final int getMinimum()
Get the range lower bound.- Returns:
- The lower bound.
-
getMaximum
public final int getMaximum()
Get the range upper bound.- Returns:
- The upper bound.
-
getFactor
public final int getFactor()
Get the multiplication factor.- Returns:
- The factor.
-
getAmount
public int getAmount(java.lang.String prefix, java.util.Random random, boolean continuous)Gets a random value from this range.- Parameters:
prefix- A logger prefix.random- A pseudo-random number source.continuous- Choose a continuous or discrete result.- Returns:
- A random amount of plunder as defined by this
RandomRange.
-
writeAttributes
public void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.- Parameters:
xw- TheFreeColXMLWriterto write to.- Throws:
javax.xml.stream.XMLStreamException- if there are any problems writing to the stream.
-
readAttributes
public void readAttributes(FreeColXMLReader xr)
Initializes this object from an XML-representation of this object.- Parameters:
xr- The input stream with the XML.
-
-