java.lang.Object
page.codeberg.friedolyn.grades.Semester
Represents a university semester.
- Implementation Note:
- This class is not a record, because the constructor needs to validate the
year
and, if invalid, throw anIllegalArgumentException
. While the validation could be done in a record as well, we cannot addthrows IllegalArgumentException
to the record's constructor signature, risking that callers of the constructor will not handle the exception. JavaDoc is not a sufficient replacement here!
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
When the semester starts and ends. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull Semester.SemesterType
Whether the semester takes place in winter or summer.private final @NonNull Year
The year in which the semester takes place. -
Constructor Summary
ConstructorsConstructorDescriptionSemester
(@NonNull Semester.SemesterType semesterType, @NonNull Year year) Constructs a newSemester
object. -
Method Summary
Modifier and TypeMethodDescription@NonNull Semester
copy()
boolean
Checks whether thisSemester
's fields are equal to the given object's fields.@NonNull Semester.SemesterType
@NonNull Year
getYear()
static @NonNull Semester
Converts the given string representation of a semester into aSemester
object.@NonNull String
toString()
-
Field Details
-
semesterType
Whether the semester takes place in winter or summer. -
year
The year in which the semester takes place. In case of a winter semester, this is the year in which the semester begins. (It will end in the following year.)
-
-
Constructor Details
-
Semester
public Semester(@NonNull @NonNull Semester.SemesterType semesterType, @NonNull @NonNull Year year) throws IllegalArgumentException Constructs a newSemester
object.- Parameters:
semesterType
- ThesemesterType
, indicating whether the semester takes place in winter or summer.year
- Theyear
in which the semester takes place. In case of a winter semester, this is the year in which the semester begins. (It will end in the following year.) Must be between 1990 and one year from now.- Throws:
IllegalArgumentException
- If the given year is before 1990 or after one year from now.
-
-
Method Details
-
getSemesterType
- Returns:
- The
semesterType
, indicating whether the semester takes place in winter or summer.
-
getYear
- Returns:
- The
year
in which the semester takes place. In case of awinter semester
, this is the year in which the semester begins. (It will end in the following year.)
-
copy
-
equals
Checks whether thisSemester
's fields are equal to the given object's fields. -
toString
-
parse
@NonNull public static @NonNull Semester parse(@NonNull @NonNull String semester) throws IllegalArgumentException Converts the given string representation of a semester into aSemester
object.- Parameters:
semester
- The string representation of the semester. Must be in the formatSommersemester YY
orWintersemester YY/YY
, whereYY
is a two-digit year. In case of a Winter semester, the firstYY
is the year the semester starts in (used as this Semester'syear
), while the secondYY
isyear
+1
, i.e. the year the semester ends in (ignored). All years must be between 1990 and one year from now.- Returns:
- The
Semester
object represented by the given string. - Throws:
IllegalArgumentException
- If the given string does not match the required format or if the year is before 1990 or after one year from now.- Implementation Note:
- Will stop working (correctly)
in the year
2090, because the method assumes thatYY
-formatted years between 90 and 99 are in the 20th century.
-