Преглед на файлове

added FirstActTime method.

Gilian Joosen преди 10 години
родител
ревизия
db9b98dab5
променени са 2 файла, в които са добавени 28 реда и са изтрити 5 реда
  1. 6 1
      src/agenda/ActTime.java
  2. 22 4
      src/agenda/Agenda.java

+ 6 - 1
src/agenda/ActTime.java

@@ -7,7 +7,7 @@ import java.util.GregorianCalendar;
 /**
  * Created by gjoosen on 06/02/15.
  */
-public class ActTime implements Serializable {
+public class ActTime implements Serializable, Comparable<ActTime>{
     
 	private GregorianCalendar beginTime, endTime;
 
@@ -121,4 +121,9 @@ public class ActTime implements Serializable {
     public String toString(){
         return "Start time: " + this.getBeginTimeString() + "<br/>End time: " + this.getEndTimeString() + "<br/>Length: " + getLength() + " Minutes";
     }
+
+    @Override
+    public int compareTo(ActTime o) {
+        return this.getBeginTime().compareTo(o.beginTime);
+    }
 }

+ 22 - 4
src/agenda/Agenda.java

@@ -2,6 +2,7 @@ package agenda;
 
 import java.io.Serializable;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -19,6 +20,8 @@ public class Agenda implements Serializable {
         this.acts = new ArrayList<Act>();
         
         this.testAgenda();
+
+        System.out.println("first acttime: " + this.firstActTime());
     }
 
     private void testAgenda(){
@@ -32,9 +35,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,11,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,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)));
         
         //System.out.println(this);
     }
@@ -50,7 +53,22 @@ public class Agenda implements Serializable {
     public void addArtist(Artist artist){
         this.artists.add(artist);
     }
-    
+
+    /**
+     *  returns the first ActTime of all the acts.
+     * @return first ActTime of all acts
+     */
+    public ActTime firstActTime(){
+        List<Act> acts = this.getActs();
+        List<ActTime> actTimes = new ArrayList<ActTime>();
+        for(Act act: acts){
+            actTimes.add(act.getActTime());
+        }
+        Collections.sort(actTimes);
+        return actTimes.get(0);
+    }
+
+
     public void addAct(Act act){
         this.acts.add(act);
         System.err.println(this.acts);