Sfoglia il codice sorgente

get all acts that are planned at a specific time.

Gilian Joosen 10 anni fa
parent
commit
b38931096a
2 ha cambiato i file con 40 aggiunte e 5 eliminazioni
  1. 19 0
      src/agenda/ActTime.java
  2. 21 5
      src/agenda/Agenda.java

+ 19 - 0
src/agenda/ActTime.java

@@ -126,4 +126,23 @@ public class ActTime implements Serializable, Comparable<ActTime>{
     public int compareTo(ActTime o) {
         return this.getBeginTime().compareTo(o.beginTime);
     }
+
+    public boolean contains(GregorianCalendar time) {
+        long timeL = time.getTimeInMillis();
+        long beginL = this.beginTime.getTimeInMillis();
+        long endL = this.endTime.getTimeInMillis();
+
+        System.out.println(timeL);
+        System.out.println(beginL);
+        System.out.println(endL);
+        System.out.println(timeL >= beginL);
+        System.out.println(timeL == endL);
+
+        if(timeL == beginL || endL == timeL){
+            return true;
+        }else if(timeL >= beginL && timeL <= endL){
+            return true;
+        }
+        return false;
+    }
 }

+ 21 - 5
src/agenda/Agenda.java

@@ -1,8 +1,11 @@
 package agenda;
 
+import sun.util.calendar.Gregorian;
+
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.GregorianCalendar;
 import java.util.List;
 
 /**
@@ -20,8 +23,6 @@ public class Agenda implements Serializable {
         this.acts = new ArrayList<Act>();
         
         this.testAgenda();
-
-        System.out.println("first acttime: " + this.firstActTime());
     }
 
     private void testAgenda(){
@@ -35,9 +36,9 @@ public class Agenda implements Serializable {
         this.artists.add(new Artist("Sabaton", "Power metal"));
 
         //acts
-        this.acts.add(new Act(this.artists.get(0).getName(), this.stages.get(0), "Heavy metal", new ActTime(2015,02,11,21,00  ,2015,02,11,23,00), 5, this.artists.get(0)));
-        this.acts.add(new Act(this.artists.get(1).getName(), this.stages.get(1), "Test metal" , new ActTime(2015,02,10,23,00  ,2015,02,12,04,30), 5, this.artists.get(1)));
-        this.acts.add(new Act(this.artists.get(2).getName(), this.stages.get(0), "Power metal" ,new ActTime(2015,02,11,20,00  ,2015,02,11,23,00), 4, this.artists.get(2)));
+        this.acts.add(new Act(this.artists.get(0).getName(), this.stages.get(0), "Heavy metal", new ActTime(2015,02,11,21,00  ,2015,02,11,23,12), 5, this.artists.get(0)));
+        this.acts.add(new Act(this.artists.get(1).getName(), this.stages.get(1), "Test metal", new ActTime(2016, 02, 10, 23, 00, 2016, 02, 12, 04, 30), 5, this.artists.get(1)));
+        this.acts.add(new Act(this.artists.get(2).getName(), this.stages.get(0), "Power metal", new ActTime(2015, 02, 11, 20, 00, 2015, 02, 11, 23, 00), 4, this.artists.get(2)));
         
         //System.out.println(this);
     }
@@ -68,6 +69,21 @@ public class Agenda implements Serializable {
         return actTimes.get(0);
     }
 
+    /**
+     *
+     * @param time GregorianCalendar, remember month -1!
+     * @return list of acts that are planned at the time.
+     */
+    public List<Act> getCurrentActs(GregorianCalendar time){
+        List<Act> currentActs = new ArrayList<>();
+        for(Act act: this.acts){
+            if(act.getActTime().contains(time)){
+                currentActs.add(act);
+            }
+        }
+        return currentActs;
+    }
+
 
     public void addAct(Act act){
         this.acts.add(act);