Coverage Summary for Class: Cloud (it.polimi.ingsw.Model)
| Class | Class, % | Method, % | Branch, % | Line, % |
|---|---|---|---|---|
| Cloud | 100% (1/1) | 100% (5/5) | 100% (4/4) | 100% (13/13) |
1 package it.polimi.ingsw.Model; 2 3 import it.polimi.ingsw.Exceptions.Container.EmptyContainerException; 4 import it.polimi.ingsw.Exceptions.Container.FullContainerException; 5 import it.polimi.ingsw.Model.Enums.PawnColour; 6 7 import java.io.Serial; 8 import java.io.Serializable; 9 import java.util.ArrayList; 10 import java.util.Collection; 11 import java.util.List; 12 13 /** 14 * The Cloud class is used to replenish pawns in the entrance fields of the {@link PlayerBoard#getEntranceStudents()} 15 */ 16 public class Cloud implements Serializable { 17 @Serial 18 private static final long serialVersionUID = 118L; // convention: 1 for model, (01 -> 99) for objects 19 20 private final int id; 21 private ArrayList<PawnColour> contents; 22 23 /** 24 * Construct a Cloud, assigning an ID to it. 25 * 26 * @param id if the cloud is in an array, the id will be the index of the array at which the cloud is located 27 */ 28 public Cloud(int id) { 29 this.id = id; 30 contents = new ArrayList<>(3); 31 } 32 33 /** 34 * The ID of the cloud is the index of the array in which the Cloud is stored 35 * 36 * @return the ID of the cloud 37 */ 38 public int getId() { 39 return id; 40 } 41 42 /** 43 * A Cloud will need to be emptied out, eventually. This method returns a {@link List} of {@link PawnColour} and empties the Cloud. 44 * 45 * @return a {@link List} of {@link PawnColour}s that were contained in the Cloud 46 * @throws EmptyContainerException if the Cloud being emptied was already empty, this exception is thrown. 47 */ 48 public List<PawnColour> extractContents() throws EmptyContainerException { 49 if (contents.size() > 0) { 50 ArrayList<PawnColour> toReturn = new ArrayList<>(this.contents); 51 this.contents = new ArrayList<>(3); 52 return toReturn; 53 } else { 54 throw new EmptyContainerException("Cloud"); 55 } 56 } 57 58 /** 59 * Cloud contents may be inspected without emptying the tile. 60 * 61 * @return an {@link java.util.List#copyOf(Collection)} of the contents of the Cloud 62 */ 63 public List<PawnColour> getContents() { 64 return List.copyOf(contents); 65 } 66 67 /** 68 * A cloud may need to be filled from time to time. this method is used for that 69 * 70 * @param colours a {@link List} of {@link PawnColour}s to put in the Cloud tile 71 * @throws FullContainerException if the Cloud being filled already had some contents, this exception will be thrown 72 */ 73 public void fill(List<PawnColour> colours) throws FullContainerException { 74 if (contents.isEmpty()) { 75 contents.addAll(colours); 76 } else { 77 throw new FullContainerException("Cloud"); 78 } 79 } 80 } 81