forked from LittleVer/Javaee-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTermContainer.java
More file actions
83 lines (64 loc) · 2.14 KB
/
TermContainer.java
File metadata and controls
83 lines (64 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.util;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import org.springframework.stereotype.Component;
/**
* Created by c0de8ug on 16-2-15.
*/
@Component
public class TermContainer {
static List<Term> termList;
static Date beginTime;
static HashMap<String, String> map = new HashMap<>();
final static String lastTermStr = "上学期";
final static String nextTermStr = "下学期";
String lastSemester = "2,3,4,5,6,7,8";
String nextSemester = "1,9,10,11,12";
TermContainer() {
for (String temp : lastSemester.split(",")) {
map.put(temp, lastTermStr);
}
for (String temp : nextSemester.split(",")) {
map.put(temp, nextTermStr);
}
beginTime = new GregorianCalendar(2014,1,1).getTime();
update();
}
public static void update() {
termList = new ArrayList<>();
Date today = new Date();
int beginYear = beginTime.getYear();
int todayYear = today.getYear();
int count = todayYear - beginYear;
if (map.get(String.valueOf(today.getMonth())).equals(nextTermStr)) {
Term term = new Term();
term.setVal(todayYear + "2");
term.setText(todayYear + nextTermStr);
termList.add(term);
}
Term term = new Term();
term.setVal(todayYear + "1");
term.setText(todayYear + lastTermStr);
termList.add(term);
for (int i = 0; i < count; i++) {
todayYear--;
term = new Term();
term.setVal(todayYear + "2");
term.setText(todayYear + nextTermStr);
termList.add(term);
term = new Term();
term.setVal(todayYear + "1");
term.setText(todayYear + lastTermStr);
termList.add(term);
}
}
public static String now() {
return termList.get(0).getVal();
}
public static List<Term> getTermList() {
return termList;
}
}