Merge branch 'development' of git@git.bfh.ch:/staff/due1/sed-hs15-srs-purple.git...
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / datahandler / DataHandlerForTests.java
CommitLineData
7903e50e
M
1/*
2 * Copyright (c) 2015 Berner Fachhochschule, Switzerland.
3 *
4 * Project Smart Reservation System.
5 *
6 * Distributable under GPL license. See terms of license at gnu.org.
7 */
8package ch.bfh.ti.srs.datahandler;
9
10import java.util.HashSet;
11import java.util.Set;
12
13import ch.bfh.ti.daterange.DateRange;
14import ch.bfh.ti.srs.dataschema.Reservation;
15import ch.bfh.ti.srs.dataschema.Resource;
16import ch.bfh.ti.srs.dataschema.User;
17
18public class DataHandlerForTests implements DataHandler{
19 Set<User> userList = new HashSet<User>();
20 Set<Resource> resourceList = new HashSet<Resource>();
21 Set<Reservation> reservationList = new HashSet<Reservation>();
22
23 public DataHandlerForTests(){
24
25 }
26
27 /* (non-Javadoc)
28 * @see ch.bfh.ti.srs.dataschema.DataHandler#findUser(java.lang.String)
29 */
30 @Override
31 public User findUser(String userName) {
32 for (User user : userList) {
33 if(user.getUserName().equals(userName)) return user;
34 }
35 return null;
36 }
37
38 /* (non-Javadoc)
39 * @see ch.bfh.ti.srs.dataschema.DataHandler#addUser(ch.bfh.ti.srs.dataschema.User)
40 */
41 @Override
42 public void addUser(User user) throws Exception {
43 if(user == null) throw new IllegalArgumentException("User object must not be null!");
44 if(userList.contains(user)) throw new IllegalArgumentException("User already exists!");
45 userList.add(user);
46 }
47
48 /* (non-Javadoc)
49 * @see ch.bfh.ti.srs.dataschema.DataHandler#findResource(java.lang.String)
50 */
51 @Override
52 public Resource findResource(String resourceName) {
53 for (Resource resource : resourceList) {
54 if(resource.getName().equals(resourceName)) return resource;
55 }
56 return null;
57 }
58 /* (non-Javadoc)
59 * @see ch.bfh.ti.srs.dataschema.DataHandler#addResource(ch.bfh.ti.srs.dataschema.Resource)
60 */
61 @Override
62 public void addResource(Resource resource) throws Exception {
63 if(resource == null) throw new IllegalArgumentException("Resource object must not be null!");
64 if(resourceList.contains(resource)) throw new IllegalArgumentException("Resource already exists!");
65 resourceList.add(resource);
66 }
67
68 /* (non-Javadoc)
69 * @see ch.bfh.ti.srs.dataschema.DataHandler#findReservation(java.lang.String)
70 */
71 @Override
72 public Reservation findReservation(Resource resource, DateRange daterange) {
73 for (Reservation reservation : reservationList) {
74 if(reservation.getResource().equals(resource) && reservation.getDateRange().equals(daterange)) return reservation;
75 }
76 return null;
77 }
78 /* (non-Javadoc)
79 * @see ch.bfh.ti.srs.dataschema.DataHandler#addReservation(ch.bfh.ti.srs.dataschema.Reservation)
80 */
81 @Override
82 public void addReservation(Reservation reservation) throws Exception {
83 if(reservation == null) throw new IllegalArgumentException("Reservation object must not be null!");
84 if(resourceList.contains(reservation)) throw new IllegalArgumentException("Reservation already exists!");
85 reservationList.add(reservation);
86 }
87}