-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTripBooking.java
69 lines (58 loc) · 2.03 KB
/
TripBooking.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package it.uniud.poo.trasporti_2024;
import lombok.NonNull;
import lombok.Getter;
import java.time.LocalDateTime;
import java.util.UUID;
/**
* MISSION: represent a trip booking which consists of a trip that is
* booked for a specific client.
* The trip may be valid or not, depending on whether it has at least one
* valid path.
* Thus a valid TripBooking is a tuple <Trip, Client, Path>.
*/
public class TripBooking {
/**
* INVARIANT: the trip is not null, the client is not null.
* The path may be null if no path has been set yet.
*/
private @Getter final Trip trip; // The trip that is booked
private @Getter @NonNull String bookingID; // The booking id
private @Getter Path path;
private @Getter Client client;
private @Getter Truck truck;
public TripBooking(@NonNull Trip trip, @NonNull Truck truck, @NonNull Client client) {
this.trip = trip;
bookingID = UUID.randomUUID().toString();
this.truck = truck;
this.client = client;
}
public boolean isValid() {
return path != null;
}
/**
* set the path of the trip booking.
* @throws IllegalArgumentException if the path is null or if the path
* does not start from the origin of the trip and does not end in the
* destination of the trip.
* @param path the path to set
*/
public void setPath(@NonNull Path path) {
if (!path.getStartLocation().equals(trip.getOrigin()) ||
!path.getEndLocation().equals(trip.getDestination())) {
throw new IllegalArgumentException("The path must start from the origin and end in the destination of the trip");
}
this.path = path;
}
public LocalDateTime getDepartureDate() {
return trip.getDepartureDate();
}
public String getStartPlace() {
return trip.getOrigin();
}
public String getEndPlace() {
return trip.getDestination();
}
public String toString() {
return "TripBooking(" + bookingID + ", " + trip + ", " + path + ")";
}
}