checkstyle adapted in Datahandler interface
[staff/due1/sed-hs15-srs-purple.git] / src / main / java / ch / bfh / ti / srs / datahandler / DataHandlerForTests.java
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 */
8 package ch.bfh.ti.srs.datahandler;
9
10 import java.util.ArrayList;
11 import java.util.HashSet;
12 import java.util.List;
13 import java.util.Set;
14 import java.util.UUID;
15
16 import ch.bfh.ti.daterange.DateRange;
17 import ch.bfh.ti.srs.dataschema.Reservation;
18 import ch.bfh.ti.srs.dataschema.Resource;
19 import ch.bfh.ti.srs.dataschema.User;
20
21 public class DataHandlerForTests implements DataHandler{
22 Set<User> userList = new HashSet<User>();
23 Set<Resource> resourceList = new HashSet<Resource>();
24 Set<Reservation> reservationList = new HashSet<Reservation>();
25
26 public DataHandlerForTests(){
27
28 }
29
30 /* (non-Javadoc)
31 * @see ch.bfh.ti.srs.dataschema.DataHandler#findUser(java.lang.String)
32 */
33 @Override
34 public User findUser(String userName) {
35 for (User user : userList) {
36 if(user.getUserName().equals(userName)) return user;
37 }
38 return null;
39 }
40
41 /* (non-Javadoc)
42 * @see ch.bfh.ti.srs.dataschema.DataHandler#addUser(ch.bfh.ti.srs.dataschema.User)
43 */
44 @Override
45 public void addUser(User user) throws Exception {
46 if(user == null) throw new IllegalArgumentException("User object must not be null!");
47 if(userList.contains(user)) throw new IllegalArgumentException("User already exists!");
48 userList.add(user);
49 }
50
51 /* (non-Javadoc)
52 * @see ch.bfh.ti.srs.dataschema.DataHandler#findResource(java.lang.String)
53 */
54 @Override
55 public Resource findResource(String resourceName) {
56 for (Resource resource : resourceList) {
57 if(resource.getName().equals(resourceName)) return resource;
58 }
59 return null;
60 }
61 /* (non-Javadoc)
62 * @see ch.bfh.ti.srs.dataschema.DataHandler#addResource(ch.bfh.ti.srs.dataschema.Resource)
63 */
64 @Override
65 public void addResource(Resource resource) throws Exception {
66 if(resource == null) throw new IllegalArgumentException("Resource object must not be null!");
67 if(resourceList.contains(resource)) throw new IllegalArgumentException("Resource already exists!");
68 resourceList.add(resource);
69 }
70
71 /* (non-Javadoc)
72 * @see ch.bfh.ti.srs.dataschema.DataHandler#findReservation(java.lang.String)
73 */
74 @Override
75 public Reservation findReservation(UUID id) {
76 for (Reservation reservation : reservationList) {
77 if(reservation.getId().equals(id)) return reservation;
78 }
79 return null;
80 }
81
82 @Override
83 public List<Reservation> findGroupReservations(UUID groupID) {
84 List<Reservation> groupReservations = new ArrayList<Reservation>();
85 for (Reservation reservation : reservationList) {
86 if(reservation.getGroupId().equals(groupID))
87 groupReservations.add(reservation);
88 }
89 return groupReservations;
90 }
91
92 @Override
93 public List<Reservation> overlaps(DateRange range) {
94 // TODO Auto-generated method stub
95 return null;
96 }
97
98 /* (non-Javadoc)
99 * @see ch.bfh.ti.srs.dataschema.DataHandler#addReservation(ch.bfh.ti.srs.dataschema.Reservation)
100 */
101 @Override
102 public void addReservation(Reservation reservation) throws Exception {
103 if(reservation == null) throw new IllegalArgumentException("Reservation object must not be null!");
104 if(resourceList.contains(reservation)) throw new IllegalArgumentException("Reservation already exists!");
105 reservationList.add(reservation);
106 }
107
108 }