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
ConstructorsConstructorDescriptionConstructs aStudentContainerwith maximum size equal to the total number of student discs in the game (130).StudentContainer(int maxSize) Constructs an emptyStudentContainerwith the specified maximum size. -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanempty()A method to state if the object has no students.protected voidfill()Fills the container withMAX_STUDENTS_PER_COLOR(26) students of each color.intgetQuantity(Color color) A getter for the amount of students of colorcolorcurrently in the container.A helper-getter method to fulfill theBoardStatuscreation process.voidmoveAllTo(StudentContainer dest) Moves all the students fromthisto the destination containerdest.voidmoveTo(StudentContainer dest, int amount) Movesamountstudents of random colors fromthisto the destination containerdest.voidmoveTo(StudentContainer dest, Color color) Moves a student of colorcolorfromthisto the destination containerdest.voidrefillFrom(StudentContainer source) Refillsthisto its maximum capacity by picking random students fromsource.protected intremainingCapacity(Color color) Returns the container's remaining capacity for the specifiedColor, an integer between 0 andMAX_STUDENTS_PER_COLOR, or -1 ifcolorisnull.voidswap(StudentContainer that, Color thisColor, Color thatColor) Swaps two student discs betweenthisandthat: one student of colorthisColoris removed fromthisand added tothat, and one student of colorthatColoris removed fromthatand added tothis.
-
Constructor Details
-
StudentContainer
public StudentContainer()Constructs aStudentContainerwith maximum size equal to the total number of student discs in the game (130). This constructor is to be used only to construct aStudentContainerwith no specified maximum size. -
StudentContainer
public StudentContainer(int maxSize) Constructs an emptyStudentContainerwith 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 colorcolorcurrently in the container.- Parameters:
color- the color of students whose amount is requested.- Returns:
- the amount of students of color
colorcurrently in the container, or -1 ifcolorisnull
-
moveTo
public void moveTo(StudentContainer dest, Color color) throws InvalidArgumentException, NoMovementException Moves a student of colorcolorfromthisto the destination containerdest. No movement occurs ifthisis empty or the destination container has no remaining capacity.- Parameters:
dest- the destinationStudentContainercolor- theColorof the student to be moved- Throws:
InvalidArgumentException- if any argument isnullNoMovementException- ifthisis empty or the destination container is full
-
moveTo
public void moveTo(StudentContainer dest, int amount) throws InvalidArgumentException, NoMovementException Movesamountstudents of random colors fromthisto the destination containerdest. Students are moved one by one untilamountis reached or no colors that can be both removed fromthisand added todestcan be found, at which point no subsequent movements occur.- Parameters:
dest- the destinationStudentContaineramount- the amount of students to be moved- Throws:
InvalidArgumentException- ifdestisnullNoMovementException- if no colors that can be both removed fromthisand added todestcan be found
-
moveAllTo
Moves all the students fromthisto the destination containerdest. Students are moved color by color until the source containerthisis empty or the destination container has no remaining capacity, at which point no subsequent movements occur. Generally, the source containerthisshould be emptied as a result of this method.- Parameters:
dest- the destinationStudentContainer- Throws:
InvalidArgumentException- ifdestisnullNoMovementException- ifthiscontains more students than the destination container can add
-
refillFrom
public void refillFrom(StudentContainer source) throws InvalidArgumentException, NoMovementException Refillsthisto its maximum capacity by picking random students fromsource. Students are moved one by one untilthisis full orsourceis empty, at which point no subsequent movements occur.- Parameters:
source- the sourceStudentContainer- Throws:
InvalidArgumentException- ifsourceisnullNoMovementException- ifsourceis emptied beforethiscan be filled- See Also:
-
swap
public void swap(StudentContainer that, Color thisColor, Color thatColor) throws InvalidArgumentException, NoMovementException Swaps two student discs betweenthisandthat: one student of colorthisColoris removed fromthisand added tothat, and one student of colorthatColoris removed fromthatand added tothis. If any container does not have enough students or enough capacity to perform the swap, the operation is aborted.- Parameters:
that- the secondStudentContainerthisColor- theColorof the student being moved fromthistothatthatColor- theColorof the student being moved fromthattothis- Throws:
InvalidArgumentException- if any argument isnullNoMovementException- if any container does not have enough students or enough capacity to perform the swap
-
getRepresentation
A helper-getter method to fulfill theBoardStatuscreation process.- Returns:
- a representation for the object, ordered by
Colorenum declarations
-
remainingCapacity
Returns the container's remaining capacity for the specifiedColor, an integer between 0 andMAX_STUDENTS_PER_COLOR, or -1 ifcolorisnull.- 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 ifcolorisnull. - 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 aBagobject. -
empty
protected boolean empty()A method to state if the object has no students.- Returns:
- true if and only if the container is empty
-