Class Bag

java.lang.Object
  extended byBag

public class Bag
extends java.lang.Object

This class contains the bag of letters for a current ScrabbleBuilder. Class also provides methods for operating on the bag of letters.

Version:
2.0
Author:
3GP01 - Hardev Bhamra, Deepak Chandarana, Kevin Lano, James Tompkin
See Also:
Game, Letter

Constructor Summary
Bag(ScrabbleBuilder builder)
          Constructs a new bag for a given Scrabblebuilder
 
Method Summary
 int getBagValue()
          Returns an int containing the current score sum of the bag.
 Letter getLetter(int i)
          Returns a Letter at a specific i in the bag.
 java.util.List getLetters()
          Returns a List, the bag.
 int getSize()
          Returns an int containing the current size of the bag.
 java.util.List giveLetters(int giving)
          Allocates a random selection of new letters to a list, the size of the required number of letters.
 java.util.List giveLetters(int giving, boolean remote)
          Overloaded method of giveLetters.
 boolean isEmpty()
          Tests to see whether the bag of letters is empty.
 void replaceLetters(java.util.List list)
          Method takes a list of letters and replaces (into the bag) all letters from the list
 void setLetters(java.util.List letters)
          Sets the current bag to be the input List letters.
 java.lang.String toString()
          Returns a String representation of the bag.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Bag

public Bag(ScrabbleBuilder builder)
Constructs a new bag for a given Scrabblebuilder

Parameters:
builder - The ScrabbleBuilder of the game you'd like to create a bag for.
Method Detail

getLetter

public Letter getLetter(int i)
Returns a Letter at a specific i in the bag.

Parameters:
i - The specific location in the bag of the letter to return.
Returns:
Letter The specific letter in the bag.

getBagValue

public int getBagValue()
Returns an int containing the current score sum of the bag.

Returns:
int The total score of the current bag.

getSize

public int getSize()
Returns an int containing the current size of the bag.

Returns:
int The size of the current bag.

getLetters

public java.util.List getLetters()
Returns a List, the bag.

Returns:
List The total score of the current bag.

isEmpty

public boolean isEmpty()
Tests to see whether the bag of letters is empty.

Returns:
A boolean value (true or false)

setLetters

public void setLetters(java.util.List letters)
Sets the current bag to be the input List letters.

Parameters:
letters - A List containing the letters the bag should be set to.

toString

public java.lang.String toString()
Returns a String representation of the bag.

Returns:
String The bag.

giveLetters

public java.util.List giveLetters(int giving)
Allocates a random selection of new letters to a list, the size of the required number of letters.

Parameters:
giving - The number of letters needed to be returned to the rack.
Returns:
List The list containing the returned letters.

giveLetters

public java.util.List giveLetters(int giving,
                                  boolean remote)
Overloaded method of giveLetters. If remote is fed, method will return the number of required letters (giving). The method will not return a random selection, as the remote game uses a 'static' bag of pre-randomised letters.

Parameters:
giving - The number of letters needing to be replaced in the rack.
remote - A field used to denote a call to this overloaded method.
Returns:
List The list containing the required letters.

replaceLetters

public void replaceLetters(java.util.List list)
Method takes a list of letters and replaces (into the bag) all letters from the list

Parameters:
list - The list of letters to replace into the bag.