JenkinsSonaImron
3 years ago
13 changed files with 255 additions and 53 deletions
-
8src/main/java/hs/fulda/de/ci/exam/project/Admin.java
-
4src/main/java/hs/fulda/de/ci/exam/project/Airport.java
-
4src/main/java/hs/fulda/de/ci/exam/project/Customer.java
-
4src/main/java/hs/fulda/de/ci/exam/project/Flight.java
-
20src/main/java/hs/fulda/de/ci/exam/project/FlightRepository.java
-
3src/main/java/hs/fulda/de/ci/exam/project/FlightReservation.java
-
36src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java
-
48src/main/java/hs/fulda/de/ci/exam/project/Itinerary.java
-
36src/main/java/hs/fulda/de/ci/exam/project/Passenger.java
-
23src/main/java/hs/fulda/de/ci/exam/project/Person.java
-
7src/test/java/hs/fulda/de/ci/exam/project/AdminTest.java
-
77src/test/java/hs/fulda/de/ci/exam/project/ItineraryTest.java
-
38src/test/java/hs/fulda/de/ci/exam/project/PersonTest.java
@ -1,8 +1,36 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.Collection; |
|||
import java.util.Map; |
|||
import java.util.concurrent.ConcurrentHashMap; |
|||
|
|||
public class FlightReservationRepository { |
|||
Map<String, FlightReservation> flightReservationList = new ConcurrentHashMap<String, FlightReservation>(); |
|||
|
|||
public boolean checkIfFlightAlreadyExist(FlightReservation flightReservation){ |
|||
if(flightReservationList.containsKey(generateKey(flightReservation))){ |
|||
return true; |
|||
} |
|||
return false; |
|||
} |
|||
FlightReservation findById(String id){ |
|||
FlightReservation flightReservation = flightReservationList.get(id); |
|||
return flightReservation; |
|||
} |
|||
|
|||
private String generateKey(FlightReservation flightReservation) { |
|||
return String.format("%s", flightReservation.getReservationNumber()); |
|||
} |
|||
public Collection<FlightReservation> findAll() { |
|||
return flightReservationList.values(); |
|||
} |
|||
public boolean save(FlightReservation flightReservation){ |
|||
flightReservationList.put(generateKey(flightReservation), flightReservation); |
|||
return true; |
|||
} |
|||
|
|||
public void delete(FlightReservation flightReservation) { |
|||
flightReservationList.remove(generateKey(flightReservation)); |
|||
} |
|||
|
|||
public interface FlightReservationRepository { |
|||
ArrayList<FlightReservation> findAll(); |
|||
void save(FlightReservation flightReservation); |
|||
} |
@ -1,4 +1,40 @@ |
|||
package hs.fulda.de.ci.exam.project; |
|||
|
|||
import java.util.Date; |
|||
import java.util.regex.Matcher; |
|||
import java.util.regex.Pattern; |
|||
|
|||
public class Passenger { |
|||
private String name; |
|||
private String passportNumber; |
|||
private Date dateOfBirth; |
|||
|
|||
public Passenger(String name, String passportNumber, Date dateOfBirth) { |
|||
this.name = name; |
|||
this.passportNumber = passportNumber; |
|||
this.dateOfBirth = dateOfBirth; |
|||
} |
|||
|
|||
public void validateName() { |
|||
if(name.isBlank()) { |
|||
throw new RuntimeException(("Name cannot be null or empty")); |
|||
} |
|||
} |
|||
|
|||
public void validatePassportNumber() { |
|||
Pattern pattern = Pattern.compile("^(?!^0+$)[a-zA-Z0-9]{3,20}$"); |
|||
Matcher matcher = pattern.matcher(this.passportNumber); |
|||
if(passportNumber.isBlank()){ |
|||
throw new RuntimeException("Passport number cannot be blank"); |
|||
} |
|||
if(!matcher.matches()){ |
|||
throw new RuntimeException("Passport number cannot be null or empty"); |
|||
} |
|||
} |
|||
|
|||
public void validateDate() { |
|||
if(dateOfBirth.equals(null)) { |
|||
throw new RuntimeException("Birthdate cannot be null"); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue