Class RandomRange


  • public final class RandomRange
    extends java.lang.Object
    A range of numbers, and support routines to make a random choice therefrom.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int factor
      Factor to multiply the final value with.
      private static java.lang.String FACTOR_TAG  
      private static java.util.logging.Logger logger  
      private int maximum
      The inclusive upper bound of the range.
      private static java.lang.String MAXIMUM_TAG  
      private int minimum
      The inclusive lower bound of the range.
      private static java.lang.String MINIMUM_TAG  
      private int probability
      Percentage probability that the result is not zero.
      private static java.lang.String PROBABILITY_TAG  
    • Constructor Summary

      Constructors 
      Constructor Description
      RandomRange​(int probability, int minimum, int maximum, int factor)
      Creates a new RandomRange instance.
      RandomRange​(FreeColXMLReader xr)
      Read a new RandomRange instance from a stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getAmount​(java.lang.String prefix, java.util.Random random, boolean continuous)
      Gets a random value from this range.
      int getFactor()
      Get the multiplication factor.
      int getMaximum()
      Get the range upper bound.
      int getMinimum()
      Get the range lower bound.
      int getProbability()
      Get the result probability.
      void readAttributes​(FreeColXMLReader xr)
      Initializes this object from an XML-representation of this object.
      void writeAttributes​(FreeColXMLWriter xw)
      This method writes an XML-representation of this object to the given stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.
    • Constructor Detail

      • RandomRange

        public RandomRange​(int probability,
                           int minimum,
                           int maximum,
                           int factor)
        Creates a new RandomRange instance.
        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 new RandomRange instance from a stream.
        Parameters:
        xr - The FreeColXMLReader to 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 - The FreeColXMLWriter to 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.