MCPcopy Create free account
hub / github.com/crate/crate / fromStringSlow

Method fromStringSlow

server/src/main/java/org/elasticsearch/Version.java:395–440  ·  view source on GitHub ↗
(String version)

Source from the content-addressed store, hash-verified

393 }
394
395 private static Version fromStringSlow(String version) {
396 final boolean snapshot; // this is some BWC for 2.x and before indices
397 if (snapshot = version.endsWith("-SNAPSHOT")) {
398 version = version.substring(0, version.length() - 9);
399 }
400 String[] parts = version.split("[.-]");
401 if (parts.length < 3 || parts.length > 4) {
402 throw new IllegalArgumentException(
403 "the version needs to contain major, minor, and revision, and optionally the build: " + version);
404 }
405
406 try {
407 final int rawMajor = Integer.parseInt(parts[0]);
408 if (rawMajor >= 2 && snapshot) { // we don't support snapshot as part of the version here anymore
409 throw new IllegalArgumentException("illegal version format - snapshots are only supported until version 2.x");
410 }
411 final int betaOffset = rawMajor < 2 ? 0 : 25;
412 //we reverse the version id calculation based on some assumption as we can't reliably reverse the modulo
413 final int major = rawMajor * 1000000;
414 final int minor = Integer.parseInt(parts[1]) * 10000;
415 final int revision = Integer.parseInt(parts[2]) * 100;
416
417
418 int build = 99;
419 if (parts.length == 4) {
420 String buildStr = parts[3];
421 if (buildStr.startsWith("alpha")) {
422 assert rawMajor >= 5 : "major must be >= 5 but was " + major;
423 build = Integer.parseInt(buildStr.substring(5));
424 assert build < 25 : "expected a beta build but " + build + " >= 25";
425 } else if (buildStr.startsWith("Beta") || buildStr.startsWith("beta")) {
426 build = betaOffset + Integer.parseInt(buildStr.substring(4));
427 assert build < 50 : "expected a beta build but " + build + " >= 50";
428 } else if (buildStr.startsWith("RC") || buildStr.startsWith("rc")) {
429 build = Integer.parseInt(buildStr.substring(2)) + 50;
430 } else {
431 throw new IllegalArgumentException("unable to parse version " + version);
432 }
433 }
434
435 return fromId(major + minor + revision + build + INTERNAL_OFFSET);
436
437 } catch (NumberFormatException e) {
438 throw new IllegalArgumentException("unable to parse version " + version, e);
439 }
440 }
441
442 private final boolean isSnapshot;
443 public final int externalId;

Callers 1

fromStringMethod · 0.95

Calls 6

fromIdMethod · 0.95
substringMethod · 0.80
parseIntMethod · 0.80
startsWithMethod · 0.80
lengthMethod · 0.65
splitMethod · 0.45

Tested by

no test coverage detected