Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/langtools/tools/lib/toolbox/Assert.java
41149 views
1
/*
2
* Copyright (c) 2011, 2016, 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
package toolbox;
25
26
import java.util.function.Supplier;
27
28
/**
29
* Simple facility for unconditional assertions.
30
* The methods in this class are described in terms of equivalent assert
31
* statements, assuming that assertions have been enabled.
32
*/
33
public class Assert {
34
/** Equivalent to
35
* assert cond;
36
*/
37
public static void check(boolean cond) {
38
if (!cond)
39
error();
40
}
41
42
/** Equivalent to
43
* assert (o == null);
44
*/
45
public static void checkNull(Object o) {
46
if (o != null)
47
error();
48
}
49
50
/** Equivalent to
51
* assert (t != null); return t;
52
*/
53
public static <T> T checkNonNull(T t) {
54
if (t == null)
55
error();
56
return t;
57
}
58
59
/** Equivalent to
60
* assert cond : value;
61
*/
62
public static void check(boolean cond, int value) {
63
if (!cond)
64
error(String.valueOf(value));
65
}
66
67
/** Equivalent to
68
* assert cond : value;
69
*/
70
public static void check(boolean cond, long value) {
71
if (!cond)
72
error(String.valueOf(value));
73
}
74
75
/** Equivalent to
76
* assert cond : value;
77
*/
78
public static void check(boolean cond, Object value) {
79
if (!cond)
80
error(String.valueOf(value));
81
}
82
83
/** Equivalent to
84
* assert cond : msg;
85
*/
86
public static void check(boolean cond, String msg) {
87
if (!cond)
88
error(msg);
89
}
90
91
/** Equivalent to
92
* assert cond : msg.get();
93
* Note: message string is computed lazily.
94
*/
95
public static void check(boolean cond, Supplier<String> msg) {
96
if (!cond)
97
error(msg.get());
98
}
99
100
/** Equivalent to
101
* assert (o == null) : value;
102
*/
103
public static void checkNull(Object o, Object value) {
104
if (o != null)
105
error(String.valueOf(value));
106
}
107
108
/** Equivalent to
109
* assert (o == null) : msg;
110
*/
111
public static void checkNull(Object o, String msg) {
112
if (o != null)
113
error(msg);
114
}
115
116
/** Equivalent to
117
* assert (o == null) : msg.get();
118
* Note: message string is computed lazily.
119
*/
120
public static void checkNull(Object o, Supplier<String> msg) {
121
if (o != null)
122
error(msg.get());
123
}
124
125
/** Equivalent to
126
* assert (o != null) : msg;
127
*/
128
public static <T> T checkNonNull(T t, String msg) {
129
if (t == null)
130
error(msg);
131
return t;
132
}
133
134
/** Equivalent to
135
* assert (o != null) : msg.get();
136
* Note: message string is computed lazily.
137
*/
138
public static <T> T checkNonNull(T t, Supplier<String> msg) {
139
if (t == null)
140
error(msg.get());
141
return t;
142
}
143
144
/** Equivalent to
145
* assert false;
146
*/
147
public static void error() {
148
throw new AssertionError();
149
}
150
151
/** Equivalent to
152
* assert false : msg;
153
*/
154
public static void error(String msg) {
155
throw new AssertionError(msg);
156
}
157
158
/** Prevent instantiation. */
159
private Assert() { }
160
}
161
162