author | iris |
Thu, 19 May 2016 12:04:54 -0700 | |
changeset 38432 | 892603099bb0 |
parent 37606 | e74fdd1e637f |
child 39302 | aa8d0bc2a6d2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
2 |
* Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.lang; |
|
27 |
||
28 |
import java.io.*; |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
29 |
import java.math.BigInteger; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
30 |
import java.util.AbstractList; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
31 |
import java.util.Arrays; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
32 |
import java.util.ArrayList; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
33 |
import java.util.regex.Matcher; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
34 |
import java.util.regex.Pattern; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
35 |
import java.util.stream.Collectors; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
36 |
import java.util.Collections; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
37 |
import java.util.List; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
38 |
import java.util.Optional; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
39 |
import java.util.RandomAccess; |
2 | 40 |
import java.util.StringTokenizer; |
37363
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
41 |
import jdk.internal.reflect.CallerSensitive; |
329dba26ffd2
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
34350
diff
changeset
|
42 |
import jdk.internal.reflect.Reflection; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
43 |
import sun.security.action.GetPropertyAction; |
2 | 44 |
|
45 |
/** |
|
46 |
* Every Java application has a single instance of class |
|
30042 | 47 |
* {@code Runtime} that allows the application to interface with |
2 | 48 |
* the environment in which the application is running. The current |
30042 | 49 |
* runtime can be obtained from the {@code getRuntime} method. |
2 | 50 |
* <p> |
51 |
* An application cannot create its own instance of this class. |
|
52 |
* |
|
53 |
* @author unascribed |
|
54 |
* @see java.lang.Runtime#getRuntime() |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
55 |
* @since 1.0 |
2 | 56 |
*/ |
57 |
||
58 |
public class Runtime { |
|
34350 | 59 |
private static final Runtime currentRuntime = new Runtime(); |
2 | 60 |
|
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
61 |
private static Version version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
62 |
|
2 | 63 |
/** |
64 |
* Returns the runtime object associated with the current Java application. |
|
30042 | 65 |
* Most of the methods of class {@code Runtime} are instance |
2 | 66 |
* methods and must be invoked with respect to the current runtime object. |
67 |
* |
|
30042 | 68 |
* @return the {@code Runtime} object associated with the current |
2 | 69 |
* Java application. |
70 |
*/ |
|
71 |
public static Runtime getRuntime() { |
|
72 |
return currentRuntime; |
|
73 |
} |
|
74 |
||
75 |
/** Don't let anyone else instantiate this class */ |
|
76 |
private Runtime() {} |
|
77 |
||
78 |
/** |
|
79 |
* Terminates the currently running Java virtual machine by initiating its |
|
80 |
* shutdown sequence. This method never returns normally. The argument |
|
81 |
* serves as a status code; by convention, a nonzero status code indicates |
|
82 |
* abnormal termination. |
|
83 |
* |
|
84 |
* <p> The virtual machine's shutdown sequence consists of two phases. In |
|
85 |
* the first phase all registered {@link #addShutdownHook shutdown hooks}, |
|
86 |
* if any, are started in some unspecified order and allowed to run |
|
87 |
* concurrently until they finish. In the second phase all uninvoked |
|
88 |
* finalizers are run if {@link #runFinalizersOnExit finalization-on-exit} |
|
30042 | 89 |
* has been enabled. Once this is done the virtual machine {@link #halt halts}. |
2 | 90 |
* |
91 |
* <p> If this method is invoked after the virtual machine has begun its |
|
92 |
* shutdown sequence then if shutdown hooks are being run this method will |
|
93 |
* block indefinitely. If shutdown hooks have already been run and on-exit |
|
94 |
* finalization has been enabled then this method halts the virtual machine |
|
95 |
* with the given status code if the status is nonzero; otherwise, it |
|
96 |
* blocks indefinitely. |
|
97 |
* |
|
30042 | 98 |
* <p> The {@link System#exit(int) System.exit} method is the |
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
99 |
* conventional and convenient means of invoking this method. |
2 | 100 |
* |
101 |
* @param status |
|
102 |
* Termination status. By convention, a nonzero status code |
|
103 |
* indicates abnormal termination. |
|
104 |
* |
|
105 |
* @throws SecurityException |
|
30042 | 106 |
* If a security manager is present and its |
107 |
* {@link SecurityManager#checkExit checkExit} method does not permit |
|
2 | 108 |
* exiting with the specified status |
109 |
* |
|
110 |
* @see java.lang.SecurityException |
|
111 |
* @see java.lang.SecurityManager#checkExit(int) |
|
112 |
* @see #addShutdownHook |
|
113 |
* @see #removeShutdownHook |
|
114 |
* @see #runFinalizersOnExit |
|
115 |
* @see #halt(int) |
|
116 |
*/ |
|
117 |
public void exit(int status) { |
|
118 |
SecurityManager security = System.getSecurityManager(); |
|
119 |
if (security != null) { |
|
120 |
security.checkExit(status); |
|
121 |
} |
|
122 |
Shutdown.exit(status); |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Registers a new virtual-machine shutdown hook. |
|
127 |
* |
|
128 |
* <p> The Java virtual machine <i>shuts down</i> in response to two kinds |
|
129 |
* of events: |
|
130 |
* |
|
131 |
* <ul> |
|
132 |
* |
|
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
133 |
* <li> The program <i>exits</i> normally, when the last non-daemon |
30042 | 134 |
* thread exits or when the {@link #exit exit} (equivalently, |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
135 |
* {@link System#exit(int) System.exit}) method is invoked, or |
2 | 136 |
* |
18546
862067c6481c
8017550: Fix doclint issues in java.lang and subpackages
darcy
parents:
16906
diff
changeset
|
137 |
* <li> The virtual machine is <i>terminated</i> in response to a |
30042 | 138 |
* user interrupt, such as typing {@code ^C}, or a system-wide event, |
2 | 139 |
* such as user logoff or system shutdown. |
140 |
* |
|
141 |
* </ul> |
|
142 |
* |
|
143 |
* <p> A <i>shutdown hook</i> is simply an initialized but unstarted |
|
144 |
* thread. When the virtual machine begins its shutdown sequence it will |
|
145 |
* start all registered shutdown hooks in some unspecified order and let |
|
146 |
* them run concurrently. When all the hooks have finished it will then |
|
147 |
* run all uninvoked finalizers if finalization-on-exit has been enabled. |
|
148 |
* Finally, the virtual machine will halt. Note that daemon threads will |
|
149 |
* continue to run during the shutdown sequence, as will non-daemon threads |
|
30042 | 150 |
* if shutdown was initiated by invoking the {@link #exit exit} method. |
2 | 151 |
* |
152 |
* <p> Once the shutdown sequence has begun it can be stopped only by |
|
30042 | 153 |
* invoking the {@link #halt halt} method, which forcibly |
2 | 154 |
* terminates the virtual machine. |
155 |
* |
|
156 |
* <p> Once the shutdown sequence has begun it is impossible to register a |
|
157 |
* new shutdown hook or de-register a previously-registered hook. |
|
158 |
* Attempting either of these operations will cause an |
|
30042 | 159 |
* {@link IllegalStateException} to be thrown. |
2 | 160 |
* |
161 |
* <p> Shutdown hooks run at a delicate time in the life cycle of a virtual |
|
162 |
* machine and should therefore be coded defensively. They should, in |
|
163 |
* particular, be written to be thread-safe and to avoid deadlocks insofar |
|
164 |
* as possible. They should also not rely blindly upon services that may |
|
165 |
* have registered their own shutdown hooks and therefore may themselves in |
|
166 |
* the process of shutting down. Attempts to use other thread-based |
|
167 |
* services such as the AWT event-dispatch thread, for example, may lead to |
|
168 |
* deadlocks. |
|
169 |
* |
|
170 |
* <p> Shutdown hooks should also finish their work quickly. When a |
|
30042 | 171 |
* program invokes {@link #exit exit} the expectation is |
2 | 172 |
* that the virtual machine will promptly shut down and exit. When the |
173 |
* virtual machine is terminated due to user logoff or system shutdown the |
|
174 |
* underlying operating system may only allow a fixed amount of time in |
|
175 |
* which to shut down and exit. It is therefore inadvisable to attempt any |
|
176 |
* user interaction or to perform a long-running computation in a shutdown |
|
177 |
* hook. |
|
178 |
* |
|
179 |
* <p> Uncaught exceptions are handled in shutdown hooks just as in any |
|
30042 | 180 |
* other thread, by invoking the |
181 |
* {@link ThreadGroup#uncaughtException uncaughtException} method of the |
|
182 |
* thread's {@link ThreadGroup} object. The default implementation of this |
|
183 |
* method prints the exception's stack trace to {@link System#err} and |
|
2 | 184 |
* terminates the thread; it does not cause the virtual machine to exit or |
185 |
* halt. |
|
186 |
* |
|
187 |
* <p> In rare circumstances the virtual machine may <i>abort</i>, that is, |
|
188 |
* stop running without shutting down cleanly. This occurs when the |
|
189 |
* virtual machine is terminated externally, for example with the |
|
30042 | 190 |
* {@code SIGKILL} signal on Unix or the {@code TerminateProcess} call on |
2 | 191 |
* Microsoft Windows. The virtual machine may also abort if a native |
192 |
* method goes awry by, for example, corrupting internal data structures or |
|
193 |
* attempting to access nonexistent memory. If the virtual machine aborts |
|
194 |
* then no guarantee can be made about whether or not any shutdown hooks |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
195 |
* will be run. |
2 | 196 |
* |
197 |
* @param hook |
|
30042 | 198 |
* An initialized but unstarted {@link Thread} object |
2 | 199 |
* |
200 |
* @throws IllegalArgumentException |
|
201 |
* If the specified hook has already been registered, |
|
202 |
* or if it can be determined that the hook is already running or |
|
203 |
* has already been run |
|
204 |
* |
|
205 |
* @throws IllegalStateException |
|
206 |
* If the virtual machine is already in the process |
|
207 |
* of shutting down |
|
208 |
* |
|
209 |
* @throws SecurityException |
|
210 |
* If a security manager is present and it denies |
|
30042 | 211 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 212 |
* |
213 |
* @see #removeShutdownHook |
|
214 |
* @see #halt(int) |
|
215 |
* @see #exit(int) |
|
216 |
* @since 1.3 |
|
217 |
*/ |
|
218 |
public void addShutdownHook(Thread hook) { |
|
219 |
SecurityManager sm = System.getSecurityManager(); |
|
220 |
if (sm != null) { |
|
221 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
222 |
} |
|
223 |
ApplicationShutdownHooks.add(hook); |
|
224 |
} |
|
225 |
||
226 |
/** |
|
30042 | 227 |
* De-registers a previously-registered virtual-machine shutdown hook. |
2 | 228 |
* |
229 |
* @param hook the hook to remove |
|
30042 | 230 |
* @return {@code true} if the specified hook had previously been |
231 |
* registered and was successfully de-registered, {@code false} |
|
2 | 232 |
* otherwise. |
233 |
* |
|
234 |
* @throws IllegalStateException |
|
235 |
* If the virtual machine is already in the process of shutting |
|
236 |
* down |
|
237 |
* |
|
238 |
* @throws SecurityException |
|
239 |
* If a security manager is present and it denies |
|
30042 | 240 |
* {@link RuntimePermission}("shutdownHooks") |
2 | 241 |
* |
242 |
* @see #addShutdownHook |
|
243 |
* @see #exit(int) |
|
244 |
* @since 1.3 |
|
245 |
*/ |
|
246 |
public boolean removeShutdownHook(Thread hook) { |
|
247 |
SecurityManager sm = System.getSecurityManager(); |
|
248 |
if (sm != null) { |
|
249 |
sm.checkPermission(new RuntimePermission("shutdownHooks")); |
|
250 |
} |
|
251 |
return ApplicationShutdownHooks.remove(hook); |
|
252 |
} |
|
253 |
||
254 |
/** |
|
255 |
* Forcibly terminates the currently running Java virtual machine. This |
|
256 |
* method never returns normally. |
|
257 |
* |
|
258 |
* <p> This method should be used with extreme caution. Unlike the |
|
30042 | 259 |
* {@link #exit exit} method, this method does not cause shutdown |
2 | 260 |
* hooks to be started and does not run uninvoked finalizers if |
261 |
* finalization-on-exit has been enabled. If the shutdown sequence has |
|
262 |
* already been initiated then this method does not wait for any running |
|
24367
705490680527
8030709: Tidy warnings cleanup for java.lang package; minor cleanup in java.math, javax.script
yan
parents:
18776
diff
changeset
|
263 |
* shutdown hooks or finalizers to finish their work. |
2 | 264 |
* |
265 |
* @param status |
|
30042 | 266 |
* Termination status. By convention, a nonzero status code |
267 |
* indicates abnormal termination. If the {@link Runtime#exit exit} |
|
268 |
* (equivalently, {@link System#exit(int) System.exit}) method |
|
269 |
* has already been invoked then this status code |
|
270 |
* will override the status code passed to that method. |
|
2 | 271 |
* |
272 |
* @throws SecurityException |
|
30042 | 273 |
* If a security manager is present and its |
274 |
* {@link SecurityManager#checkExit checkExit} method |
|
275 |
* does not permit an exit with the specified status |
|
2 | 276 |
* |
277 |
* @see #exit |
|
278 |
* @see #addShutdownHook |
|
279 |
* @see #removeShutdownHook |
|
280 |
* @since 1.3 |
|
281 |
*/ |
|
282 |
public void halt(int status) { |
|
283 |
SecurityManager sm = System.getSecurityManager(); |
|
284 |
if (sm != null) { |
|
285 |
sm.checkExit(status); |
|
286 |
} |
|
287 |
Shutdown.halt(status); |
|
288 |
} |
|
289 |
||
290 |
/** |
|
291 |
* Enable or disable finalization on exit; doing so specifies that the |
|
292 |
* finalizers of all objects that have finalizers that have not yet been |
|
293 |
* automatically invoked are to be run before the Java runtime exits. |
|
294 |
* By default, finalization on exit is disabled. |
|
295 |
* |
|
296 |
* <p>If there is a security manager, |
|
30042 | 297 |
* its {@code checkExit} method is first called |
2 | 298 |
* with 0 as its argument to ensure the exit is allowed. |
299 |
* This could result in a SecurityException. |
|
300 |
* |
|
301 |
* @param value true to enable finalization on exit, false to disable |
|
302 |
* @deprecated This method is inherently unsafe. It may result in |
|
303 |
* finalizers being called on live objects while other threads are |
|
304 |
* concurrently manipulating those objects, resulting in erratic |
|
305 |
* behavior or deadlock. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
306 |
* This method is subject to removal in a future version of Java SE. |
2 | 307 |
* |
308 |
* @throws SecurityException |
|
30042 | 309 |
* if a security manager exists and its {@code checkExit} |
2 | 310 |
* method doesn't allow the exit. |
311 |
* |
|
312 |
* @see java.lang.Runtime#exit(int) |
|
313 |
* @see java.lang.Runtime#gc() |
|
314 |
* @see java.lang.SecurityManager#checkExit(int) |
|
24865
09b1d992ca72
8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
henryjen
parents:
24367
diff
changeset
|
315 |
* @since 1.1 |
2 | 316 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
317 |
@Deprecated(since="1.2", forRemoval=true) |
2 | 318 |
public static void runFinalizersOnExit(boolean value) { |
319 |
SecurityManager security = System.getSecurityManager(); |
|
320 |
if (security != null) { |
|
321 |
try { |
|
322 |
security.checkExit(0); |
|
323 |
} catch (SecurityException e) { |
|
324 |
throw new SecurityException("runFinalizersOnExit"); |
|
325 |
} |
|
326 |
} |
|
327 |
Shutdown.setRunFinalizersOnExit(value); |
|
328 |
} |
|
329 |
||
330 |
/** |
|
331 |
* Executes the specified string command in a separate process. |
|
332 |
* |
|
333 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 334 |
* {@code exec(command)} |
2 | 335 |
* behaves in exactly the same way as the invocation |
30042 | 336 |
* {@link #exec(String, String[], File) exec}{@code (command, null, null)}. |
2 | 337 |
* |
338 |
* @param command a specified system command. |
|
339 |
* |
|
340 |
* @return A new {@link Process} object for managing the subprocess |
|
341 |
* |
|
342 |
* @throws SecurityException |
|
343 |
* If a security manager exists and its |
|
344 |
* {@link SecurityManager#checkExec checkExec} |
|
345 |
* method doesn't allow creation of the subprocess |
|
346 |
* |
|
347 |
* @throws IOException |
|
348 |
* If an I/O error occurs |
|
349 |
* |
|
350 |
* @throws NullPointerException |
|
30042 | 351 |
* If {@code command} is {@code null} |
2 | 352 |
* |
353 |
* @throws IllegalArgumentException |
|
30042 | 354 |
* If {@code command} is empty |
2 | 355 |
* |
356 |
* @see #exec(String[], String[], File) |
|
357 |
* @see ProcessBuilder |
|
358 |
*/ |
|
359 |
public Process exec(String command) throws IOException { |
|
360 |
return exec(command, null, null); |
|
361 |
} |
|
362 |
||
363 |
/** |
|
364 |
* Executes the specified string command in a separate process with the |
|
365 |
* specified environment. |
|
366 |
* |
|
367 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 368 |
* {@code exec(command, envp)} |
2 | 369 |
* behaves in exactly the same way as the invocation |
30042 | 370 |
* {@link #exec(String, String[], File) exec}{@code (command, envp, null)}. |
2 | 371 |
* |
372 |
* @param command a specified system command. |
|
373 |
* |
|
374 |
* @param envp array of strings, each element of which |
|
375 |
* has environment variable settings in the format |
|
376 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 377 |
* {@code null} if the subprocess should inherit |
2 | 378 |
* the environment of the current process. |
379 |
* |
|
380 |
* @return A new {@link Process} object for managing the subprocess |
|
381 |
* |
|
382 |
* @throws SecurityException |
|
383 |
* If a security manager exists and its |
|
384 |
* {@link SecurityManager#checkExec checkExec} |
|
385 |
* method doesn't allow creation of the subprocess |
|
386 |
* |
|
387 |
* @throws IOException |
|
388 |
* If an I/O error occurs |
|
389 |
* |
|
390 |
* @throws NullPointerException |
|
30042 | 391 |
* If {@code command} is {@code null}, |
392 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 393 |
* |
394 |
* @throws IllegalArgumentException |
|
30042 | 395 |
* If {@code command} is empty |
2 | 396 |
* |
397 |
* @see #exec(String[], String[], File) |
|
398 |
* @see ProcessBuilder |
|
399 |
*/ |
|
400 |
public Process exec(String command, String[] envp) throws IOException { |
|
401 |
return exec(command, envp, null); |
|
402 |
} |
|
403 |
||
404 |
/** |
|
405 |
* Executes the specified string command in a separate process with the |
|
406 |
* specified environment and working directory. |
|
407 |
* |
|
408 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 409 |
* {@code exec(command, envp, dir)} |
2 | 410 |
* behaves in exactly the same way as the invocation |
30042 | 411 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, dir)}, |
412 |
* where {@code cmdarray} is an array of all the tokens in |
|
413 |
* {@code command}. |
|
2 | 414 |
* |
30042 | 415 |
* <p>More precisely, the {@code command} string is broken |
2 | 416 |
* into tokens using a {@link StringTokenizer} created by the call |
30042 | 417 |
* {@code new {@link StringTokenizer}(command)} with no |
2 | 418 |
* further modification of the character categories. The tokens |
419 |
* produced by the tokenizer are then placed in the new string |
|
30042 | 420 |
* array {@code cmdarray}, in the same order. |
2 | 421 |
* |
422 |
* @param command a specified system command. |
|
423 |
* |
|
424 |
* @param envp array of strings, each element of which |
|
425 |
* has environment variable settings in the format |
|
426 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 427 |
* {@code null} if the subprocess should inherit |
2 | 428 |
* the environment of the current process. |
429 |
* |
|
430 |
* @param dir the working directory of the subprocess, or |
|
30042 | 431 |
* {@code null} if the subprocess should inherit |
2 | 432 |
* the working directory of the current process. |
433 |
* |
|
434 |
* @return A new {@link Process} object for managing the subprocess |
|
435 |
* |
|
436 |
* @throws SecurityException |
|
437 |
* If a security manager exists and its |
|
438 |
* {@link SecurityManager#checkExec checkExec} |
|
439 |
* method doesn't allow creation of the subprocess |
|
440 |
* |
|
441 |
* @throws IOException |
|
442 |
* If an I/O error occurs |
|
443 |
* |
|
444 |
* @throws NullPointerException |
|
30042 | 445 |
* If {@code command} is {@code null}, |
446 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 447 |
* |
448 |
* @throws IllegalArgumentException |
|
30042 | 449 |
* If {@code command} is empty |
2 | 450 |
* |
451 |
* @see ProcessBuilder |
|
452 |
* @since 1.3 |
|
453 |
*/ |
|
454 |
public Process exec(String command, String[] envp, File dir) |
|
455 |
throws IOException { |
|
456 |
if (command.length() == 0) |
|
457 |
throw new IllegalArgumentException("Empty command"); |
|
458 |
||
459 |
StringTokenizer st = new StringTokenizer(command); |
|
460 |
String[] cmdarray = new String[st.countTokens()]; |
|
461 |
for (int i = 0; st.hasMoreTokens(); i++) |
|
462 |
cmdarray[i] = st.nextToken(); |
|
463 |
return exec(cmdarray, envp, dir); |
|
464 |
} |
|
465 |
||
466 |
/** |
|
467 |
* Executes the specified command and arguments in a separate process. |
|
468 |
* |
|
469 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 470 |
* {@code exec(cmdarray)} |
2 | 471 |
* behaves in exactly the same way as the invocation |
30042 | 472 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, null, null)}. |
2 | 473 |
* |
474 |
* @param cmdarray array containing the command to call and |
|
475 |
* its arguments. |
|
476 |
* |
|
477 |
* @return A new {@link Process} object for managing the subprocess |
|
478 |
* |
|
479 |
* @throws SecurityException |
|
480 |
* If a security manager exists and its |
|
481 |
* {@link SecurityManager#checkExec checkExec} |
|
482 |
* method doesn't allow creation of the subprocess |
|
483 |
* |
|
484 |
* @throws IOException |
|
485 |
* If an I/O error occurs |
|
486 |
* |
|
487 |
* @throws NullPointerException |
|
30042 | 488 |
* If {@code cmdarray} is {@code null}, |
489 |
* or one of the elements of {@code cmdarray} is {@code null} |
|
2 | 490 |
* |
491 |
* @throws IndexOutOfBoundsException |
|
30042 | 492 |
* If {@code cmdarray} is an empty array |
493 |
* (has length {@code 0}) |
|
2 | 494 |
* |
495 |
* @see ProcessBuilder |
|
496 |
*/ |
|
497 |
public Process exec(String cmdarray[]) throws IOException { |
|
498 |
return exec(cmdarray, null, null); |
|
499 |
} |
|
500 |
||
501 |
/** |
|
502 |
* Executes the specified command and arguments in a separate process |
|
503 |
* with the specified environment. |
|
504 |
* |
|
505 |
* <p>This is a convenience method. An invocation of the form |
|
30042 | 506 |
* {@code exec(cmdarray, envp)} |
2 | 507 |
* behaves in exactly the same way as the invocation |
30042 | 508 |
* {@link #exec(String[], String[], File) exec}{@code (cmdarray, envp, null)}. |
2 | 509 |
* |
510 |
* @param cmdarray array containing the command to call and |
|
511 |
* its arguments. |
|
512 |
* |
|
513 |
* @param envp array of strings, each element of which |
|
514 |
* has environment variable settings in the format |
|
515 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 516 |
* {@code null} if the subprocess should inherit |
2 | 517 |
* the environment of the current process. |
518 |
* |
|
519 |
* @return A new {@link Process} object for managing the subprocess |
|
520 |
* |
|
521 |
* @throws SecurityException |
|
522 |
* If a security manager exists and its |
|
523 |
* {@link SecurityManager#checkExec checkExec} |
|
524 |
* method doesn't allow creation of the subprocess |
|
525 |
* |
|
526 |
* @throws IOException |
|
527 |
* If an I/O error occurs |
|
528 |
* |
|
529 |
* @throws NullPointerException |
|
30042 | 530 |
* If {@code cmdarray} is {@code null}, |
531 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
532 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 533 |
* |
534 |
* @throws IndexOutOfBoundsException |
|
30042 | 535 |
* If {@code cmdarray} is an empty array |
536 |
* (has length {@code 0}) |
|
2 | 537 |
* |
538 |
* @see ProcessBuilder |
|
539 |
*/ |
|
540 |
public Process exec(String[] cmdarray, String[] envp) throws IOException { |
|
541 |
return exec(cmdarray, envp, null); |
|
542 |
} |
|
543 |
||
544 |
||
545 |
/** |
|
546 |
* Executes the specified command and arguments in a separate process with |
|
547 |
* the specified environment and working directory. |
|
548 |
* |
|
30042 | 549 |
* <p>Given an array of strings {@code cmdarray}, representing the |
550 |
* tokens of a command line, and an array of strings {@code envp}, |
|
2 | 551 |
* representing "environment" variable settings, this method creates |
552 |
* a new process in which to execute the specified command. |
|
553 |
* |
|
30042 | 554 |
* <p>This method checks that {@code cmdarray} is a valid operating |
2 | 555 |
* system command. Which commands are valid is system-dependent, |
556 |
* but at the very least the command must be a non-empty list of |
|
557 |
* non-null strings. |
|
558 |
* |
|
30042 | 559 |
* <p>If {@code envp} is {@code null}, the subprocess inherits the |
2 | 560 |
* environment settings of the current process. |
561 |
* |
|
9500
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
562 |
* <p>A minimal set of system dependent environment variables may |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
563 |
* be required to start a process on some operating systems. |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
564 |
* As a result, the subprocess may inherit additional environment variable |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
565 |
* settings beyond those in the specified environment. |
268f823d9e1c
7034570: java.lang.Runtime.exec(String[] cmd, String[] env) can not work properly if SystemRoot not inherited
michaelm
parents:
5506
diff
changeset
|
566 |
* |
2 | 567 |
* <p>{@link ProcessBuilder#start()} is now the preferred way to |
568 |
* start a process with a modified environment. |
|
569 |
* |
|
30042 | 570 |
* <p>The working directory of the new subprocess is specified by {@code dir}. |
571 |
* If {@code dir} is {@code null}, the subprocess inherits the |
|
2 | 572 |
* current working directory of the current process. |
573 |
* |
|
574 |
* <p>If a security manager exists, its |
|
575 |
* {@link SecurityManager#checkExec checkExec} |
|
576 |
* method is invoked with the first component of the array |
|
30042 | 577 |
* {@code cmdarray} as its argument. This may result in a |
2 | 578 |
* {@link SecurityException} being thrown. |
579 |
* |
|
580 |
* <p>Starting an operating system process is highly system-dependent. |
|
581 |
* Among the many things that can go wrong are: |
|
582 |
* <ul> |
|
583 |
* <li>The operating system program file was not found. |
|
584 |
* <li>Access to the program file was denied. |
|
585 |
* <li>The working directory does not exist. |
|
586 |
* </ul> |
|
587 |
* |
|
588 |
* <p>In such cases an exception will be thrown. The exact nature |
|
589 |
* of the exception is system-dependent, but it will always be a |
|
590 |
* subclass of {@link IOException}. |
|
591 |
* |
|
28872
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
592 |
* <p>If the operating system does not support the creation of |
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
593 |
* processes, an {@link UnsupportedOperationException} will be thrown. |
82a09f5a7ed6
8072034: (process) ProcessBuilder.start and Runtime.exec UnsupportedOperationException editorial cleanup
rriggs
parents:
28750
diff
changeset
|
594 |
* |
2 | 595 |
* |
596 |
* @param cmdarray array containing the command to call and |
|
597 |
* its arguments. |
|
598 |
* |
|
599 |
* @param envp array of strings, each element of which |
|
600 |
* has environment variable settings in the format |
|
601 |
* <i>name</i>=<i>value</i>, or |
|
30042 | 602 |
* {@code null} if the subprocess should inherit |
2 | 603 |
* the environment of the current process. |
604 |
* |
|
605 |
* @param dir the working directory of the subprocess, or |
|
30042 | 606 |
* {@code null} if the subprocess should inherit |
2 | 607 |
* the working directory of the current process. |
608 |
* |
|
609 |
* @return A new {@link Process} object for managing the subprocess |
|
610 |
* |
|
611 |
* @throws SecurityException |
|
612 |
* If a security manager exists and its |
|
613 |
* {@link SecurityManager#checkExec checkExec} |
|
614 |
* method doesn't allow creation of the subprocess |
|
615 |
* |
|
28750
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
616 |
* @throws UnsupportedOperationException |
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
617 |
* If the operating system does not support the creation of processes. |
a1dae439cdab
8055330: (process spec) ProcessBuilder.start and Runtime.exec should throw UnsupportedOperationException on platforms that don't support
rriggs
parents:
27184
diff
changeset
|
618 |
* |
2 | 619 |
* @throws IOException |
620 |
* If an I/O error occurs |
|
621 |
* |
|
622 |
* @throws NullPointerException |
|
30042 | 623 |
* If {@code cmdarray} is {@code null}, |
624 |
* or one of the elements of {@code cmdarray} is {@code null}, |
|
625 |
* or one of the elements of {@code envp} is {@code null} |
|
2 | 626 |
* |
627 |
* @throws IndexOutOfBoundsException |
|
30042 | 628 |
* If {@code cmdarray} is an empty array |
629 |
* (has length {@code 0}) |
|
2 | 630 |
* |
631 |
* @see ProcessBuilder |
|
632 |
* @since 1.3 |
|
633 |
*/ |
|
634 |
public Process exec(String[] cmdarray, String[] envp, File dir) |
|
635 |
throws IOException { |
|
636 |
return new ProcessBuilder(cmdarray) |
|
637 |
.environment(envp) |
|
638 |
.directory(dir) |
|
639 |
.start(); |
|
640 |
} |
|
641 |
||
642 |
/** |
|
643 |
* Returns the number of processors available to the Java virtual machine. |
|
644 |
* |
|
645 |
* <p> This value may change during a particular invocation of the virtual |
|
646 |
* machine. Applications that are sensitive to the number of available |
|
647 |
* processors should therefore occasionally poll this property and adjust |
|
648 |
* their resource usage appropriately. </p> |
|
649 |
* |
|
650 |
* @return the maximum number of processors available to the virtual |
|
651 |
* machine; never smaller than one |
|
652 |
* @since 1.4 |
|
653 |
*/ |
|
654 |
public native int availableProcessors(); |
|
655 |
||
656 |
/** |
|
657 |
* Returns the amount of free memory in the Java Virtual Machine. |
|
658 |
* Calling the |
|
30042 | 659 |
* {@code gc} method may result in increasing the value returned |
660 |
* by {@code freeMemory.} |
|
2 | 661 |
* |
662 |
* @return an approximation to the total amount of memory currently |
|
663 |
* available for future allocated objects, measured in bytes. |
|
664 |
*/ |
|
665 |
public native long freeMemory(); |
|
666 |
||
667 |
/** |
|
668 |
* Returns the total amount of memory in the Java virtual machine. |
|
669 |
* The value returned by this method may vary over time, depending on |
|
670 |
* the host environment. |
|
671 |
* <p> |
|
672 |
* Note that the amount of memory required to hold an object of any |
|
673 |
* given type may be implementation-dependent. |
|
674 |
* |
|
675 |
* @return the total amount of memory currently available for current |
|
676 |
* and future objects, measured in bytes. |
|
677 |
*/ |
|
678 |
public native long totalMemory(); |
|
679 |
||
680 |
/** |
|
30042 | 681 |
* Returns the maximum amount of memory that the Java virtual machine |
682 |
* will attempt to use. If there is no inherent limit then the value |
|
683 |
* {@link java.lang.Long#MAX_VALUE} will be returned. |
|
2 | 684 |
* |
685 |
* @return the maximum amount of memory that the virtual machine will |
|
686 |
* attempt to use, measured in bytes |
|
687 |
* @since 1.4 |
|
688 |
*/ |
|
689 |
public native long maxMemory(); |
|
690 |
||
691 |
/** |
|
692 |
* Runs the garbage collector. |
|
693 |
* Calling this method suggests that the Java virtual machine expend |
|
694 |
* effort toward recycling unused objects in order to make the memory |
|
695 |
* they currently occupy available for quick reuse. When control |
|
696 |
* returns from the method call, the virtual machine has made |
|
697 |
* its best effort to recycle all discarded objects. |
|
698 |
* <p> |
|
30042 | 699 |
* The name {@code gc} stands for "garbage |
2 | 700 |
* collector". The virtual machine performs this recycling |
701 |
* process automatically as needed, in a separate thread, even if the |
|
30042 | 702 |
* {@code gc} method is not invoked explicitly. |
2 | 703 |
* <p> |
704 |
* The method {@link System#gc()} is the conventional and convenient |
|
705 |
* means of invoking this method. |
|
706 |
*/ |
|
707 |
public native void gc(); |
|
708 |
||
709 |
/* Wormhole for calling java.lang.ref.Finalizer.runFinalization */ |
|
710 |
private static native void runFinalization0(); |
|
711 |
||
712 |
/** |
|
713 |
* Runs the finalization methods of any objects pending finalization. |
|
714 |
* Calling this method suggests that the Java virtual machine expend |
|
30042 | 715 |
* effort toward running the {@code finalize} methods of objects |
716 |
* that have been found to be discarded but whose {@code finalize} |
|
2 | 717 |
* methods have not yet been run. When control returns from the |
718 |
* method call, the virtual machine has made a best effort to |
|
719 |
* complete all outstanding finalizations. |
|
720 |
* <p> |
|
721 |
* The virtual machine performs the finalization process |
|
722 |
* automatically as needed, in a separate thread, if the |
|
30042 | 723 |
* {@code runFinalization} method is not invoked explicitly. |
2 | 724 |
* <p> |
725 |
* The method {@link System#runFinalization()} is the conventional |
|
726 |
* and convenient means of invoking this method. |
|
727 |
* |
|
728 |
* @see java.lang.Object#finalize() |
|
729 |
*/ |
|
730 |
public void runFinalization() { |
|
731 |
runFinalization0(); |
|
732 |
} |
|
733 |
||
734 |
/** |
|
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
735 |
* Not implemented, does nothing. |
2 | 736 |
* |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
737 |
* @deprecated |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
738 |
* This method was intended to control instruction tracing. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
739 |
* It has been superseded by JVM-specific tracing mechanisms. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
740 |
* |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
741 |
* @param on ignored |
2 | 742 |
*/ |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
743 |
@Deprecated(since="9", forRemoval=true) |
27184 | 744 |
public void traceInstructions(boolean on) { } |
2 | 745 |
|
746 |
/** |
|
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
747 |
* Not implemented, does nothing. |
2 | 748 |
* |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
749 |
* @deprecated |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
750 |
* This method was intended to control method call tracing. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
751 |
* It has been superseded by JVM-specific tracing mechanisms. |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
752 |
* |
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
753 |
* @param on ignored |
2 | 754 |
*/ |
37606
e74fdd1e637f
8153330: deprecate Runtime.traceInstructions() and traceMethodCalls()
smarks
parents:
37521
diff
changeset
|
755 |
@Deprecated(since="9", forRemoval=true) |
27184 | 756 |
public void traceMethodCalls(boolean on) { } |
2 | 757 |
|
758 |
/** |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
759 |
* Loads the native library specified by the filename argument. The filename |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
760 |
* argument must be an absolute path name. |
2 | 761 |
* (for example |
30042 | 762 |
* {@code Runtime.getRuntime().load("/home/avh/lib/libX11.so");}). |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
763 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
764 |
* If the filename argument, when stripped of any platform-specific library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
765 |
* prefix, path, and file extension, indicates a library whose name is, |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
766 |
* for example, L, and a native library called L is statically linked |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
767 |
* with the VM, then the JNI_OnLoad_L function exported by the library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
768 |
* is invoked rather than attempting to load a dynamic library. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
769 |
* A filename matching the argument does not have to exist in the file |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
770 |
* system. See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
771 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
772 |
* Otherwise, the filename argument is mapped to a native library image in |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
773 |
* an implementation-dependent manner. |
2 | 774 |
* <p> |
30042 | 775 |
* First, if there is a security manager, its {@code checkLink} |
776 |
* method is called with the {@code filename} as its argument. |
|
2 | 777 |
* This may result in a security exception. |
778 |
* <p> |
|
779 |
* This is similar to the method {@link #loadLibrary(String)}, but it |
|
780 |
* accepts a general file name as an argument rather than just a library |
|
781 |
* name, allowing any file of native code to be loaded. |
|
782 |
* <p> |
|
783 |
* The method {@link System#load(String)} is the conventional and |
|
784 |
* convenient means of invoking this method. |
|
785 |
* |
|
786 |
* @param filename the file to load. |
|
787 |
* @exception SecurityException if a security manager exists and its |
|
30042 | 788 |
* {@code checkLink} method doesn't allow |
2 | 789 |
* loading of the specified dynamic library |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
790 |
* @exception UnsatisfiedLinkError if either the filename is not an |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
791 |
* absolute path name, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
792 |
* linked with the VM, or the library cannot be mapped to |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
793 |
* a native library image by the host system. |
30042 | 794 |
* @exception NullPointerException if {@code filename} is |
795 |
* {@code null} |
|
2 | 796 |
* @see java.lang.Runtime#getRuntime() |
797 |
* @see java.lang.SecurityException |
|
798 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
799 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
800 |
@CallerSensitive |
2 | 801 |
public void load(String filename) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
802 |
load0(Reflection.getCallerClass(), filename); |
2 | 803 |
} |
804 |
||
11117
b6e68b1344d4
7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents:
9500
diff
changeset
|
805 |
synchronized void load0(Class<?> fromClass, String filename) { |
2 | 806 |
SecurityManager security = System.getSecurityManager(); |
807 |
if (security != null) { |
|
808 |
security.checkLink(filename); |
|
809 |
} |
|
810 |
if (!(new File(filename).isAbsolute())) { |
|
811 |
throw new UnsatisfiedLinkError( |
|
812 |
"Expecting an absolute path of the library: " + filename); |
|
813 |
} |
|
814 |
ClassLoader.loadLibrary(fromClass, filename, true); |
|
815 |
} |
|
816 |
||
817 |
/** |
|
30042 | 818 |
* Loads the native library specified by the {@code libname} |
819 |
* argument. The {@code libname} argument must not contain any platform |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
820 |
* specific prefix, file extension or path. If a native library |
30042 | 821 |
* called {@code libname} is statically linked with the VM, then the |
822 |
* JNI_OnLoad_{@code libname} function exported by the library is invoked. |
|
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
823 |
* See the JNI Specification for more details. |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
824 |
* |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
825 |
* Otherwise, the libname argument is loaded from a system library |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
826 |
* location and mapped to a native library image in an implementation- |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
827 |
* dependent manner. |
2 | 828 |
* <p> |
30042 | 829 |
* First, if there is a security manager, its {@code checkLink} |
830 |
* method is called with the {@code libname} as its argument. |
|
2 | 831 |
* This may result in a security exception. |
832 |
* <p> |
|
833 |
* The method {@link System#loadLibrary(String)} is the conventional |
|
834 |
* and convenient means of invoking this method. If native |
|
835 |
* methods are to be used in the implementation of a class, a standard |
|
836 |
* strategy is to put the native code in a library file (call it |
|
30042 | 837 |
* {@code LibFile}) and then to put a static initializer: |
2 | 838 |
* <blockquote><pre> |
839 |
* static { System.loadLibrary("LibFile"); } |
|
840 |
* </pre></blockquote> |
|
841 |
* within the class declaration. When the class is loaded and |
|
842 |
* initialized, the necessary native code implementation for the native |
|
843 |
* methods will then be loaded as well. |
|
844 |
* <p> |
|
845 |
* If this method is called more than once with the same library |
|
846 |
* name, the second and subsequent calls are ignored. |
|
847 |
* |
|
848 |
* @param libname the name of the library. |
|
849 |
* @exception SecurityException if a security manager exists and its |
|
30042 | 850 |
* {@code checkLink} method doesn't allow |
2 | 851 |
* loading of the specified dynamic library |
16479
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
852 |
* @exception UnsatisfiedLinkError if either the libname argument |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
853 |
* contains a file path, the native library is not statically |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
854 |
* linked with the VM, or the library cannot be mapped to a |
d845c18d13f2
8005716: Enhance JNI specification to allow support of static JNI libraries in Embedded JREs
alanb
parents:
14342
diff
changeset
|
855 |
* native library image by the host system. |
30042 | 856 |
* @exception NullPointerException if {@code libname} is |
857 |
* {@code null} |
|
2 | 858 |
* @see java.lang.SecurityException |
859 |
* @see java.lang.SecurityManager#checkLink(java.lang.String) |
|
860 |
*/ |
|
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
861 |
@CallerSensitive |
2 | 862 |
public void loadLibrary(String libname) { |
16906
44dfee24cb71
8010117: Annotate jdk caller sensitive methods with @sun.reflect.CallerSensitive
mchung
parents:
16479
diff
changeset
|
863 |
loadLibrary0(Reflection.getCallerClass(), libname); |
2 | 864 |
} |
865 |
||
11117
b6e68b1344d4
7116404: Miscellaneous warnings (java.rmi.**, serialization, some core classes)
alanb
parents:
9500
diff
changeset
|
866 |
synchronized void loadLibrary0(Class<?> fromClass, String libname) { |
2 | 867 |
SecurityManager security = System.getSecurityManager(); |
868 |
if (security != null) { |
|
869 |
security.checkLink(libname); |
|
870 |
} |
|
871 |
if (libname.indexOf((int)File.separatorChar) != -1) { |
|
872 |
throw new UnsatisfiedLinkError( |
|
873 |
"Directory separator should not appear in library name: " + libname); |
|
874 |
} |
|
875 |
ClassLoader.loadLibrary(fromClass, libname, false); |
|
876 |
} |
|
877 |
||
878 |
/** |
|
879 |
* Creates a localized version of an input stream. This method takes |
|
30042 | 880 |
* an {@code InputStream} and returns an {@code InputStream} |
2 | 881 |
* equivalent to the argument in all respects except that it is |
882 |
* localized: as characters in the local character set are read from |
|
883 |
* the stream, they are automatically converted from the local |
|
884 |
* character set to Unicode. |
|
885 |
* <p> |
|
886 |
* If the argument is already a localized stream, it may be returned |
|
887 |
* as the result. |
|
888 |
* |
|
889 |
* @param in InputStream to localize |
|
890 |
* @return a localized input stream |
|
891 |
* @see java.io.InputStream |
|
892 |
* @see java.io.BufferedReader#BufferedReader(java.io.Reader) |
|
893 |
* @see java.io.InputStreamReader#InputStreamReader(java.io.InputStream) |
|
894 |
* @deprecated As of JDK 1.1, the preferred way to translate a byte |
|
895 |
* stream in the local encoding into a character stream in Unicode is via |
|
30042 | 896 |
* the {@code InputStreamReader} and {@code BufferedReader} |
2 | 897 |
* classes. |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
898 |
* This method is subject to removal in a future version of Java SE. |
2 | 899 |
*/ |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
900 |
@Deprecated(since="1.1", forRemoval=true) |
2 | 901 |
public InputStream getLocalizedInputStream(InputStream in) { |
902 |
return in; |
|
903 |
} |
|
904 |
||
905 |
/** |
|
906 |
* Creates a localized version of an output stream. This method |
|
30042 | 907 |
* takes an {@code OutputStream} and returns an |
908 |
* {@code OutputStream} equivalent to the argument in all respects |
|
2 | 909 |
* except that it is localized: as Unicode characters are written to |
910 |
* the stream, they are automatically converted to the local |
|
911 |
* character set. |
|
912 |
* <p> |
|
913 |
* If the argument is already a localized stream, it may be returned |
|
914 |
* as the result. |
|
915 |
* |
|
916 |
* @deprecated As of JDK 1.1, the preferred way to translate a |
|
917 |
* Unicode character stream into a byte stream in the local encoding is via |
|
30042 | 918 |
* the {@code OutputStreamWriter}, {@code BufferedWriter}, and |
919 |
* {@code PrintWriter} classes. |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
920 |
* This method is subject to removal in a future version of Java SE. |
2 | 921 |
* |
922 |
* @param out OutputStream to localize |
|
923 |
* @return a localized output stream |
|
924 |
* @see java.io.OutputStream |
|
925 |
* @see java.io.BufferedWriter#BufferedWriter(java.io.Writer) |
|
926 |
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream) |
|
927 |
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream) |
|
928 |
*/ |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
37363
diff
changeset
|
929 |
@Deprecated(since="1.1", forRemoval=true) |
2 | 930 |
public OutputStream getLocalizedOutputStream(OutputStream out) { |
931 |
return out; |
|
932 |
} |
|
933 |
||
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
934 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
935 |
* Returns the version of the Java Runtime Environment as a {@link |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
936 |
* Runtime.Version}. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
937 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
938 |
* @return the {@link Runtime.Version} of the Java Runtime Environment |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
939 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
940 |
* @since 9 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
941 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
942 |
public static Version version() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
943 |
if (version == null) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
944 |
version = Version.parse( |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
945 |
GetPropertyAction.privilegedGetProperty("java.runtime.version")); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
946 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
947 |
return version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
948 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
949 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
950 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
951 |
* A representation of a version string for an implemenation of the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
952 |
* Java SE Platform. A version string contains a version number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
953 |
* optionally followed by pre-release and build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
954 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
955 |
* <h2><a name="verNum">Version numbers</a></h2> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
956 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
957 |
* <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
958 |
* of elements separated by period characters (U+002E). An element is |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
959 |
* either zero, or a unsigned integer numeral without leading zeros. The |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
960 |
* final element in a version number must not be zero. The format is: |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
961 |
* </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
962 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
963 |
* <blockquote><pre> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
964 |
* ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
965 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
966 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
967 |
* <p> The sequence may be of arbitrary length but the first three |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
968 |
* elements are assigned specific meanings, as follows:</p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
969 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
970 |
* <blockquote><pre> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
971 |
* $MAJOR.$MINOR.$SECURITY |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
972 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
973 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
974 |
* <ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
975 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
976 |
* <li><p> <a name="major">{@code $MAJOR}</a> --- The major version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
977 |
* number, incremented for a major release that contains significant new |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
978 |
* features as specified in a new edition of the Java SE Platform |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
979 |
* Specification, <em>e.g.</em>, <a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
980 |
* href="https://jcp.org/en/jsr/detail?id=337">JSR 337</a> for |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
981 |
* Java SE 8. Features may be removed in a major release, given |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
982 |
* advance notice at least one major release ahead of time, and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
983 |
* incompatible changes may be made when justified. The {@code $MAJOR} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
984 |
* version number of JDK 8 is {@code 8}; the {@code $MAJOR} version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
985 |
* number of JDK 9 is {@code 9}. When {@code $MAJOR} is incremented, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
986 |
* all subsequent elements are removed. </p></li> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
987 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
988 |
* <li><p> <a name="minor">{@code $MINOR}</a> --- The minor version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
989 |
* number, incremented for a minor update release that may contain |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
990 |
* compatible bug fixes, revisions to standard APIs mandated by a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
991 |
* <a href="https://jcp.org/en/procedures/jcp2#5.3">Maintenance Release</a> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
992 |
* of the relevant Platform Specification, and implementation features |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
993 |
* outside the scope of that Specification such as new JDK-specific APIs, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
994 |
* additional service providers, new garbage collectors, and ports to new |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
995 |
* hardware architectures. </p></li> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
996 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
997 |
* <li><p> <a name="security">{@code $SECURITY}</a> --- The security |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
998 |
* level, incremented for a security update release that contains critical |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
999 |
* fixes including those necessary to improve security. {@code $SECURITY} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1000 |
* is <strong>not</strong> reset when {@code $MINOR} is incremented. A |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1001 |
* higher value of {@code $SECURITY} for a given {@code $MAJOR} value, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1002 |
* therefore, always indicates a more secure release, regardless of the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1003 |
* value of {@code $MINOR}. </p></li> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1004 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1005 |
* </ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1006 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1007 |
* <p> The fourth and later elements of a version number are free for use |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1008 |
* by downstream consumers of this code base. Such a consumer may, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1009 |
* <em>e.g.</em>, use the fourth element to identify patch releases which |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1010 |
* contain a small number of critical non-security fixes in addition to |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1011 |
* the security fixes in the corresponding security release. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1012 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1013 |
* <p> The version number does not include trailing zero elements; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1014 |
* <em>i.e.</em>, {@code $SECURITY} is omitted if it has the value zero, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1015 |
* and {@code $MINOR} is omitted if both {@code $MINOR} and {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1016 |
* $SECURITY} have the value zero. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1017 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1018 |
* <p> The sequence of numerals in a version number is compared to another |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1019 |
* such sequence in numerical, pointwise fashion; <em>e.g.</em>, {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1020 |
* 9.9.1} is less than {@code 9.10.3}. If one sequence is shorter than |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1021 |
* another then the missing elements of the shorter sequence are |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1022 |
* considered to be less than the corresponding elements of the longer |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1023 |
* sequence; <em>e.g.</em>, {@code 9.1.2} is less than {@code 9.1.2.1}. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1024 |
* </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1025 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1026 |
* <h2><a name="verStr">Version strings</a></h2> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1027 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1028 |
* <p> A <em>version string</em>, {@code $VSTR}, consists of a version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1029 |
* number {@code $VNUM}, as described above, optionally followed by |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1030 |
* pre-release and build information, in the format </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1031 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1032 |
* <blockquote><pre> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1033 |
* $VNUM(-$PRE)?(\+($BUILD)?(-$OPT)?)? |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1034 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1035 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1036 |
* <p> where: </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1037 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1038 |
* <ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1039 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1040 |
* <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1041 |
* --- A pre-release identifier. Typically {@code ea}, for a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1042 |
* potentially unstable early-access release under active development, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1043 |
* or {@code internal}, for an internal developer build. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1044 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1045 |
* <li><p> <a name="build">{@code $BUILD}</a>, matching {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1046 |
* (0|[1-9][0-9]*)} --- The build number, incremented for each promoted |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1047 |
* build. {@code $BUILD} is reset to {@code 1} when any portion of {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1048 |
* $VNUM} is incremented. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1049 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1050 |
* <li><p> <a name="opt">{@code $OPT}</a>, matching {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1051 |
* ([-a-zA-Z0-9\.]+)} --- Additional build information, if desired. In |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1052 |
* the case of an {@code internal} build this will often contain the date |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1053 |
* and time of the build. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1054 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1055 |
* </ul> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1056 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1057 |
* <p> A version number {@code 10-ea} matches {@code $VNUM = "10"} and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1058 |
* {@code $PRE = "ea"}. The version number {@code 10+-ea} matches |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1059 |
* {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1060 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1061 |
* <p> When comparing two version strings, the value of {@code $OPT}, if |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1062 |
* present, may or may not be significant depending on the chosen |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1063 |
* comparison method. The comparison methods {@link #compareTo(Version) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1064 |
* compareTo()} and {@link #compareToIgnoreOpt(Version) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1065 |
* compareToIgnoreOpt()} should be used consistently with the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1066 |
* corresponding methods {@link #equals(Object) equals()} and {@link |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1067 |
* #equalsIgnoreOpt(Object) equalsIgnoreOpt()}. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1068 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1069 |
* <p> A <em>short version string</em>, {@code $SVSTR}, often useful in |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1070 |
* less formal contexts, is a version number optionally followed by a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1071 |
* pre-release identifier: |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1072 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1073 |
* <blockquote><pre> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1074 |
* $VNUM(-$PRE)? |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1075 |
* </pre></blockquote> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1076 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1077 |
* @since 9 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1078 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1079 |
public static class Version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1080 |
implements Comparable<Version> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1081 |
{ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1082 |
private final List<Integer> version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1083 |
private final Optional<String> pre; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1084 |
private final Optional<Integer> build; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1085 |
private final Optional<String> optional; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1086 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1087 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1088 |
// $VNUM(-$PRE)?(\+($BUILD)?(\-$OPT)?)? |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1089 |
// RE limits the format of version strings |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1090 |
// ([1-9][0-9]*(?:(?:\.0)*\.[1-9][0-9]*)*)(?:-([a-zA-Z0-9]+))?(?:(\+)(0|[1-9][0-9]*)?)?(?:-([-a-zA-Z0-9.]+))? |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1091 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1092 |
private static final String VNUM |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1093 |
= "(?<VNUM>[1-9][0-9]*(?:(?:\\.0)*\\.[1-9][0-9]*)*)"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1094 |
private static final String VNUM_GROUP = "VNUM"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1095 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1096 |
private static final String PRE = "(?:-(?<PRE>[a-zA-Z0-9]+))?"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1097 |
private static final String PRE_GROUP = "PRE"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1098 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1099 |
private static final String BUILD |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1100 |
= "(?:(?<PLUS>\\+)(?<BUILD>0|[1-9][0-9]*)?)?"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1101 |
private static final String PLUS_GROUP = "PLUS"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1102 |
private static final String BUILD_GROUP = "BUILD"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1103 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1104 |
private static final String OPT = "(?:-(?<OPT>[-a-zA-Z0-9.]+))?"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1105 |
private static final String OPT_GROUP = "OPT"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1106 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1107 |
private static final String VSTR_FORMAT |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1108 |
= "^" + VNUM + PRE + BUILD + OPT + "$"; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1109 |
private static final Pattern VSTR_PATTERN = Pattern.compile(VSTR_FORMAT); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1110 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1111 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1112 |
* Constructs a valid <a href="verStr">version string</a> containing |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1113 |
* a <a href="#verNum">version number</a> followed by pre-release and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1114 |
* build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1115 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1116 |
* @param s |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1117 |
* A string to be interpreted as a version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1118 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1119 |
* @throws IllegalArgumentException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1120 |
* If the given string cannot be interpreted as a valid |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1121 |
* version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1122 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1123 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1124 |
* If {@code s} is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1125 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1126 |
* @throws NumberFormatException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1127 |
* If an element of the version number or the build number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1128 |
* cannot be represented as an {@link Integer} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1129 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1130 |
private Version(String s) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1131 |
if (s == null) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1132 |
throw new NullPointerException(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1133 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1134 |
Matcher m = VSTR_PATTERN.matcher(s); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1135 |
if (!m.matches()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1136 |
throw new IllegalArgumentException("Invalid version string: '" |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1137 |
+ s + "'"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1138 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1139 |
// $VNUM is a dot-separated list of integers of arbitrary length |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1140 |
List<Integer> list = new ArrayList<>(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1141 |
for (String i : m.group(VNUM_GROUP).split("\\.")) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1142 |
list.add(Integer.parseInt(i)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1143 |
version = Collections.unmodifiableList(list); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1144 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1145 |
pre = Optional.ofNullable(m.group(PRE_GROUP)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1146 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1147 |
String b = m.group(BUILD_GROUP); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1148 |
// $BUILD is an integer |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1149 |
build = (b == null) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1150 |
? Optional.<Integer>empty() |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1151 |
: Optional.ofNullable(Integer.parseInt(b)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1152 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1153 |
optional = Optional.ofNullable(m.group(OPT_GROUP)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1154 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1155 |
// empty '+' |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1156 |
if ((m.group(PLUS_GROUP) != null) && !build.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1157 |
if (optional.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1158 |
if (pre.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1159 |
throw new IllegalArgumentException("'+' found with" |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1160 |
+ " pre-release and optional components:'" + s |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1161 |
+ "'"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1162 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1163 |
throw new IllegalArgumentException("'+' found with neither" |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1164 |
+ " build or optional components: '" + s + "'"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1165 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1166 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1167 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1168 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1169 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1170 |
* Parses the given string as a valid |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1171 |
* <a href="#verStr">version string</a> containing a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1172 |
* <a href="#verNum">version number</a> followed by pre-release and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1173 |
* build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1174 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1175 |
* @param s |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1176 |
* A string to interpret as a version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1177 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1178 |
* @throws IllegalArgumentException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1179 |
* If the given string cannot be interpreted as a valid |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1180 |
* version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1181 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1182 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1183 |
* If the given string is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1184 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1185 |
* @throws NumberFormatException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1186 |
* If an element of the version number or the build number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1187 |
* cannot be represented as an {@link Integer} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1188 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1189 |
* @return The Version of the given string |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1190 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1191 |
public static Version parse(String s) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1192 |
return new Version(s); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1193 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1194 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1195 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1196 |
* Returns the <a href="#major">major</a> version number. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1197 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1198 |
* @return The major version number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1199 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1200 |
public int major() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1201 |
return version.get(0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1202 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1203 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1204 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1205 |
* Returns the <a href="#minor">minor</a> version number or zero if it |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1206 |
* was not set. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1207 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1208 |
* @return The minor version number or zero if it was not set |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1209 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1210 |
public int minor() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1211 |
return (version.size() > 1 ? version.get(1) : 0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1212 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1213 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1214 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1215 |
* Returns the <a href="#security">security</a> version number or zero |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1216 |
* if it was not set. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1217 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1218 |
* @return The security version number or zero if it was not set |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1219 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1220 |
public int security() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1221 |
return (version.size() > 2 ? version.get(2) : 0); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1222 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1223 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1224 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1225 |
* Returns an unmodifiable {@link java.util.List List} of the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1226 |
* integer numerals contained in the <a href="#verNum">version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1227 |
* number</a>. The {@code List} always contains at least one |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1228 |
* element corresponding to the <a href="#major">major version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1229 |
* number</a>. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1230 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1231 |
* @return An unmodifiable list of the integer numerals |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1232 |
* contained in the version number |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1233 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1234 |
public List<Integer> version() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1235 |
return version; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1236 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1237 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1238 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1239 |
* Returns the optional <a href="#pre">pre-release</a> information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1240 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1241 |
* @return The optional pre-release information as a String |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1242 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1243 |
public Optional<String> pre() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1244 |
return pre; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1245 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1246 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1247 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1248 |
* Returns the <a href="#build">build number</a>. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1249 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1250 |
* @return The optional build number. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1251 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1252 |
public Optional<Integer> build() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1253 |
return build; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1254 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1255 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1256 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1257 |
* Returns <a href="#opt">optional</a> additional identifying build |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1258 |
* information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1259 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1260 |
* @return Additional build information as a String |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1261 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1262 |
public Optional<String> optional() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1263 |
return optional; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1264 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1265 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1266 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1267 |
* Compares this version to another. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1268 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1269 |
* <p> Each of the components in the <a href="#verStr">version</a> is |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1270 |
* compared in the follow order of precedence: version numbers, |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1271 |
* pre-release identifiers, build numbers, optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1272 |
* </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1273 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1274 |
* <p> Comparison begins by examining the sequence of version numbers. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1275 |
* If one sequence is shorter than another, then the missing elements |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1276 |
* of the shorter sequence are considered to be less than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1277 |
* corresponding elements of the longer sequence. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1278 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1279 |
* <p> A version with a pre-release identifier is always considered to |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1280 |
* be less than a version without one. Pre-release identifiers are |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1281 |
* compared numerically when they consist only of digits, and |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1282 |
* lexicographically otherwise. Numeric identifiers are considered to |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1283 |
* be less than non-numeric identifiers. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1284 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1285 |
* <p> A version without a build number is always less than one with a |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1286 |
* build number; otherwise build numbers are compared numerically. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1287 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1288 |
* <p> The optional build information is compared lexicographically. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1289 |
* During this comparison, a version with optional build information is |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1290 |
* considered to be greater than a version without one. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1291 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1292 |
* <p> A version is not comparable to any other type of object. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1293 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1294 |
* @param ob |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1295 |
* The object to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1296 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1297 |
* @return A negative integer, zero, or a positive integer if this |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1298 |
* {@code Version} is less than, equal to, or greater than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1299 |
* given {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1300 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1301 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1302 |
* If the given object is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1303 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1304 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1305 |
public int compareTo(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1306 |
return compare(ob, false); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1307 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1308 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1309 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1310 |
* Compares this version to another disregarding optional build |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1311 |
* information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1312 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1313 |
* <p> Two versions are compared by examining the version string as |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1314 |
* described in {@link #compareTo(Version)} with the exception that the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1315 |
* optional build information is always ignored. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1316 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1317 |
* <p> A version is not comparable to any other type of object. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1318 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1319 |
* @param ob |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1320 |
* The object to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1321 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1322 |
* @return A negative integer, zero, or a positive integer if this |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1323 |
* {@code Version} is less than, equal to, or greater than the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1324 |
* given {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1325 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1326 |
* @throws NullPointerException |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1327 |
* If the given object is {@code null} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1328 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1329 |
public int compareToIgnoreOpt(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1330 |
return compare(ob, true); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1331 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1332 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1333 |
private int compare(Version ob, boolean ignoreOpt) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1334 |
if (ob == null) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1335 |
throw new NullPointerException("Invalid argument"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1336 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1337 |
int ret = compareVersion(ob); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1338 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1339 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1340 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1341 |
ret = comparePre(ob); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1342 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1343 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1344 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1345 |
ret = compareBuild(ob); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1346 |
if (ret != 0) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1347 |
return ret; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1348 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1349 |
if (!ignoreOpt) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1350 |
return compareOpt(ob); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1351 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1352 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1353 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1354 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1355 |
private int compareVersion(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1356 |
int size = version.size(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1357 |
int oSize = ob.version().size(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1358 |
int min = Math.min(size, oSize); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1359 |
for (int i = 0; i < min; i++) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1360 |
Integer val = version.get(i); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1361 |
Integer oVal = ob.version().get(i); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1362 |
if (val != oVal) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1363 |
return val - oVal; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1364 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1365 |
if (size != oSize) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1366 |
return size - oSize; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1367 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1368 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1369 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1370 |
private int comparePre(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1371 |
Optional<String> oPre = ob.pre(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1372 |
if (!pre.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1373 |
if (oPre.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1374 |
return 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1375 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1376 |
if (!oPre.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1377 |
return -1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1378 |
String val = pre.get(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1379 |
String oVal = oPre.get(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1380 |
if (val.matches("\\d+")) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1381 |
return (oVal.matches("\\d+") |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1382 |
? (new BigInteger(val)).compareTo(new BigInteger(oVal)) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1383 |
: -1); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1384 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1385 |
return (oVal.matches("\\d+") |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1386 |
? 1 |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1387 |
: val.compareTo(oVal)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1388 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1389 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1390 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1391 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1392 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1393 |
private int compareBuild(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1394 |
Optional<Integer> oBuild = ob.build(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1395 |
if (oBuild.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1396 |
return (build.isPresent() |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1397 |
? build.get().compareTo(oBuild.get()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1398 |
: 1); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1399 |
} else if (build.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1400 |
return -1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1401 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1402 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1403 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1404 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1405 |
private int compareOpt(Version ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1406 |
Optional<String> oOpt = ob.optional(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1407 |
if (!optional.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1408 |
if (oOpt.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1409 |
return -1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1410 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1411 |
if (!oOpt.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1412 |
return 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1413 |
return optional.get().compareTo(oOpt.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1414 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1415 |
return 0; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1416 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1417 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1418 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1419 |
* Returns a string representation of this version. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1420 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1421 |
* @return The version string |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1422 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1423 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1424 |
public String toString() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1425 |
StringBuilder sb |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1426 |
= new StringBuilder(version.stream() |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1427 |
.map(Object::toString) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1428 |
.collect(Collectors.joining("."))); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1429 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1430 |
pre.ifPresent(v -> sb.append("-").append(v)); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1431 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1432 |
if (build.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1433 |
sb.append("+").append(build.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1434 |
if (optional.isPresent()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1435 |
sb.append("-").append(optional.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1436 |
} else { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1437 |
if (optional.isPresent()) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1438 |
sb.append(pre.isPresent() ? "-" : "+-"); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1439 |
sb.append(optional.get()); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1440 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1441 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1442 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1443 |
return sb.toString(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1444 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1445 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1446 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1447 |
* Determines whether this {@code Version} is equal to another object. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1448 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1449 |
* <p> Two {@code Version}s are equal if and only if they represent the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1450 |
* same version string. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1451 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1452 |
* <p> This method satisfies the general contract of the {@link |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1453 |
* Object#equals(Object) Object.equals} method. </p> |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1454 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1455 |
* @param ob |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1456 |
* The object to which this {@code Version} is to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1457 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1458 |
* @return {@code true} if, and only if, the given object is a {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1459 |
* Version} that is identical to this {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1460 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1461 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1462 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1463 |
public boolean equals(Object ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1464 |
boolean ret = equalsIgnoreOpt(ob); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1465 |
if (!ret) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1466 |
return false; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1467 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1468 |
Version that = (Version)ob; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1469 |
return (this.optional().equals(that.optional())); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1470 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1471 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1472 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1473 |
* Determines whether this {@code Version} is equal to another |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1474 |
* disregarding optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1475 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1476 |
* <p> Two {@code Version}s are equal if and only if they represent the |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1477 |
* same version string disregarding the optional build information. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1478 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1479 |
* @param ob |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1480 |
* The object to which this {@code Version} is to be compared |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1481 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1482 |
* @return {@code true} if, and only if, the given object is a {@code |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1483 |
* Version} that is identical to this {@code Version} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1484 |
* ignoring the optinal build information |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1485 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1486 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1487 |
public boolean equalsIgnoreOpt(Object ob) { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1488 |
if (this == ob) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1489 |
return true; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1490 |
if (!(ob instanceof Version)) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1491 |
return false; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1492 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1493 |
Version that = (Version)ob; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1494 |
return (this.version().equals(that.version()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1495 |
&& this.pre().equals(that.pre()) |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1496 |
&& this.build().equals(that.build())); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1497 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1498 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1499 |
/** |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1500 |
* Returns the hash code of this version. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1501 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1502 |
* <p> This method satisfies the general contract of the {@link |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1503 |
* Object#hashCode Object.hashCode} method. |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1504 |
* |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1505 |
* @return The hashcode of this version |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1506 |
*/ |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1507 |
@Override |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1508 |
public int hashCode() { |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1509 |
int h = 1; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1510 |
int p = 17; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1511 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1512 |
h = p * h + version.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1513 |
h = p * h + pre.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1514 |
h = p * h + build.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1515 |
h = p * h + optional.hashCode(); |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1516 |
|
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1517 |
return h; |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1518 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1519 |
} |
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37606
diff
changeset
|
1520 |
|
2 | 1521 |
} |