Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/lang/Package/IsCompatibleWith.java
41149 views
1
/*
2
* Copyright (c) 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
public class IsCompatibleWith {
25
private static boolean fail = false;
26
private static Package p = p.A.class.getPackage();
27
28
public static void main(String [] args) {
29
IsCompatibleWith s = new IsCompatibleWith();
30
31
s.ex("");
32
s.ex("x.31");
33
s.ex("5....");
34
s.ex("10.3a");
35
s.ex("2.-2");
36
s.ex("-1.0");
37
s.ex(".01");
38
39
s.t("0");
40
s.t("1.4");
41
s.t("1.4.0");
42
s.f("1.415");
43
s.t("1.3.1.0.0.0.0.7");
44
s.t("1.2.02");
45
s.f("1.4.35");
46
s.f("33.0");
47
48
s.f(new Integer(Integer.MAX_VALUE).toString());
49
s.ex("2147483648"); // Integer.MAX_VALUE + 1
50
51
if (fail == true)
52
throw new RuntimeException("Test FAILED");
53
else
54
System.out.println("Test PASSED");
55
}
56
57
// NumberFormatException expected
58
private void ex(String s) {
59
try {
60
p.isCompatibleWith(s);
61
} catch (NumberFormatException e) {
62
System.out.println("PASS: \"" + s + "\"");
63
e.printStackTrace(System.out);
64
return;
65
}
66
fail = true;
67
System.err.println("FAIL: Exception missing: \"" + s + "\"");
68
}
69
70
// "true" or "false" expected
71
private void t(String s) { test(s, true); }
72
private void f(String s) { test(s, false); }
73
74
private void test(String s, boolean expect) {
75
try {
76
if (p.isCompatibleWith(s) != expect) {
77
System.err.println("FAIL: \"" + s + "\", expected: " + expect);
78
fail = true;
79
return;
80
}
81
} catch (Exception e) {
82
System.err.println("FAIL: \"" + s + "\"");
83
e.printStackTrace();
84
fail = true;
85
return;
86
}
87
System.out.println("PASS: \"" + s + "\"");
88
}
89
}
90
91