Skip to content

Commit

Permalink
Ajout enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Trylz committed Mar 10, 2015
1 parent 803b5fa commit 00d41cb
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,29 @@
import ca.ulaval.glo4002.GRAISSE.Boardroom.BookingAssignable;

public class Booking implements BookingAssignable {
private final int DEFAULT_PRIORITY = 3;

public enum Priority {
VERY_LOW,
LOW,
MEDIUM,
HIGH,
VERY_HIGH
}

private static final Priority DEFAULT_PRIORITY = Priority.MEDIUM;
private static final int A_POSITIVE_NUMBER =1;

private int numberOfSeatsNeeded;
private boolean assigned;
private int priority;
private Priority priority;

public Booking(int numberOfSeatsNeeded) {
assigned = false;
this.numberOfSeatsNeeded = numberOfSeatsNeeded;
priority = DEFAULT_PRIORITY;
}

public void setPriority(int priority) throws InvalidPriorityException{
validatePriorityValue(priority);
public void setPriority(Priority priority) throws InvalidPriorityException{
this.priority = priority;
}

Expand All @@ -33,13 +43,39 @@ public boolean verifyNumberOfSeats(int numberOfSeats) {
return this.numberOfSeatsNeeded <= numberOfSeats;
}

private void validatePriorityValue(int priorityValueToValidate) throws InvalidPriorityException {
if (priorityValueToValidate < 1 || priorityValueToValidate > 5) {
throw new InvalidPriorityException();
}
}

public int comparePriorityToBooking(Booking bookingToCompare) {
return Integer.compare(this.priority, bookingToCompare.priority);

This comment has been minimized.

Copy link
@jpgiroux

jpgiroux Mar 10, 2015

Collaborator

N'y a t'il pas moyen de faire plus simple? On passe de 1 ligne à un switch case de 30 lignes.

This comment has been minimized.

Copy link
@Trylz

Trylz Mar 10, 2015

Contributor

j'avoue que ca me goss un peu. Pour linstan jai pas dautres idee

int comparisonValue=0;

if(priority == bookingToCompare.priority) return 0;

switch(bookingToCompare.priority)
{
case VERY_LOW :
if(priority == Priority.LOW) comparisonValue= A_POSITIVE_NUMBER;
else comparisonValue= -A_POSITIVE_NUMBER;
break;

case LOW :
if(priority == Priority.VERY_LOW) comparisonValue= -A_POSITIVE_NUMBER;
else comparisonValue= A_POSITIVE_NUMBER;
break;

case MEDIUM :
if((priority == Priority.VERY_LOW)|| (priority == Priority.LOW) ) comparisonValue= -A_POSITIVE_NUMBER;
else comparisonValue= A_POSITIVE_NUMBER;
break;

case HIGH :
if(priority == Priority.VERY_HIGH) comparisonValue= A_POSITIVE_NUMBER;
else comparisonValue= -A_POSITIVE_NUMBER;
break;

case VERY_HIGH :comparisonValue= -A_POSITIVE_NUMBER;;
break;
}

return comparisonValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ public class BookingTest {
private static final int BIGGER = 1;
private static final int SMALLER = -1;

private static final int PRIORITY_VALUE_OF_BOOKING = 2;
private static final int PRIORITY_VALUE_OF_BOOKING_BIGGER = 3;
private static final int PRIORITY_VALUE_OF_BOOKING_SMALLER = 1;
private static final Booking.Priority PRIORITY_VALUE_OF_BOOKING = Booking.Priority.LOW;
private static final Booking.Priority PRIORITY_VALUE_OF_BOOKING_BIGGER =Booking.Priority.HIGH;
private static final Booking.Priority PRIORITY_VALUE_OF_BOOKING_SMALLER = Booking.Priority.VERY_LOW;

private static final int INVALID_PRIORITY_VALUE_OF_BOOKING_BECAUSE_IT_IS_TO_LOW = 0;
private static final int INVALID_PRIORITY_VALUE_OF_BOOKING_BECAUSE_IT_IS_TO_HIGH = 6;

private static final int NUMBER_OF_SEATS_IN_BOOKING = 10;

Expand All @@ -46,17 +44,6 @@ public void setUp() throws InvalidPriorityException {
bookingWithSmallerPriority.setPriority(PRIORITY_VALUE_OF_BOOKING_SMALLER);
}

@Test(expected = InvalidPriorityException.class)
public void withInvalidBecauseItIsToHighPriorityValueConstructorShouldThrowInvalidPriorityValue() throws InvalidPriorityException {
booking = new Booking(NUMBER_OF_SEATS_IN_BOOKING);
booking.setPriority(INVALID_PRIORITY_VALUE_OF_BOOKING_BECAUSE_IT_IS_TO_HIGH);
}

@Test(expected = InvalidPriorityException.class)
public void withInvalidBecauseItIsToLowPriorityValueConstructorShouldThrowInvalidPriorityValue() throws InvalidPriorityException {
booking = new Booking(NUMBER_OF_SEATS_IN_BOOKING);
booking.setPriority(INVALID_PRIORITY_VALUE_OF_BOOKING_BECAUSE_IT_IS_TO_LOW);
}

@Test
public void withValidPriorityValueConstructorShouldNotThrowInvalidPriorityValue() throws InvalidPriorityException {
Expand Down

0 comments on commit 00d41cb

Please sign in to comment.