Finished Date object
Signed-off-by: Jim Martens <github@2martens.de>
This commit is contained in:
parent
6b441cfb63
commit
422669c2ba
|
@ -1,12 +1,27 @@
|
|||
package de.dis2017.data;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Date {
|
||||
private static Map<String, Date> _dates;
|
||||
private static List<Date> _datesList;
|
||||
|
||||
private int _dateID;
|
||||
private int _day;
|
||||
private int _month;
|
||||
private int _quarter;
|
||||
private int _year;
|
||||
|
||||
static {
|
||||
_dates = new HashMap<>();
|
||||
_datesList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public int get_dateID() {
|
||||
return _dateID;
|
||||
}
|
||||
|
@ -29,6 +44,28 @@ public class Date {
|
|||
|
||||
public void set_month(int _month) {
|
||||
this._month = _month;
|
||||
switch (this._month) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
_quarter = 1;
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
_quarter = 2;
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
_quarter = 3;
|
||||
break;
|
||||
case 10:
|
||||
case 11:
|
||||
case 12:
|
||||
_quarter = 4;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public int get_quarter() {
|
||||
|
@ -46,4 +83,27 @@ public class Date {
|
|||
public void set_year(int _year) {
|
||||
this._year = _year;
|
||||
}
|
||||
|
||||
public static Date parse(String date) {
|
||||
if (_dates.containsKey(date)) {
|
||||
return _dates.get(date);
|
||||
}
|
||||
|
||||
String[] elements = date.split(".");
|
||||
Date newDate = new Date();
|
||||
newDate.set_dateID(Integer.parseInt(elements[2] + elements[1] + elements[0]));
|
||||
newDate.set_day(Integer.parseInt(elements[0]));
|
||||
newDate.set_month(Integer.parseInt(elements[1]));
|
||||
newDate.set_year(Integer.parseInt(elements[2]));
|
||||
|
||||
_dates.put(date, newDate);
|
||||
_datesList.add(newDate);
|
||||
|
||||
return newDate;
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
public static List<Date> getDates() {
|
||||
return _datesList;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue