001package org.hl7.fhir.utilities; 002 003import java.util.Comparator; 004import java.util.HashSet; 005import java.util.List; 006import java.util.Set; 007import java.util.StringJoiner; 008 009import org.apache.commons.lang3.StringUtils; 010import org.hl7.fhir.exceptions.FHIRException; 011import org.hl7.fhir.utilities.VersionUtilities.SemVer; 012 013/* 014 Copyright (c) 2011+, HL7, Inc. 015 All rights reserved. 016 017 Redistribution and use in source and binary forms, with or without modification, 018 are permitted provided that the following conditions are met: 019 020 * Redistributions of source code must retain the above copyright notice, this 021 list of conditions and the following disclaimer. 022 * Redistributions in binary form must reproduce the above copyright notice, 023 this list of conditions and the following disclaimer in the documentation 024 and/or other materials provided with the distribution. 025 * Neither the name of HL7 nor the names of its contributors may be used to 026 endorse or promote products derived from this software without specific 027 prior written permission. 028 029 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 030 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 031 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 032 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 033 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 034 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 035 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 036 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 037 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 038 POSSIBILITY OF SUCH DAMAGE. 039 040 */ 041 042 043public class VersionUtilities { 044 045 046 public static class SemVerSorter implements Comparator<String> { 047 048 @Override 049 public int compare(String s1, String s2) { 050 return compareVersions(s1, s2); 051 } 052 053 } 054 055 public static class SemVer { 056 private String major; 057 private String minor; 058 private String patch; 059 private String label; 060 061 public SemVer(String ver) { 062 String[] p = ver.split("\\."); 063 if (p.length > 0) { 064 major = p[0]; 065 } 066 if (p.length > 1) { 067 minor = p[1]; 068 } 069 if (p.length > 2) { 070 patch = p[2]; 071 if (patch.contains("-")) { 072 label = patch.substring(patch.indexOf("-")+1); 073 patch = patch.substring(0, patch.indexOf("-")); 074 } 075 } 076 } 077 078 private int compareString(String s1, String s2) { 079 if (s1 == null) { 080 return s2 == null ? 0 : 1; 081 } else if (s2 == null) { 082 return -1; 083 } else { 084 return s1.compareTo(s2); 085 } 086 } 087 088 089 private int compareInteger(String s1, String s2) { 090 if (s1 == null) { 091 return s2 == null ? 0 : 1; 092 } else if (s2 == null) { 093 return -1; 094 } else { 095 return Integer.compare(Integer.parseInt(s1), Integer.parseInt(s2)); 096 } 097 } 098 099 public int compareTo(SemVer sv2) { 100 int c = compareInteger(major, sv2.major); 101 if (c == 0) { 102 c = compareInteger(minor, sv2.minor); 103 } 104 if (c == 0) { 105 c = compareInteger(patch, sv2.patch); 106 } 107 if (c == 0) { 108 c = compareString(label, sv2.label); 109 } 110 return c; 111 } 112 113 } 114 115 public static final String[] SUPPORTED_MAJOR_VERSIONS = {"1.0", "1.4", "3.0", "4.0", "5.0", "6.0"}; 116 public static final String[] SUPPORTED_VERSIONS = {"1.0.2", "1.4.0", "3.0.2", "4.0.1", "4.1.0", "4.3.0", "5.0.0", "6.0.0"}; 117 118 public static class VersionURLInfo { 119 private String version; 120 private String url; 121 public VersionURLInfo(String version, String url) { 122 super(); 123 this.version = version; 124 this.url = url; 125 } 126 public String getVersion() { 127 return version; 128 } 129 public String getUrl() { 130 return url; 131 } 132 } 133 134 public static String packageForVersion(String v) { 135 if (isR2Ver(v)) { 136 return "hl7.fhir.r2.core"; 137 } 138 if (isR2BVer(v)) { 139 return "hl7.fhir.r2b.core"; 140 } 141 if (isR3Ver(v)) { 142 return "hl7.fhir.r3.core"; 143 } 144 if (isR4Ver(v)) { 145 return "hl7.fhir.r4.core"; 146 } 147 148 if (isR4BVer(v)) { 149 return "hl7.fhir.r4b.core"; 150 } 151 152 if (isR5Ver(v)) { 153 return "hl7.fhir.r5.core"; 154 } 155 156 if (isR6Ver(v)) { 157 return "hl7.fhir.r6.core"; 158 } 159 160 if ("current".equals(v)) { 161 return "hl7.fhir.r5.core"; 162 } 163 164 return null; 165 } 166 167 public static String getCurrentVersion(String v) { 168 if (isR2Ver(v)) { 169 return "1.0.2"; 170 } 171 if (isR2BVer(v)) { 172 return "1.4.0"; 173 } 174 if (isR3Ver(v)) { 175 return "3.0.2"; 176 } 177 if (isR4Ver(v)) { 178 return "4.0.1"; 179 } 180 if (isR5Ver(v)) { 181 return "5.0.0"; 182 } 183 if (isR6Ver(v)) { 184 return "6.0.0"; 185 } 186 return v; 187 } 188 189 public static String getCurrentPackageVersion(String v) { 190 if (isR2Ver(v)) { 191 return "1.0"; 192 } 193 if (isR2BVer(v)) { 194 return "1.4"; 195 } 196 if (isR3Ver(v)) { 197 return "3.0"; 198 } 199 if (isR4Ver(v)) { 200 return "4.0"; 201 } 202 if (isR5Ver(v)) { 203 return "5.0"; 204 } 205 if (isR6Ver(v)) { 206 return "6.0"; 207 } 208 return v; 209 } 210 211 public static boolean isSupportedVersion(String version) { 212 if (version.contains("-")) { 213 version = version.substring(0, version.indexOf("-")); 214 } 215 return Utilities.existsInList(version, SUPPORTED_VERSIONS); 216 } 217 218 public static String listSupportedVersions() { 219 return listVersions(SUPPORTED_VERSIONS); 220 } 221 222 public static String listSupportedMajorVersions() { 223 return listVersions(SUPPORTED_MAJOR_VERSIONS); 224 } 225 226 private static String listVersions(String[] versions) { 227 StringJoiner stringJoiner = new StringJoiner(", "); 228 for (String supportedVersion : versions) { 229 stringJoiner.add(supportedVersion); 230 } 231 return stringJoiner.toString(); 232 } 233 234 public static boolean isR6Ver(String ver) { 235 return ver != null && (ver.startsWith("6.0")); 236 } 237 238 public static boolean isR5Ver(String ver) { 239 return ver != null && (ver.startsWith("5.0")); 240 } 241 242 public static boolean isR4BVer(String ver) { 243 return ver != null && (ver.startsWith("4.1") || ver.startsWith("4.3")); 244 } 245 246 public static boolean isR4Ver(String ver) { 247 return ver != null && ver.startsWith("4.0"); 248 } 249 250 public static boolean isR3Ver(String ver) { 251 return ver != null && ver.startsWith("3.0"); 252 } 253 254 public static boolean isR2BVer(String ver) { 255 return ver != null && ver.startsWith("1.4"); 256 } 257 258 public static boolean isR2Ver(String ver) { 259 return ver != null && ver.startsWith("1.0"); 260 } 261 262 public static boolean versionsCompatible(String v1, String v2) { 263 if (v1 == null || v2 == null) { 264 return false; 265 } 266 String[] v1l = v1.split("\\|"); 267 String[] v2l = v2.split("\\|"); 268 for (String vs1 : v1l) { 269 for (String vs2 : v2l) { 270 String mm1 = getMajMin(vs1); 271 String mm2 = getMajMin(vs2); 272 if (mm1 == null || mm2 == null) { 273 return false; 274 } else { 275 if (mm1.equals(mm2)) { 276 return true; 277 } 278 } 279 } 280 } 281 return false; 282 } 283 284 public static boolean isCorePackage(String s) { 285 if (s.contains("#")) { 286 s = s.substring(0, s.indexOf("#")); 287 } 288 return Utilities.existsInList(s, "hl7.fhir.core","hl7.fhir.r2.core", "hl7.fhir.r2b.core", "hl7.fhir.r3.core", "hl7.fhir.r4.core", "hl7.fhir.r4b.core", "hl7.fhir.r5.core", "hl7.fhir.r6.core"); 289 } 290 291 public static String getMajMin(String version) { 292 if (version == null) { 293 return null; 294 } 295 if (version.startsWith("http://hl7.org/fhir/")) { 296 version = version.substring(20); 297 if (version.contains("/")) { 298 version = version.substring(0, version.indexOf("/")); 299 } 300 } 301 302 if (Utilities.charCount(version, '.') == 1) { 303 String[] p = version.split("\\."); 304 return p[0]+"."+p[1]; 305 } else if (Utilities.charCount(version, '.') == 2) { 306 String[] p = version.split("\\."); 307 return p[0]+"."+p[1]; 308 } else if (Utilities.existsInList(version.toUpperCase(), "R2", "R2B", "R3", "R4", "R4B", "R5", "R6")) { 309 switch (version.toUpperCase()) { 310 case "R2": return "1.0"; 311 case "R2B": return "1.4"; 312 case "R3": return "3.0"; 313 case "R4": return "4.0"; 314 case "R4B": return "4.3"; 315 case "R5": return "5.0"; 316 case "R6": return "6.0"; 317 } 318 } 319 return null; 320 } 321 322 public static String getPatch(String version) { 323 if (version == null) 324 return null; 325 if (Utilities.charCount(version, '.') == 2) { 326 String[] p = version.split("\\."); 327 return p[2]; 328 } 329 return null; 330 } 331 332 public static boolean isSemVer(String version) { 333 if (Utilities.noString(version)) { 334 return false; 335 } 336 return version.matches("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-\\+]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-\\+][0-9a-zA-Z-\\+]*))*))?)?$"); 337 } 338 339 /** 340 * return true if the current version equals test, or later, 341 * so if a feature is defined in 4.0, if (VersionUtilities.isThisOrLater("4.0", version)) 342 * <p> 343 * This method tries to perform a numeric parse, so that <code>0.9</code> will be considered below <code>0.10</code> 344 * in accordance with SemVer. If either side contains a non-numeric character in a version string, a simple text 345 * compare will be done instead. 346 * </p> 347 * 348 * @param test The value to compare to 349 * @param current The value being compared 350 * @return Is {@literal current} later or equal to {@literal test}? For example, if <code>this = 0.5</code> and <code>current = 0.6</code> this method will return true 351 */ 352 public static boolean isThisOrLater(String test, String current) { 353 if (test == null || current == null) { 354 return false; 355 } 356 String t = getMajMin(test); 357 String c = getMajMin(current); 358 if (t == null || c == null) { 359 return false; 360 } 361 if (c.compareTo(t) == 0) { 362 return isMajMinOrLaterPatch(test, current); 363 } 364 365 String[] testParts = t.split("\\."); 366 String[] currentParts = c.split("\\."); 367 368 for (int i = 0; i < Math.max(testParts.length, currentParts.length); i++) { 369 if (i == testParts.length) { 370 return true; 371 } else if (i == currentParts.length) { 372 return false; 373 } 374 String testPart = testParts[i]; 375 String currentPart = currentParts[i]; 376 if (testPart.equals(currentPart)) { 377 continue; 378 } 379 return compareVersionPart(testPart, currentPart); 380 } 381 382 return true; 383 } 384 385 private static boolean compareVersionPart(String theTestPart, String theCurrentPart) { 386 if (StringUtils.isNumeric(theTestPart) && StringUtils.isNumeric(theCurrentPart)) { 387 return Integer.parseInt(theCurrentPart) - Integer.parseInt(theTestPart) >= 0; 388 } else { 389 return theCurrentPart.compareTo(theTestPart) >= 0; 390 } 391 } 392 393 /** 394 * return true if the current version equals test for major and min, or later patch 395 * 396 * @param test 397 * @param current 398 * @return 399 */ 400 public static boolean isMajMinOrLaterPatch(String test, String current) { 401 String t = getMajMin(test); 402 String c = getMajMin(current); 403 if (c != null && t != null && c.compareTo(t) == 0) { 404 String pt = getPatch(test); 405 String pc = getPatch(current); 406 if (pt==null || "x".equals(pt)) { 407 return true; 408 } 409 if (pc!=null) { 410 if (pt.contains("-") && !pc.contains("-")) { 411 pt = pt.substring(0, pt.indexOf("-")); 412 int res = pc.compareTo(pt); 413 return res >= 0; 414 } else { 415 return compareVersionPart(pt, pc); 416 } 417 } 418 } 419 return false; 420 } 421 422 public static String incMajorVersion(String v) { 423 assert isSemVer(v); 424 int[] parts = splitParts(v); 425 return Integer.toString(parts[0]+1)+".0.0"; 426 } 427 428 public static String incMinorVersion(String v) { 429 assert isSemVer(v); 430 int[] parts = splitParts(v); 431 return Integer.toString(parts[0])+"."+Integer.toString(parts[1]+1)+".0"; 432 } 433 434 public static String incPatchVersion(String v) { 435 assert isSemVer(v); 436 int[] parts = splitParts(v); 437 return Integer.toString(parts[0])+"."+Integer.toString(parts[1])+"."+Integer.toString(parts[2]+1); 438 } 439 440 private static int[] splitParts(String v) { 441 String[] p = v.split("\\."); 442 int[] i = new int[] {Integer.parseInt(p[0]),Integer.parseInt(p[1]),Integer.parseInt(p[2])}; 443 return i; 444 } 445 446 public static String versionFromCode(String version) { 447 if ("r2".equals(version)) { 448 return "1.0.2"; 449 } 450 if ("r2b".equals(version)) { 451 return "1.4.0"; 452 } 453 if ("r3".equals(version)) { 454 return "3.0.2"; 455 } 456 if ("r4".equals(version)) { 457 return "4.0.1"; 458 } 459 if ("r4".equals(version)) { 460 return "4.0.1"; 461 } 462 if ("r4b".equals(version)) { 463 return "4.3.0"; 464 } 465 if ("r5".equals(version)) { 466 return "5.0.0"; 467 } 468 if ("r6".equals(version)) { 469 return "6.0.0-cibuild"; 470 } 471 throw new FHIRException("Unknown version "+version); 472 } 473 474 public static VersionURLInfo parseVersionUrl(String url) { 475 if (url.length() < 24) { 476 return null; 477 } 478 String v = url.substring(20, 24); 479 if (v.endsWith("/")) { 480 v = v.substring(0, v.length()-1); 481 if (Utilities.existsInList(v, "1.0", "1.4", "3.0", "4.0", "5.0", "6.0")) { 482 return new VersionURLInfo(v, "http://hl7.org/fhir/"+url.substring(24)); 483 } 484 } 485 return null; 486 } 487 488 489 /** same as getCanonicalResourceNames but add R5 supported types that are canonical too */ 490 public static Set<String> getExtendedCanonicalResourceNames(String version) { 491 Set<String> res = getCanonicalResourceNames(version); 492 if (isR4Ver(version)) { 493 res.add("ActorDefinition"); 494 res.add("Requirements"); 495 res.add("SubscriptionTopic"); 496 res.add("TestPlan"); 497 } 498 return res; 499 } 500 public static Set<String> getCanonicalResourceNames(String version) { 501 502 Set<String> res = new HashSet<String>(); 503 if (isR2Ver(version) || isR2BVer(version)) { 504 res.add("ValueSet"); 505 res.add("ConceptMap"); 506 res.add("NamingSystem"); 507 res.add("StructureDefinition"); 508 res.add("DataElement"); 509 res.add("Conformance"); 510 res.add("OperationDefinition"); 511 res.add("SearchParameter"); 512 res.add("ImplementationGuide"); 513 res.add("TestScript"); 514 } 515 if (isR3Ver(version)) { 516 res.add("CodeSystem"); 517 res.add("CapabilityStatement"); 518 res.add("StructureDefinition"); 519 res.add("ImplementationGuide"); 520 res.add("SearchParameter"); 521 res.add("MessageDefinition"); 522 res.add("OperationDefinition"); 523 res.add("CompartmentDefinition"); 524 res.add("StructureMap"); 525 res.add("GraphDefinition"); 526 res.add("DataElement"); 527 res.add("CodeSystem"); 528 res.add("ValueSet"); 529 res.add("ConceptMap"); 530 res.add("ExpansionProfile"); 531 res.add("Questionnaire"); 532 res.add("ActivityDefinition"); 533 res.add("ServiceDefinition"); 534 res.add("PlanDefinition"); 535 res.add("Measure"); 536 res.add("TestScript"); 537 538 } 539 if (isR4Ver(version)) { 540 res.add("CodeSystem"); 541 res.add("ActivityDefinition"); 542 res.add("CapabilityStatement"); 543 res.add("ChargeItemDefinition"); 544 res.add("CodeSystem"); 545 res.add("CompartmentDefinition"); 546 res.add("ConceptMap"); 547 res.add("EffectEvidenceSynthesis"); 548 res.add("EventDefinition"); 549 res.add("Evidence"); 550 res.add("EvidenceVariable"); 551 res.add("ExampleScenario"); 552 res.add("GraphDefinition"); 553 res.add("ImplementationGuide"); 554 res.add("Library"); 555 res.add("Measure"); 556 res.add("MessageDefinition"); 557 res.add("NamingSystem"); 558 res.add("OperationDefinition"); 559 res.add("PlanDefinition"); 560 res.add("Questionnaire"); 561 res.add("ResearchDefinition"); 562 res.add("ResearchElementDefinition"); 563 res.add("RiskEvidenceSynthesis"); 564 res.add("SearchParameter"); 565 res.add("StructureDefinition"); 566 res.add("StructureMap"); 567 res.add("TerminologyCapabilities"); 568 res.add("TestScript"); 569 res.add("ValueSet"); 570 } 571 if (isR4BVer(version)) { 572 res.add("ActivityDefinition"); 573 res.add("CapabilityStatement"); 574 res.add("ChargeItemDefinition"); 575 res.add("Citation"); 576 res.add("CodeSystem"); 577 res.add("CompartmentDefinition"); 578 res.add("ConceptMap"); 579 res.add("EventDefinition"); 580 res.add("Evidence"); 581 res.add("EvidenceReport"); 582 res.add("EvidenceVariable"); 583 res.add("ExampleScenario"); 584 res.add("GraphDefinition"); 585 res.add("ImplementationGuide"); 586 res.add("Library"); 587 res.add("Measure"); 588 res.add("MessageDefinition"); 589 res.add("NamingSystem"); 590 res.add("OperationDefinition"); 591 res.add("PlanDefinition"); 592 res.add("Questionnaire"); 593 res.add("ResearchDefinition"); 594 res.add("ResearchElementDefinition"); 595 res.add("SearchParameter"); 596 res.add("SpecimenDefinition"); 597 res.add("StructureDefinition"); 598 res.add("StructureMap"); 599 res.add("SubscriptionTopic"); 600 res.add("TerminologyCapabilities"); 601 res.add("TestScript"); 602 res.add("ValueSet"); 603 } 604 605 if (isR5Ver(version) || isR6Ver(version)) { 606 res.add("ActorDefinition"); 607 res.add("ActivityDefinition"); 608 res.add("CapabilityStatement"); 609 res.add("ChargeItemDefinition"); 610 res.add("Citation"); 611 res.add("ClinicalUseDefinition"); 612 res.add("CodeSystem"); 613 res.add("CompartmentDefinition"); 614 res.add("ConceptMap"); 615 res.add("ConditionDefinition"); 616 res.add("EventDefinition"); 617 res.add("Evidence"); 618 res.add("EvidenceReport"); 619 res.add("EvidenceVariable"); 620 res.add("ExampleScenario"); 621 res.add("GraphDefinition"); 622 res.add("ImplementationGuide"); 623 res.add("Library"); 624 res.add("Measure"); 625 res.add("MessageDefinition"); 626 res.add("NamingSystem"); 627 res.add("ObservationDefinition"); 628 res.add("OperationDefinition"); 629 res.add("PlanDefinition"); 630 res.add("Questionnaire"); 631 res.add("Requirements"); 632 res.add("SearchParameter"); 633 res.add("SpecimenDefinition"); 634 res.add("StructureDefinition"); 635 res.add("StructureMap"); 636 res.add("SubscriptionTopic"); 637 res.add("TerminologyCapabilities"); 638 res.add("TestPlan"); 639 res.add("TestScript"); 640 res.add("ValueSet"); 641 } 642 return res; 643 } 644 645 public static String getVersionForPackage(String pid) { 646 if (pid.startsWith("hl7.fhir.r")) { 647 String[] p = pid.split("\\."); 648 return versionFromCode(p[2]); 649 } 650 return null; 651 } 652 653 public static boolean versionsMatch(String v1, String v2) { 654 String mm1 = getMajMin(v1); 655 String mm2 = getMajMin(v2); 656 return mm1 != null && mm2 != null && mm1.equals(mm2); 657 } 658 659 public static boolean versionsMatch(String v1, List<String> v2l) { 660 for (String v2 : v2l) { 661 if (versionsMatch(v1, v2)) { 662 return true; 663 } 664 } 665 return false; 666 } 667 668 public static boolean isR5VerOrLater(String version) { 669 if (version == null) { 670 return false; 671 } 672 String v = getMajMin(version); 673 return v.compareTo("4.5") >= 0; 674 } 675 676 public static String removeVersionFromCanonical(String url) { 677 if (url == null) { 678 return null; 679 } 680 if (url.contains("|")) { 681 return url.substring(0, url.indexOf("|")); 682 } else { 683 return url; 684 } 685 } 686 687 public static boolean isR4Plus(String version) { 688 return version != null && (version.startsWith("4.") || version.startsWith("5.") || "current".equals(version)); 689 } 690 691 public static boolean refersTo(String refVer, String v) { 692 if (v.length() > refVer.length()) { 693 v = v.substring(0, refVer.length()); 694 } 695 return refVer.equals(v); 696 } 697 698 public static String getSpecUrl(String v) { 699 if (v.contains("-cibuild")) { 700 return "http://build.fhir.org"; 701 } 702 if (v.contains("-")) { 703 return "http://hl7.org/fhir/"+v; 704 } 705 706 switch (getMajMin(v)) { 707 case "0.0" : return "http://hl7.org/fhir/DSTU1"; 708 case "1.0" : return "http://hl7.org/fhir/DSTU2"; 709 case "1.4" : return "http://hl7.org/fhir/2016May"; 710 case "3.0" : return "http://hl7.org/fhir/STU3"; 711 case "4.0" : return "http://hl7.org/fhir/R4"; 712 case "4.3" : return "http://hl7.org/fhir/R4B"; 713 case "5.0" : return "http://hl7.org/fhir/R5"; 714 case "6.0" : return "http://hl7.org/fhir/R6"; 715 default: 716 return "http://hl7.org/fhir"; 717 } 718 } 719 720 public static String getNameForVersion(String v) { 721 String mm = getMajMin(v); 722 if (mm == null) { 723 throw new Error("Unable to determine version for '"+v+"'"); 724 } 725 switch (mm) { 726 case "1.0" : return "R2"; 727 case "1.4" : return "R2B"; 728 case "3.0" : return "R3"; 729 case "4.0" : return "R4"; 730 case "4.3" : return "R4B"; 731 case "5.0" : return "R5"; 732 case "6.0" : return "R6"; 733 default: 734 return "R?"; 735 } 736 } 737 738 public static boolean isR5Plus(String version) { 739 return version != null && (version.startsWith("5.") || version.startsWith("6.") || "current".equals(version)); 740 } 741 742 public static boolean isR6Plus(String version) { 743 return version != null && version.startsWith("6."); 744 } 745 746 public static int compareVersions(String ver1, String ver2) { 747 if (ver1 == null) { 748 return ver2 == null ? 0 : 1; 749 } else if (isSemVer(ver1) && isSemVer(ver2)) { 750 SemVer sv1 = new SemVer(ver1); 751 SemVer sv2 = new SemVer(ver2); 752 return sv1.compareTo(sv2); 753 } else { 754 return ver1.compareTo(ver2); 755 } 756 } 757 758 public static boolean includedInRange(String startVer, String stopVer, String ver) { 759 if (ver.equals(startVer)) { 760 return true; 761 } 762 if (ver.equals(stopVer)) { 763 return true; 764 } 765 return startVer.compareTo(ver) < 0 && stopVer.compareTo(ver) > 0; 766 } 767 768 public static String getNoPatch(String version) { 769 return version.contains("-") ? version.substring(0, version.indexOf("-")) : version; 770 } 771 772 773}