Coverage Summary for Class: MoveDestination (it.polimi.ingsw.Controller)

Class Class, % Method, % Branch, % Line, %
MoveDestination 100% (1/1) 100% (6/6) 50% (2/4) 91,7% (11/12)


1 package it.polimi.ingsw.Controller; 2  3 import it.polimi.ingsw.Controller.Actions.MoveStudent; 4 import it.polimi.ingsw.Misc.OptionalValue; 5  6 import java.io.Serial; 7 import java.io.Serializable; 8  9 /** 10  * This class is used by {@link MoveStudent} to direct a pawn from the entrance to the correct destination 11  */ 12 public class MoveDestination implements Serializable { 13  @Serial 14  private static final long serialVersionUID = 203L; // convention: 2 for controller, (01 -> 99) for objects 15  private final DestinationType destinationType; 16  private final OptionalValue<Integer> islandID; 17  18  /** 19  * Constructor used to point to an island 20  * 21  * @param islandID the id of the island to point to 22  */ 23  private MoveDestination(int islandID) { 24  this.destinationType = DestinationType.ISLAND; 25  this.islandID = OptionalValue.of(islandID); 26  } 27  28  /** 29  * Constructor used to point to the dining room 30  */ 31  private MoveDestination() { 32  this.destinationType = DestinationType.DININGROOM; 33  this.islandID = OptionalValue.empty(); 34  } 35  36  /** 37  * call this method if you wish to point to the dining room 38  * 39  * @return a new object pointing to the dining room 40  */ 41  public static MoveDestination toDiningRoom() { 42  return new MoveDestination(); 43  } 44  45  /** 46  * call this method if you wish to point to an island 47  * 48  * @param islandID the id of the island to point to 49  * @return a new object pointing to the desired island id 50  */ 51  public static MoveDestination toIsland(int islandID) { 52  return new MoveDestination(islandID); 53  } 54  55  /** 56  * @return the {@link DestinationType} selected during creation of the object 57  */ 58  public DestinationType getDestinationType() { 59  return destinationType; 60  } 61  62  /** 63  * @return the ID of the island this class is pointing to, or null if the {@link DestinationType} is {@link DestinationType#DININGROOM} 64  */ 65  public Integer getIslandID() { 66  if (this.destinationType == DestinationType.ISLAND && this.islandID.isPresent()) { 67  return this.islandID.get(); 68  } else { 69  return null; 70  } 71  } 72 }