< prev index next >

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

Print this page




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




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 >