Package it.polimi.ingsw.eriantys.model
Class StudentContainer
java.lang.Object
it.polimi.ingsw.eriantys.model.StudentContainer
- Direct Known Subclasses:
Bag
,ContainerCharacterCard
,DiningRoom
,IslandGroup
This class provides a container for student discs.
It is meant to model every game object on which student discs can be placed.
It can be used as is, or it can be extended in order to include additional methods and attributes.
It exposes various methods to move students between two
StudentContainer
objects
and a method returning the number of students of a given Color
in the container.-
Constructor Summary
ConstructorDescriptionConstructs aStudentContainer
with maximum size equal to the total number of student discs in the game (130).StudentContainer
(int maxSize) Constructs an emptyStudentContainer
with the specified maximum size. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
empty()
A method to state if the object has no students.protected void
fill()
Fills the container withMAX_STUDENTS_PER_COLOR
(26) students of each color.int
getQuantity
(Color color) A getter for the amount of students of colorcolor
currently in the container.A helper-getter method to fulfill theBoardStatus
creation process.void
moveAllTo
(StudentContainer dest) Moves all the students fromthis
to the destination containerdest
.void
moveTo
(StudentContainer dest, int amount) Movesamount
students of random colors fromthis
to the destination containerdest
.void
moveTo
(StudentContainer dest, Color color) Moves a student of colorcolor
fromthis
to the destination containerdest
.void
refillFrom
(StudentContainer source) Refillsthis
to its maximum capacity by picking random students fromsource
.protected int
remainingCapacity
(Color color) Returns the container's remaining capacity for the specifiedColor
, an integer between 0 andMAX_STUDENTS_PER_COLOR
, or -1 ifcolor
isnull
.void
swap
(StudentContainer that, Color thisColor, Color thatColor) Swaps two student discs betweenthis
andthat
: one student of colorthisColor
is removed fromthis
and added tothat
, and one student of colorthatColor
is removed fromthat
and added tothis
.
-
Constructor Details
-
StudentContainer
public StudentContainer()Constructs aStudentContainer
with maximum size equal to the total number of student discs in the game (130). This constructor is to be used only to construct aStudentContainer
with no specified maximum size. -
StudentContainer
public StudentContainer(int maxSize) Constructs an emptyStudentContainer
with the specified maximum size. The size has an upper bound of 130.- Parameters:
maxSize
- the maximum number of students allowed in the container at any moment.
-
-
Method Details
-
getQuantity
A getter for the amount of students of colorcolor
currently in the container.- Parameters:
color
- the color of students whose amount is requested.- Returns:
- the amount of students of color
color
currently in the container, or -1 ifcolor
isnull
-
moveTo
public void moveTo(StudentContainer dest, Color color) throws InvalidArgumentException, NoMovementException Moves a student of colorcolor
fromthis
to the destination containerdest
. No movement occurs ifthis
is empty or the destination container has no remaining capacity.- Parameters:
dest
- the destinationStudentContainer
color
- theColor
of the student to be moved- Throws:
InvalidArgumentException
- if any argument isnull
NoMovementException
- ifthis
is empty or the destination container is full
-
moveTo
public void moveTo(StudentContainer dest, int amount) throws InvalidArgumentException, NoMovementException Movesamount
students of random colors fromthis
to the destination containerdest
. Students are moved one by one untilamount
is reached or no colors that can be both removed fromthis
and added todest
can be found, at which point no subsequent movements occur.- Parameters:
dest
- the destinationStudentContainer
amount
- the amount of students to be moved- Throws:
InvalidArgumentException
- ifdest
isnull
NoMovementException
- if no colors that can be both removed fromthis
and added todest
can be found
-
moveAllTo
Moves all the students fromthis
to the destination containerdest
. Students are moved color by color until the source containerthis
is empty or the destination container has no remaining capacity, at which point no subsequent movements occur. Generally, the source containerthis
should be emptied as a result of this method.- Parameters:
dest
- the destinationStudentContainer
- Throws:
InvalidArgumentException
- ifdest
isnull
NoMovementException
- ifthis
contains more students than the destination container can add
-
refillFrom
public void refillFrom(StudentContainer source) throws InvalidArgumentException, NoMovementException Refillsthis
to its maximum capacity by picking random students fromsource
. Students are moved one by one untilthis
is full orsource
is empty, at which point no subsequent movements occur.- Parameters:
source
- the sourceStudentContainer
- Throws:
InvalidArgumentException
- ifsource
isnull
NoMovementException
- ifsource
is emptied beforethis
can be filled- See Also:
-
swap
public void swap(StudentContainer that, Color thisColor, Color thatColor) throws InvalidArgumentException, NoMovementException Swaps two student discs betweenthis
andthat
: one student of colorthisColor
is removed fromthis
and added tothat
, and one student of colorthatColor
is removed fromthat
and added tothis
. If any container does not have enough students or enough capacity to perform the swap, the operation is aborted.- Parameters:
that
- the secondStudentContainer
thisColor
- theColor
of the student being moved fromthis
tothat
thatColor
- theColor
of the student being moved fromthat
tothis
- Throws:
InvalidArgumentException
- if any argument isnull
NoMovementException
- if any container does not have enough students or enough capacity to perform the swap
-
getRepresentation
A helper-getter method to fulfill theBoardStatus
creation process.- Returns:
- a representation for the object, ordered by
Color
enum declarations
-
remainingCapacity
Returns the container's remaining capacity for the specifiedColor
, an integer between 0 andMAX_STUDENTS_PER_COLOR
, or -1 ifcolor
isnull
.- Parameters:
color
- the color whose remaining capacity is returned.- Returns:
- the container's remaining capacity for the specified
Color
, an integer between 0 andMAX_STUDENTS_PER_COLOR
, or -1 ifcolor
isnull
. - See Also:
-
remainingCapacity()
-
fill
protected void fill()Fills the container withMAX_STUDENTS_PER_COLOR
(26) students of each color. This method is only to be called while constructing aBag
object. -
empty
protected boolean empty()A method to state if the object has no students.- Returns:
- true if and only if the container is empty
-