< prev index next >

src/java.base/share/classes/java/lang/Runtime.java

Print this page


   1 /*
   2  * Copyright (c) 1995, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 938      * @since  9
 939      */
 940     public static Version version() {
 941         if (version == null) {
 942             version = new Version(VersionProps.versionNumbers(),
 943                     VersionProps.pre(), VersionProps.build(),
 944                     VersionProps.optional());
 945         }
 946         return version;
 947     }
 948 
 949     /**
 950      * A representation of a version string for an implementation of the
 951      * Java&nbsp;SE Platform.  A version string contains a version number
 952      * optionally followed by pre-release and build information.
 953      *
 954      * <h2><a name="verNum">Version numbers</a></h2>
 955      *
 956      * <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence
 957      * of elements separated by period characters (U+002E).  An element is
 958      * either zero, or a unsigned integer numeral without leading zeros.  The
 959      * final element in a version number must not be zero.  The format is:
 960      * </p>
 961      *
 962      * <blockquote><pre>
 963      *     ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$
 964      * </pre></blockquote>
 965      *
 966      * <p> The sequence may be of arbitrary length but the first three
 967      * elements are assigned specific meanings, as follows:</p>
 968      *
 969      * <blockquote><pre>
 970      *     $MAJOR.$MINOR.$SECURITY
 971      * </pre></blockquote>
 972      *
 973      * <ul>
 974      *
 975      * <li><p> <a name="major">{@code $MAJOR}</a> --- The major version
 976      * number, incremented for a major release that contains significant new
 977      * features as specified in a new edition of the Java SE Platform
 978      * Specification, <em>e.g.</em>, <a


1036      *
1037      * <ul>
1038      *
1039      * <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)}
1040      * --- A pre-release identifier.  Typically {@code ea}, for a
1041      * potentially unstable early-access release under active development,
1042      * or {@code internal}, for an internal developer build.
1043      *
1044      * <li><p> <a name="build">{@code $BUILD}</a>, matching {@code
1045      * (0|[1-9][0-9]*)} --- The build number, incremented for each promoted
1046      * build.  {@code $BUILD} is reset to {@code 1} when any portion of {@code
1047      * $VNUM} is incremented. </p>
1048      *
1049      * <li><p> <a name="opt">{@code $OPT}</a>, matching {@code
1050      * ([-a-zA-Z0-9\.]+)} --- Additional build information, if desired.  In
1051      * the case of an {@code internal} build this will often contain the date
1052      * and time of the build. </p>
1053      *
1054      * </ul>
1055      *
1056      * <p> A version number {@code 10-ea} matches {@code $VNUM = "10"} and
1057      * {@code $PRE = "ea"}.  The version number {@code 10+-ea} matches
1058      * {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p>
1059      *
1060      * <p> When comparing two version strings, the value of {@code $OPT}, if
1061      * present, may or may not be significant depending on the chosen
1062      * comparison method.  The comparison methods {@link #compareTo(Version)
1063      * compareTo()} and {@link #compareToIgnoreOptional(Version)
1064      * compareToIgnoreOptional()} should be used consistently with the
1065      * corresponding methods {@link #equals(Object) equals()} and {@link
1066      * #equalsIgnoreOptional(Object) equalsIgnoreOptional()}.  </p>
1067      *
1068      * <p> A <em>short version string</em>, {@code $SVSTR}, often useful in
1069      * less formal contexts, is a version number optionally followed by a
1070      * pre-release identifier:
1071      *
1072      * <blockquote><pre>
1073      *     $VNUM(-$PRE)?
1074      * </pre></blockquote>
1075      *
1076      * @since  9
1077      */


