-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
62760fd
commit 5f59b76
Showing
3 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
app/src/main/java/schmitt_florian/schoolplanner/logic/Period.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package schmitt_florian.schoolplanner.logic; | ||
|
||
|
||
import java.util.GregorianCalendar; | ||
|
||
/** | ||
* The Period Class represents an Object in the Period SQL table and is usually returned by methods from the DatabaseHelper Interface | ||
*/ | ||
public class Period { | ||
/** | ||
* numeric id of the period (unique) | ||
*/ | ||
private int id; | ||
|
||
/** | ||
* the {@link Subject} taught in this period | ||
*/ | ||
private Subject subject; | ||
|
||
/** | ||
* the time the period starts as GregorianCalendar | ||
*/ | ||
private GregorianCalendar startTime; | ||
/** | ||
* the time the period ends as GregorianCalendar | ||
*/ | ||
private GregorianCalendar endTime; | ||
|
||
//region c'tors | ||
|
||
/** | ||
* standard c'tor for Period class | ||
* | ||
* @param id numeric id of the period (unique) | ||
* @param subject the {@link Subject} taught in this period | ||
* @param startTime the time the period starts as GregorianCalendar | ||
* @param endTime the time the period ends as GregorianCalendar | ||
*/ | ||
public Period(int id, Subject subject, GregorianCalendar startTime, GregorianCalendar endTime) { | ||
this.id = id; | ||
this.subject = subject; | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
} | ||
|
||
/** | ||
* constructs a Period from Id as int and times as Strings, | ||
* note, that if this c'tor is used the Year, month, dayOfMonth fields in the GregorianCalendars will be initialized with 0 value | ||
* | ||
* @param id numeric id of the period (unique) | ||
* @param subject the {@link Subject} taught in this period | ||
* @param startTime the time the period starts as String separated by '-' to look like HH-MM-SS | ||
* @param endTime the time the period ends as String separated by '-' to look like HH-MM-SS | ||
*/ | ||
public Period(int id, Subject subject, String startTime, String endTime) { | ||
this.id = id; | ||
this.startTime = getTimeFromString(startTime); | ||
this.endTime = getTimeFromString(endTime); | ||
} | ||
//endregion | ||
|
||
//region private methods | ||
|
||
/** | ||
* method to transfer time data as Sting to a GregorianCalendar | ||
* | ||
* @param source string with time information separated by '-' HH-MM-SS | ||
* @return GregorianCalendar with time information's. Year, month, dayOfMonth = 0 | ||
*/ | ||
private GregorianCalendar getTimeFromString(String source) { | ||
return new GregorianCalendar(0, | ||
0, | ||
0, | ||
Integer.parseInt(source.split("-")[0]), | ||
Integer.parseInt(source.split("-")[1]), | ||
Integer.parseInt(source.split("-")[2]) | ||
); | ||
} | ||
|
||
//endregion | ||
} |