Added README.txt and GPL Header to Source Files
[DHBWCampusApp.git] / app / src / main / java / de / dhbwloe / campusapp / vorlesungen / CourseGroup.java
1 /* CourseGroup.java
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 package de.dhbwloe.campusapp.vorlesungen;
17 import android.os.Bundle;
18 import android.provider.ContactsContract;
19
20 import java.lang.reflect.Array;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
25
26 import de.dhbwloe.campusapp.database.DatabaseManager;
27
28 /**
29  * Created by pk910 on 21.01.2016.
30  */
31 public class CourseGroup {
32     private static ArrayList<CourseGroup> CourseGroups = new ArrayList<CourseGroup>();
33     private int iCourseGroupId;
34     private String sCourseGroupName;
35     private String sCourseName;
36     private boolean bIsNew = false;
37     private ArrayList<CourseEvent> events = new ArrayList<CourseEvent>();
38
39     private Bundle extraData = new Bundle();
40
41     public static CourseGroup GetCourseGroupById(DatabaseManager dbm, int id) {
42         for(CourseGroup group : CourseGroups) {
43             if(group.iCourseGroupId == id)
44                 return group;
45         }
46         return dbm.getCourseGroup(id);
47     }
48
49     public static CourseGroup GetCourseGroupByName(DatabaseManager dbm, String coursename, String groupname) {
50         for(CourseGroup group : CourseGroups) {
51             if(group.sCourseName.equalsIgnoreCase(coursename) && group.sCourseGroupName.equalsIgnoreCase(groupname))
52                 return group;
53         }
54         CourseGroup group = dbm.getCourseGroup(coursename, groupname);
55         if(group == null) {
56             group = dbm.addCourseGroup(coursename, groupname);
57             group.bIsNew = true;
58         }
59         return group;
60     }
61
62     public static void ResetEventGroups() {
63         for(CourseGroup group : CourseGroups) {
64             group.events.clear();
65         }
66     }
67
68
69     public CourseGroup(int id, String coursename, String groupname) {
70         iCourseGroupId = id;
71         sCourseGroupName = groupname;
72         sCourseName = coursename;
73
74         CourseGroups.add(this);
75     }
76
77     public void addCourseEvent(CourseEvent event) {
78         this.events.add(event);
79     }
80
81     public CourseEvent[] getCourseEvents() {
82         return (CourseEvent[])this.events.toArray();
83     }
84
85     public CourseEvent[] getOrderedCourseEvents() {
86         CourseEvent[] events = getCourseEvents();
87
88         Arrays.sort(events);
89
90         return events;
91     }
92
93     public int getGroupId() {
94         return iCourseGroupId;
95     }
96
97     public boolean isNewGroup(boolean reset) {
98         boolean ret = bIsNew;
99         if(reset)
100             bIsNew = false;
101         return ret;
102     }
103
104     public Bundle getExtraData() {
105         return extraData;
106     }
107
108     public String getGroupName() {
109         return sCourseGroupName;
110     }
111
112 }