1230          * @return  The optional build number.
1231          */
1232         public Optional<Integer> build() {
1233             return build;
1234         }
1235 
1236         /**
1237          * Returns <a href="#opt">optional</a> additional identifying build
1238          * information.
1239          *
1240          * @return  Additional build information as a String
1241          */
1242         public Optional<String> optional() {
1243             return optional;
1244         }
1245 
1246         /**
1247          * Compares this version to another.
1248          *
1249          * <p> Each of the components in the <a href="#verStr">version</a> is
1250          * compared in the follow order of precedence: version numbers,
1251          * pre-release identifiers, build numbers, optional build information.
1252          * </p>
1253          *
1254          * <p> Comparison begins by examining the sequence of version numbers.
1255          * If one sequence is shorter than another, then the missing elements
1256          * of the shorter sequence are considered to be less than the
1257          * corresponding elements of the longer sequence. </p>
1258          *
1259          * <p> A version with a pre-release identifier is always considered to
1260          * be less than a version without one.  Pre-release identifiers are
1261          * compared numerically when they consist only of digits, and
1262          * lexicographically otherwise.  Numeric identifiers are considered to
1263          * be less than non-numeric identifiers.  </p>
1264          *
1265          * <p> A version without a build number is always less than one with a
1266          * build number; otherwise build numbers are compared numerically. </p>
1267          *
1268          * <p> The optional build information is compared lexicographically.
1269          * During this comparison, a version with optional build information is
1270          * considered to be greater than a version without one. </p>


1358                 String val = pre.get();
1359                 String oVal = oPre.get();
1360                 if (val.matches("\\d+")) {
1361                     return (oVal.matches("\\d+")
1362                         ? (new BigInteger(val)).compareTo(new BigInteger(oVal))
1363                         : -1);
1364                 } else {
1365                     return (oVal.matches("\\d+")
1366                         ? 1
1367                         : val.compareTo(oVal));
1368                 }
1369             }
1370             return 0;
1371         }
1372 
1373         private int compareBuild(Version ob) {
1374             Optional<Integer> oBuild = ob.build();
1375             if (oBuild.isPresent()) {
1376                 return (build.isPresent()
1377                         ? build.get().compareTo(oBuild.get())
1378                         : 1);
1379             } else if (build.isPresent()) {
1380                 return -1;
1381             }
1382             return 0;
1383         }
1384 
1385         private int compareOptional(Version ob) {
1386             Optional<String> oOpt = ob.optional();
1387             if (!optional.isPresent()) {
1388                 if (oOpt.isPresent())
1389                     return -1;
1390             } else {
1391                 if (!oOpt.isPresent())
1392                     return 1;
1393                 return optional.get().compareTo(oOpt.get());
1394             }
1395             return 0;
1396         }
1397 
1398         /**
1399          * Returns a string representation of this version.
1400          *


1444             boolean ret = equalsIgnoreOptional(ob);
1445             if (!ret)
1446                 return false;
1447 
1448             Version that = (Version)ob;
1449             return (this.optional().equals(that.optional()));
1450         }
1451 
1452         /**
1453          * Determines whether this {@code Version} is equal to another
1454          * disregarding optional build information.
1455          *
1456          * <p> Two {@code Version}s are equal if and only if they represent the
1457          * same version string disregarding the optional build information.
1458          *
1459          * @param  ob
1460          *         The object to which this {@code Version} is to be compared
1461          *
1462          * @return  {@code true} if, and only if, the given object is a {@code
1463          *          Version} that is identical to this {@code Version}
1464          *          ignoring the optinal build information
1465          *
1466          */
1467         public boolean equalsIgnoreOptional(Object ob) {
1468             if (this == ob)
1469                 return true;
1470             if (!(ob instanceof Version))
1471                 return false;
1472 
1473             Version that = (Version)ob;
1474             return (this.version().equals(that.version())
1475                 && this.pre().equals(that.pre())
1476                 && this.build().equals(that.build()));
1477         }
1478 
1479         /**
1480          * Returns the hash code of this version.
1481          *
1482          * <p> This method satisfies the general contract of the {@link
1483          * Object#hashCode Object.hashCode} method.
1484          *


   1 /*
   2  * Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  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  *
  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


 938      * @since  9
 939      */
 940     public static Version version() {
 941         if (version == null) {
 942             version = new Version(VersionProps.versionNumbers(),
 943                     VersionProps.pre(), VersionProps.build(),
 944                     VersionProps.optional());
 945         }
 946         return version;
 947     }
 948 
 949     /**
 950      * A representation of a version string for an implementation of the
 951      * Java&nbsp;SE Platform.  A version string contains a version number
 952      * optionally followed by pre-release and build information.
 953      *
 954      * <h2><a name="verNum">Version numbers</a></h2>
 955      *
 956      * <p> A <em>version number</em>, {@code $VNUM}, is a non-empty sequence
 957      * of elements separated by period characters (U+002E).  An element is
 958      * either zero, or an unsigned integer numeral without leading zeros.  The
 959      * final element in a version number must not be zero.  The format is:
 960      * </p>
 961      *
 962      * <blockquote><pre>
 963      *     ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$
 964      * </pre></blockquote>
 965      *
 966      * <p> The sequence may be of arbitrary length but the first three
 967      * elements are assigned specific meanings, as follows:</p>
 968      *
 969      * <blockquote><pre>
 970      *     $MAJOR.$MINOR.$SECURITY
 971      * </pre></blockquote>
 972      *
 973      * <ul>
 974      *
 975      * <li><p> <a name="major">{@code $MAJOR}</a> --- The major version
 976      * number, incremented for a major release that contains significant new
 977      * features as specified in a new edition of the Java SE Platform
 978      * Specification, <em>e.g.</em>, <a


1036      *
1037      * <ul>
1038      *
1039      * <li><p> <a name="pre">{@code $PRE}</a>, matching {@code ([a-zA-Z0-9]+)}
1040      * --- A pre-release identifier.  Typically {@code ea}, for a
1041      * potentially unstable early-access release under active development,
1042      * or {@code internal}, for an internal developer build.
1043      *
1044      * <li><p> <a name="build">{@code $BUILD}</a>, matching {@code
1045      * (0|[1-9][0-9]*)} --- The build number, incremented for each promoted
1046      * build.  {@code $BUILD} is reset to {@code 1} when any portion of {@code
1047      * $VNUM} is incremented. </p>
1048      *
1049      * <li><p> <a name="opt">{@code $OPT}</a>, matching {@code
1050      * ([-a-zA-Z0-9\.]+)} --- Additional build information, if desired.  In
1051      * the case of an {@code internal} build this will often contain the date
1052      * and time of the build. </p>
1053      *
1054      * </ul>
1055      *
1056      * <p> A version string {@code 10-ea} matches {@code $VNUM = "10"} and
1057      * {@code $PRE = "ea"}.  The version string {@code 10+-ea} matches
1058      * {@code $VNUM = "10"} and {@code $OPT = "ea"}. </p>
1059      *
1060      * <p> When comparing two version strings, the value of {@code $OPT}, if
1061      * present, may or may not be significant depending on the chosen
1062      * comparison method.  The comparison methods {@link #compareTo(Version)
1063      * compareTo()} and {@link #compareToIgnoreOptional(Version)
1064      * compareToIgnoreOptional()} should be used consistently with the
1065      * corresponding methods {@link #equals(Object) equals()} and {@link
1066      * #equalsIgnoreOptional(Object) equalsIgnoreOptional()}.  </p>
1067      *
1068      * <p> A <em>short version string</em>, {@code $SVSTR}, often useful in
1069      * less formal contexts, is a version number optionally followed by a
1070      * pre-release identifier:
1071      *
1072      * <blockquote><pre>
1073      *     $VNUM(-$PRE)?
1074      * </pre></blockquote>
1075      *
1076      * @since  9
1077      */


