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