Class ListNumberGenerator

java.lang.Object
ListNumberGenerator
All Implemented Interfaces:
NumberGenerator

public class ListNumberGenerator
extends Object
implements NumberGenerator
Produces deterministic numbers by iterating repeatedly over a list or array of integers argued in the constructors.
  • Field Summary

    Fields
    Modifier and Type Field Description
    (package private) int index  
    (package private) List<Integer> list  
    (package private) int smallestUpperBound  
  • Constructor Summary

    Constructors
    Constructor Description
    ListNumberGenerator​(Integer[] arr)
    Creates a ListNumberGenerator which generates numbers based off of an array of possible integers.
    ListNumberGenerator​(List<Integer> list)
    Creates a ListNumberGenerator which generates numbers based off of a list of possible integers.
  • Method Summary

    Modifier and Type Method Description
    int next()
    Returns the next integer available in the list.
    int next​(int bound)
    Returns the next integer available in the list that is less than the specified bound.

    Methods inherited from class java.lang.Object

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

    • list

      final List<Integer> list
    • index

      int index
    • smallestUpperBound

      int smallestUpperBound
  • Constructor Details

    • ListNumberGenerator

      public ListNumberGenerator​(List<Integer> list)
      Creates a ListNumberGenerator which generates numbers based off of a list of possible integers.
      Parameters:
      list - - an list of integers to step through and output in the generator.
    • ListNumberGenerator

      public ListNumberGenerator​(Integer[] arr)
      Creates a ListNumberGenerator which generates numbers based off of an array of possible integers.
      Parameters:
      arr - - an array of integers to step through and output in the generator.
  • Method Details

    • next

      public int next()
      Returns the next integer available in the list.
      Returns:
      an unbounded number from the list.
    • next

      public int next​(int bound)
      Returns the next integer available in the list that is less than the specified bound.
      Specified by:
      next in interface NumberGenerator
      Parameters:
      bound - - the max value that can be returned by this call to next.
      Returns:
      a number between 0 and bound (inclusive)