Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Calendar/CalendarTestScripts/JapaneseRollDayOfWeekTestGenerator.java
41152 views
1
/*
2
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.PrintWriter;
25
import java.nio.file.Path;
26
import java.nio.file.Paths;
27
import java.util.GregorianCalendar;
28
import java.util.Locale;
29
import static java.util.Calendar.*;
30
31
32
public class JapaneseRollDayOfWeekTestGenerator {
33
private static final String[] ERAS = {
34
"BeforeMeiji", "Meiji", "Taisho", "Showa", "Heisei"
35
};
36
37
private static final String[] DAYOFWEEK = {
38
null, "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
39
};
40
41
private static final int[] DAYOFMONTH = {
42
25, 26, 27, 28, 29, 30, 31,
43
1, 2, 3, 4, 5, 6, 7
44
};
45
46
private static final int DOM_BASE = 7;
47
48
//Usage: JapaneseRollDayOfWeekTestGenerator will generate test script into
49
// file rolldow.cts.
50
public static void generateTestScript(String[] args) throws Exception{
51
Locale.setDefault(Locale.ROOT);
52
53
//This test generator assumes that Heisei has (nYears - 1) or more years.
54
int nYears = (args.length == 1) ?
55
Math.max(3, Math.min(Integer.parseInt(args[0]), 40)) : 28;
56
57
// Start from Showa 63
58
int era = 3;
59
int year = 63;
60
Path testPath = Paths.get(System.getProperty("test.classes"));
61
String scFileName = testPath + "/rolldow.cts";
62
63
try (PrintWriter out = new PrintWriter(scFileName)){
64
out.println("locale ja JP JP\n" + "new instance jcal\n" + "use jcal");
65
for (int y = 0; y < nYears; y++) {
66
out.printf("\nTest %s %d\n", ERAS[era], year);
67
for (int fdw = SUNDAY; fdw <= SATURDAY; fdw++) {
68
int endFdw = fdw + 6;
69
if (endFdw > SATURDAY) {
70
endFdw -= 7;
71
}
72
for (int mdifw = 1; mdifw <= 7; mdifw++) {
73
int domIndex = DOM_BASE;
74
out.println(" clear all");
75
out.printf(" set FirstDayOfWeek %s\n", DAYOFWEEK[fdw]);
76
out.printf(" set MinimalDaysInFirstWeek %d\n", mdifw);
77
out.printf(" set date %s %d Jan 1\n", ERAS[era], year);
78
out.println(" get week_of_year\n" + " assign $result $woy");
79
out.println(" get day_of_week\n" + " assign $result $doy");
80
81
int gyear = year + (year >= 60 ? 1925 : 1988);
82
int next = new GregorianCalendar(gyear, JANUARY, 1).get(DAY_OF_WEEK);
83
for (int i = 0; i < 10; i++) {
84
85
out.println(" roll day_of_week 1");
86
next = nextFdw(next, fdw, endFdw);
87
if (next == fdw) {
88
domIndex -= 6;
89
} else {
90
domIndex++;
91
}
92
int dom = DAYOFMONTH[domIndex];
93
out.printf("\tcheck date %d %s %d%n", (dom >= 25) ? year - 1 : year,
94
(dom >= 25) ? "Dec" : "Jan", dom);
95
out.println("\teval $doy + 1");
96
out.println("\tassign $result $doy");
97
out.println("\tassign Sun $doy if $doy > Sat");
98
out.println("\tcheck day_of_week $doy");
99
out.println("\tcheck week_of_year $woy");
100
}
101
102
for (int i = 0; i < 10; i++) {
103
out.println("\troll day_of_week -1");
104
out.println("\teval $doy - 1");
105
out.println("\tassign $result $doy");
106
out.println("\tassign Sat $doy if $doy < Sun");
107
out.println("\tcheck day_of_week $doy");
108
out.println("\tcheck week_of_year $woy");
109
}
110
}
111
}
112
113
if (year == 64 && era == 3) {
114
era++;
115
year = 2;
116
} else {
117
year++;
118
}
119
}
120
}
121
}
122
123
private static int nextFdw(int x, int start, int end) {
124
if (x == end)
125
return start;
126
x++;
127
if (x > SATURDAY)
128
x = SUNDAY;
129
return x;
130
}
131
}
132
133