< prev index next >

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

Print this page


   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


1082             // $VNUM is a dot-separated list of integers of arbitrary length
1083             String[] split = m.group(VersionPattern.VNUM_GROUP).split("\\.");
1084             Integer[] version = new Integer[split.length];
1085             for (int i = 0; i < split.length; i++) {
1086                 version[i] = Integer.parseInt(split[i]);
1087             }
1088 
1089             Optional<String> pre = Optional.ofNullable(
1090                     m.group(VersionPattern.PRE_GROUP));
1091 
1092             String b = m.group(VersionPattern.BUILD_GROUP);
1093             // $BUILD is an integer
1094             Optional<Integer> build = (b == null)
1095                 ? Optional.empty()
1096                 : Optional.of(Integer.parseInt(b));
1097 
1098             Optional<String> optional = Optional.ofNullable(
1099                     m.group(VersionPattern.OPT_GROUP));
1100 
1101             // empty '+'
1102             if ((m.group(VersionPattern.PLUS_GROUP) != null)
1103                     && !build.isPresent()) {
1104                 if (optional.isPresent()) {
1105                     if (pre.isPresent())
1106                         throw new IllegalArgumentException("'+' found with"
1107                             + " pre-release and optional components:'" + s
1108                             + "'");
1109                 } else {
1110                     throw new IllegalArgumentException("'+' found with neither"
1111                         + " build or optional components: '" + s + "'");
1112                 }







1113             }
1114             return new Version(List.of(version), pre, build, optional);
1115         }
1116 
1117         private static boolean isSimpleNumber(String s) {
1118             for (int i = 0; i < s.length(); i++) {
1119                 char c = s.charAt(i);
1120                 char lowerBound = (i > 0) ? '0' : '1';
1121                 if (c < lowerBound || c > '9') {
1122                     return false;
1123                 }
1124             }
1125             return true;
1126         }
1127 
1128         /**
1129          * Returns the value of the <a href="#FEATURE">feature</a> element of
1130          * the version number.
1131          *
1132          * @return The value of the feature element


   1 /*
   2  * Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  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


1082             // $VNUM is a dot-separated list of integers of arbitrary length
1083             String[] split = m.group(VersionPattern.VNUM_GROUP).split("\\.");
1084             Integer[] version = new Integer[split.length];
1085             for (int i = 0; i < split.length; i++) {
1086                 version[i] = Integer.parseInt(split[i]);
1087             }
1088 
1089             Optional<String> pre = Optional.ofNullable(
1090                     m.group(VersionPattern.PRE_GROUP));
1091 
1092             String b = m.group(VersionPattern.BUILD_GROUP);
1093             // $BUILD is an integer
1094             Optional<Integer> build = (b == null)
1095                 ? Optional.empty()
1096                 : Optional.of(Integer.parseInt(b));
1097 
1098             Optional<String> optional = Optional.ofNullable(
1099                     m.group(VersionPattern.OPT_GROUP));
1100 
1101             // empty '+'
1102             if (!build.isPresent()) {
1103                 if (m.group(VersionPattern.PLUS_GROUP) != null) {
1104                     if (optional.isPresent()) {
1105                         if (pre.isPresent())
1106                             throw new IllegalArgumentException("'+' found with"
1107                                 + " pre-release and optional components:'" + s
1108                                 + "'");
1109                     } else {
1110                         throw new IllegalArgumentException("'+' found with neither"
1111                             + " build or optional components: '" + s + "'");
1112                     }
1113                 } else {
1114                     if (optional.isPresent() && !pre.isPresent()) {
1115                         throw new IllegalArgumentException("optional component"
1116                             + " must be preceeded by a pre-release component"
1117                             + " or '+': '" + s + "'");
1118                     }
1119                 }
1120             }
1121             return new Version(List.of(version), pre, build, optional);
1122         }
1123 
1124         private static boolean isSimpleNumber(String s) {
1125             for (int i = 0; i < s.length(); i++) {
1126                 char c = s.charAt(i);
1127                 char lowerBound = (i > 0) ? '0' : '1';
1128                 if (c < lowerBound || c > '9') {
1129                     return false;
1130                 }
1131             }
1132             return true;
1133         }
1134 
1135         /**
1136          * Returns the value of the <a href="#FEATURE">feature</a> element of
1137          * the version number.
1138          *
1139          * @return The value of the feature element


< prev index next >