Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/text/Format/ChoiceFormat/Bug8001209.java
41152 views
1
/*
2
* Copyright (c) 2012, 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
/**
25
* @test
26
* @bug 8001209
27
* @summary Confirm that the values set by setChoices() are not mutable.
28
*/
29
import java.text.*;
30
31
public class Bug8001209 {
32
33
public static void main(String[] args) throws Exception {
34
boolean err = false;
35
36
// Borrow an example in API doc
37
double[] limits = {1,2,3,4,5,6,7};
38
String[] dayOfWeekNames = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
39
ChoiceFormat form = new ChoiceFormat(limits, dayOfWeekNames);
40
ParsePosition status = new ParsePosition(0);
41
42
StringBuilder before = new StringBuilder();
43
for (double i = 1.0; i <= 7.0; ++i) {
44
status.setIndex(0);
45
String s = form.format(i);
46
before.append(" ");
47
before.append(s);
48
before.append(form.parse(form.format(i),status));
49
}
50
String original = before.toString();
51
52
double[] newLimits = form.getLimits();
53
String[] newFormats = (String[])form.getFormats();
54
newFormats[6] = "Doyoubi";
55
StringBuilder after = new StringBuilder();
56
for (double i = 1.0; i <= 7.0; ++i) {
57
status.setIndex(0);
58
String s = form.format(i);
59
after.append(" ");
60
after.append(s);
61
after.append(form.parse(form.format(i),status));
62
}
63
if (!original.equals(after.toString())) {
64
err = true;
65
System.err.println(" Expected:" + before
66
+ "\n Got: " + after);
67
}
68
69
dayOfWeekNames[6] = "Saturday";
70
after = new StringBuilder();
71
for (double i = 1.0; i <= 7.0; ++i) {
72
status.setIndex(0);
73
String s = form.format(i);
74
after.append(" ");
75
after.append(s);
76
after.append(form.parse(form.format(i),status));
77
}
78
if (!original.equals(after.toString())) {
79
err = true;
80
System.err.println(" Expected:" + before
81
+ "\n Got: " + after);
82
}
83
84
if (err) {
85
throw new RuntimeException("Failed.");
86
} else {
87
System.out.println("Passed.");
88
}
89
}
90
}
91
92