DataHandler updated
authorMatthias <balmm1@bfh.ch>
Tue, 24 Nov 2015 12:53:20 +0000 (13:53 +0100)
committerMatthias <balmm1@bfh.ch>
Tue, 24 Nov 2015 12:53:20 +0000 (13:53 +0100)
src/main/java/ch/bfh/ti/srs/datahandler/DataHandler.java
src/main/java/ch/bfh/ti/srs/datahandler/DataHandlerForTests.java
src/main/java/ch/bfh/ti/srs/noTest/DataHandlerForExcel.java

index fbbe482..5172caa 100644 (file)
@@ -7,8 +7,8 @@
  */
 package ch.bfh.ti.srs.datahandler;
 
  */
 package ch.bfh.ti.srs.datahandler;
 
-import java.util.HashSet;
 import java.util.List;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import ch.bfh.ti.daterange.DateRange;
 import java.util.UUID;
 
 import ch.bfh.ti.daterange.DateRange;
@@ -36,7 +36,8 @@ public interface DataHandler {
         * @param user
         *            User object
         * @return returns a boolean whether the user was made or not
         * @param user
         *            User object
         * @return returns a boolean whether the user was made or not
-        * @throws Exception
+        * @throws Exception if some property of the specified element
+     *         prevents it from being added the Datacontext
         */
        public boolean addUser(User user) throws Exception;
 
         */
        public boolean addUser(User user) throws Exception;
 
@@ -55,7 +56,8 @@ public interface DataHandler {
         * @param resource
         *            Resource object
         * @return returns a boolean whether the resource was made or not
         * @param resource
         *            Resource object
         * @return returns a boolean whether the resource was made or not
-        * @throws Exception
+        * @throws Exception if some property of the specified element
+     *         prevents it from being added the Datacontext
         */
        public boolean addResource(Resource resource) throws Exception;
 
         */
        public boolean addResource(Resource resource) throws Exception;
 
@@ -107,8 +109,9 @@ public interface DataHandler {
         * @param reservation
         *            Reservation object
         *            
         * @param reservation
         *            Reservation object
         *            
-        * @return returns a boolean whether the reservation was made or not
-        * @throws Exception
+        * @return a boolean whether the reservation was made or not
+        * @throws Exception if some property of the specified element
+     *         prevents it from being added the Datacontext
         */
        public boolean addReservation(Reservation reservation) throws Exception;
        
         */
        public boolean addReservation(Reservation reservation) throws Exception;
        
@@ -123,6 +126,7 @@ public interface DataHandler {
         * @param discardChanges
         *                      <code>true</code> do not try to save the changes
         *                      <code>false</code> try to save the changes
         * @param discardChanges
         *                      <code>true</code> do not try to save the changes
         *                      <code>false</code> try to save the changes
+        * @throws Exception no implementation for <code>true</code> in this DataHandler possible
         */
        public void refresh(boolean discardChanges) throws Exception;
 
         */
        public void refresh(boolean discardChanges) throws Exception;
 
@@ -131,5 +135,5 @@ public interface DataHandler {
 
        public boolean deleteReservation(Reservation reservation);
 
 
        public boolean deleteReservation(Reservation reservation);
 
-       public List<Resource> getAllResources();
+       public Set<Resource> getAllResources();
 }
 }
index 55ce1bb..771f67e 100644 (file)
@@ -80,6 +80,11 @@ public class DataHandlerForTests implements DataHandler {
                        return false;
                }
                else{
                        return false;
                }
                else{
+                       for (Reservation res : reservationList) {
+                               if (res.getId() == resource.getId()){
+                                       return false;
+                               }
+                       }
                        resourceList.add(resource);
                        return true;
                }
                        resourceList.add(resource);
                        return true;
                }
@@ -166,6 +171,11 @@ public class DataHandlerForTests implements DataHandler {
                        return false;
                }
                else{
                        return false;
                }
                else{
+                       for (Reservation res : reservationList) {
+                               if (res.getId() == reservation.getId()){
+                                       return false;
+                               }
+                       }
                        reservationList.add(reservation);
                        return true;
                }
                        reservationList.add(reservation);
                        return true;
                }
@@ -189,20 +199,37 @@ public class DataHandlerForTests implements DataHandler {
 
        @Override
        public boolean editReservation(Reservation reservation) {
 
        @Override
        public boolean editReservation(Reservation reservation) {
-               // TODO Auto-generated method stub
+               if (reservation == null){
+                       throw new IllegalArgumentException("Reservation object must not be null!");
+               }
+               for (Reservation res : reservationList) {
+                       if (res.getId() == (reservation.getId())){
+                               reservationList.remove(res);
+                               reservationList.add(reservation);
+                               return true;
+                       }
+               }
                return false;
        }
 
        @Override
        public boolean deleteReservation(Reservation reservation) {
                return false;
        }
 
        @Override
        public boolean deleteReservation(Reservation reservation) {
-               // TODO Auto-generated method stub
-               return false;
+               if (reservation == null){
+                       throw new IllegalArgumentException("Reservation object must not be null!");
+               }
+               else if(resourceList.contains(reservation)) {
+                       resourceList.remove(reservation);
+                       return true;
+               }
+               else{
+                       return false;
+               }
        }
 
        @Override
        }
 
        @Override
-       public List<Resource> getAllResources() {
-               // TODO Auto-generated method stub
-               return null;
+       public Set<Resource> getAllResources() {
+
+               return resourceList;
        }
 
 }
        }
 
 }
index 5f20e7b..91c8082 100644 (file)
@@ -196,7 +196,7 @@ public class DataHandlerForExcel implements DataHandler {
        }
 
        @Override
        }
 
        @Override
-       public List<Resource> getAllResources() {
+       public Set<Resource> getAllResources() {
                // TODO Auto-generated method stub
                return null;
        }
                // TODO Auto-generated method stub
                return null;
        }