// Copyright © 2011 - 2012 Forerunner Games
package com.forerunnergames.tools;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 *
 * @author Aaron Mahan
 */
public class DiceUtils 
{
  // Begin public interface

  /**
   * Get a preset (fake) dice roll. Useful for testing purposes.
   * It will get a preset (fake) dice roll until the presets are all used up,
   * and then it will return 6 on each subsequent call.
   * 
   * @see DiceUtils#setTestRolls(int... rollAmounts) 
   * 
   * @return The roll amount.
   */
  public static int getTestRoll()
  {
    int rollAmount;

    if (DiceUtils.currentTestRoll < DiceUtils.testRolls.size())
    {
      rollAmount = DiceUtils.testRolls.get (DiceUtils.currentTestRoll);
    }
    else
    {
      rollAmount = 6;
    }

    ++DiceUtils.currentTestRoll;

    return rollAmount;
  }

  /**
   * Create preset (fake) dice rolls. Useful for testing purposes.
   * The rolls are used on a first-in first-out basis.
   * 
   * @see DiceUtils#getTestRoll() 
   * 
   * @param rollAmounts The list of preset (fake) roll amounts.
   */
  public static void setTestRolls (int... rollAmounts)
  {
    DiceUtils.testRolls = new ArrayList <Integer>();

    for (int i = 0; i < rollAmounts.length; ++i)
    {
      testRolls.add (rollAmounts [i]);
    }
  }

  /**
   * Roll diceCount 6-sided dice and get the resulting roll amounts.
   * 
   * @param diceCount The number of dice to roll.
   * 
   * @return A collection of the roll amounts as integers.
   */
  public static Collection <Integer> rollDice (int diceCount)
  {
    Arguments.checkLowerExclusiveBound (diceCount, 0, "diceCount");

    Collection <Integer> rolls = new ArrayList <Integer> (diceCount);

    for (int i = 0; i < diceCount; ++i)
    {
      int rollAmount = 
              RandomUtils.getRandomIntegerBetween (1, DiceUtils.FACES_PER_DIE);

      rolls.add (rollAmount);
    }

    return rolls;
  }

  public static int rollSum (int diceCount)
  {
    Arguments.checkLowerExclusiveBound (diceCount, 0, "diceCount");

    int sum = 0;

    for (Integer rollAmount : rollDice (diceCount))
    {
      sum += rollAmount;
    }

    return sum;
  }

  // End public interface

  // --------------------

  // Begin private interface

  private static int currentTestRoll = 0;

  private static List <Integer> testRolls;

  private static final int FACES_PER_DIE = 6;

  private DiceUtils()
  {
    ClassUtils.instantiationNotAllowed();
  }

  // End private interface
}

@@ -1344,17 +1344,16 @@
  Roll di
-c
 eCount 6
@@ -1420,17 +1420,16 @@
 param di
-c
 eCount T
@@ -1571,33 +1571,32 @@
 rollDice (int di
-c
 eCount)%0A  %7B%0A    
@@ -1625,33 +1625,32 @@
 clusiveBound (di
-c
 eCount, 0, %22dice
@@ -1639,33 +1639,32 @@
 dieCount, 0, %22di
-c
 eCount%22);%0A%0A    C
@@ -1714,25 +1714,24 @@
 Integer%3E (di
-c
 eCount);%0A%0A  
@@ -1754,17 +1754,16 @@
 ; i %3C di
-c
 eCount; 
@@ -1938,16 +1938,212 @@
 s;%0A  %7D%0A%0A
+  /**%0A   * Roll dieCount 6-sided dice and get the resulting roll sum.%0A   * %0A   * @param dieCount The number of dice to roll.%0A   * %0A   * @return The sum of the values of the individual dice.%0A   */%0A
   public
@@ -2169,17 +2169,16 @@
  (int di
-c
 eCount)%0A
@@ -2219,25 +2219,24 @@
 iveBound (di
-c
 eCount, 0, %22
@@ -2237,17 +2237,16 @@
 , 0, %22di
-c
 eCount%22)
@@ -2308,17 +2308,16 @@
 Dice (di
-c
 eCount))

Add javadoc and rename parameter