1230          * @return  The optional build number.
1231          */
1232         public Optional<Integer> build() {
1233             return build;
1234         }
1235 
1236         /**
1237          * Returns <a href="#opt">optional</a> additional identifying build
1238          * information.
1239          *
1240          * @return  Additional build information as a String
1241          */
1242         public Optional<String> optional() {
1243             return optional;
1244         }
1245 
1246         /**
1247          * Compares this version to another.
1248          *
1249          * <p> Each of the components in the <a href="#verStr">version</a> is
1250          * compared in the following order of precedence: version numbers,
1251          * pre-release identifiers, build numbers, optional build information.
1252          * </p>
1253          *
1254          * <p> Comparison begins by examining the sequence of version numbers.
1255          * If one sequence is shorter than another, then the missing elements
1256          * of the shorter sequence are considered to be less than the
1257          * corresponding elements of the longer sequence. </p>
1258          *
1259          * <p> A version with a pre-release identifier is always considered to
1260          * be less than a version without one.  Pre-release identifiers are
1261          * compared numerically when they consist only of digits, and
1262          * lexicographically otherwise.  Numeric identifiers are considered to
1263          * be less than non-numeric identifiers.  </p>
1264          *
1265          * <p> A version without a build number is always less than one with a
1266          * build number; otherwise build numbers are compared numerically. </p>
1267          *
1268          * <p> The optional build information is compared lexicographically.
1269          * During this comparison, a version with optional build information is
1270          * considered to be greater than a version without one. </p>


1358                 String val = pre.get();
1359                 String oVal = oPre.get();
1360                 if (val.matches("\\d+")) {
1361                     return (oVal.matches("\\d+")
1362                         ? (new BigInteger(val)).compareTo(new BigInteger(oVal))
1363                         : -1);
1364                 } else {
1365                     return (oVal.matches("\\d+")
1366                         ? 1
1367                         : val.compareTo(oVal));
1368                 }
1369             }
1370             return 0;
1371         }
1372 
1373         private int compareBuild(Version ob) {
1374             Optional<Integer> oBuild = ob.build();
1375             if (oBuild.isPresent()) {
1376                 return (build.isPresent()
1377                         ? build.get().compareTo(oBuild.get())
1378                         : -1);
1379             } else if (build.isPresent()) {
1380                 return 1;
1381             }
1382             return 0;
1383         }
1384 
1385         private int compareOptional(Version ob) {
1386             Optional<String> oOpt = ob.optional();
1387             if (!optional.isPresent()) {
1388                 if (oOpt.isPresent())
1389                     return -1;
1390             } else {
1391                 if (!oOpt.isPresent())
1392                     return 1;
1393                 return optional.get().compareTo(oOpt.get());
1394             }
1395             return 0;
1396         }
1397 
1398         /**
1399          * Returns a string representation of this version.
1400          *


1444             boolean ret = equalsIgnoreOptional(ob);
1445             if (!ret)
1446                 return false;
1447 
1448             Version that = (Version)ob;
1449             return (this.optional().equals(that.optional()));
1450         }
1451 
1452         /**
1453          * Determines whether this {@code Version} is equal to another
1454          * disregarding optional build information.
1455          *
1456          * <p> Two {@code Version}s are equal if and only if they represent the
1457          * same version string disregarding the optional build information.
1458          *
1459          * @param  ob
1460          *         The object to which this {@code Version} is to be compared
1461          *
1462          * @return  {@code true} if, and only if, the given object is a {@code
1463          *          Version} that is identical to this {@code Version}
1464          *          ignoring the optional build information
1465          *
1466          */
1467         public boolean equalsIgnoreOptional(Object ob) {
1468             if (this == ob)
1469                 return true;
1470             if (!(ob instanceof Version))
1471                 return false;
1472 
1473             Version that = (Version)ob;
1474             return (this.version().equals(that.version())
1475                 && this.pre().equals(that.pre())
1476                 && this.build().equals(that.build()));
1477         }
1478 
1479         /**
1480          * Returns the hash code of this version.
1481          *
1482          * <p> This method satisfies the general contract of the {@link
1483          * Object#hashCode Object.hashCode} method.
1484          *


< prev index next >