Module hw06

Class Randomizer

java.lang.Object
provided.utils.valueGenerator.impl.Randomizer
All Implemented Interfaces:
IRandomizer

public class Randomizer extends Object implements IRandomizer
Concrete implementation of IRandomizer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static Randomizer
    Singleton instance of this class
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private constructor for use by the Singleton only..
  • Method Summary

    Modifier and Type
    Method
    Description
    randomBounds​(Rectangle rect, Dimension maxDim)
    Generates a randomly located and sized rectangle
    randomChoice​(Object x, Object y, double probX)
    Returns a random choice of one of two objects, x and y, where probX is the probability that x will be picked (0<=x<=1).
    Generates a random color
    randomDim​(Dimension maxDim)
    Returns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.width
    double
    randomDouble​(double min, double max)
    Returns a random double greater than or equal to min and less than max.
    int
    randomInt​(int min, int max)
    Returns a random integer greater than or equal to min and less than or equal to max.
    Generates a random location point subject to the constraint that 0<=X<=dim.width and 0<=Y<=dim.height.
    Generates a random location point subject to the constraint that rect.x<=X<=rect.x+rect.width and rect.y<=Y<=rect.y+rect.height.
    Returns a random velocity (as a Point) subject to the constraint that the absolute value of the velocity (speed) within the bound (inclusive) defined by rect.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • Singleton

      public static Randomizer Singleton
      Singleton instance of this class
  • Constructor Details

    • Randomizer

      private Randomizer()
      Private constructor for use by the Singleton only..
  • Method Details

    • randomLoc

      public Point randomLoc(Rectangle rect)
      Description copied from interface: IRandomizer
      Generates a random location point subject to the constraint that rect.x<=X<=rect.x+rect.width and rect.y<=Y<=rect.y+rect.height. Note that the definition of a Rectangle object requires that (x,y) be defined as the upper left corner and that width and height must both be non-negative.
      Specified by:
      randomLoc in interface IRandomizer
      Parameters:
      rect - The bounds for the x and y values of the created Point
      Returns:
      A Point object whose x and y are subject to the given bounds
    • randomLoc

      public Point randomLoc(Dimension dim)
      Description copied from interface: IRandomizer
      Generates a random location point subject to the constraint that 0<=X<=dim.width and 0<=Y<=dim.height.
      Specified by:
      randomLoc in interface IRandomizer
      Parameters:
      dim - The bounds for the x and y values of the created Point
      Returns:
      A Point object whose x and y are subject to the given bounds
    • randomInt

      public int randomInt(int min, int max)
      Description copied from interface: IRandomizer
      Returns a random integer greater than or equal to min and less than or equal to max.
      Specified by:
      randomInt in interface IRandomizer
      Parameters:
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      an int subject to the given bounds
    • randomDouble

      public double randomDouble(double min, double max)
      Description copied from interface: IRandomizer
      Returns a random double greater than or equal to min and less than max.
      Specified by:
      randomDouble in interface IRandomizer
      Parameters:
      min - The minimum allowed value
      max - The maximum allowed value
      Returns:
      a double subject to the given bounds
    • randomVel

      public Point randomVel(Rectangle rect)
      Description copied from interface: IRandomizer
      Returns a random velocity (as a Point) subject to the constraint that the absolute value of the velocity (speed) within the bound (inclusive) defined by rect. Thus the resultant velocity may be negative. The given Rectangle should use all positive values. To create velocities or any Point with asymmetrical bounds, use the randomLoc(Rectangle rect) method with the input rectangle set to the desired bounds.
      Specified by:
      randomVel in interface IRandomizer
      Parameters:
      rect - The bounds for the absolute value of the velocity in the x and y directions.
      Returns:
      a Point object with x and y subject to the given bounds.
    • randomDim

      public Dimension randomDim(Dimension maxDim)
      Description copied from interface: IRandomizer
      Returns a random square Dimension, whose width is maxDim.width/2<=width<=maxDim.width
      Specified by:
      randomDim in interface IRandomizer
      Parameters:
      maxDim - The bounds on the side of the created Dimension.
      Returns:
      A random square Dimension subject to the given bound
    • randomBounds

      public Rectangle randomBounds(Rectangle rect, Dimension maxDim)
      Description copied from interface: IRandomizer
      Generates a randomly located and sized rectangle
      Specified by:
      randomBounds in interface IRandomizer
      Parameters:
      rect - The bounds for the location of the created rectangle
      maxDim - The bounds for the dimensions of the create rectangle
      Returns:
      A Rectangle with location and dimensions subject to the given bounds.
    • randomColor

      public Color randomColor()
      Description copied from interface: IRandomizer
      Generates a random color
      Specified by:
      randomColor in interface IRandomizer
      Returns:
      a random Color object
    • randomChoice

      public Object randomChoice(Object x, Object y, double probX)
      Description copied from interface: IRandomizer
      Returns a random choice of one of two objects, x and y, where probX is the probability that x will be picked (0<=x<=1).
      Specified by:
      randomChoice in interface IRandomizer
      Parameters:
      x - The first of two choices
      y - The second of two choices
      probX - The probability of the first choice
      Returns:
      Either x or y as per the probability of choosing them.