Skip to content

Commit

Permalink
Fixed exception comparing versions
Browse files Browse the repository at this point in the history
  • Loading branch information
depryf committed Jul 8, 2024
1 parent 4edcf99 commit 0b30e21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/imsweb/naaccrxml/SpecificationVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package com.imsweb.naaccrxml;

import java.util.Objects;

import org.apache.commons.lang3.StringUtils;

public final class SpecificationVersion {
Expand Down Expand Up @@ -46,6 +48,9 @@ public static boolean isSpecificationSupported(String spec) {
* @return negative integer if first version is smaller, 0 if they are the same, positive integer otherwise
*/
public static int compareSpecifications(String spec1, String spec2) {
if (StringUtils.isBlank(spec1) || !isSpecificationSupported(spec1) || StringUtils.isBlank(spec2) || !isSpecificationSupported(spec2))
return Objects.compare(spec1, spec2, String::compareTo);

String[] parts1 = StringUtils.split(spec1, '.');
Integer major1 = Integer.valueOf(parts1[0]);
Integer minor1 = Integer.valueOf(parts1[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void testCompareVersions() {
Assert.assertEquals(1, SpecificationVersion.compareSpecifications("2.1", "1.0"));
Assert.assertEquals(-1, SpecificationVersion.compareSpecifications("1.2", "2.1"));
Assert.assertEquals(1, SpecificationVersion.compareSpecifications("2.1", "1.2"));

Assert.assertEquals(2, SpecificationVersion.compareSpecifications("1.0", "1"));
Assert.assertEquals(-2, SpecificationVersion.compareSpecifications("1", "1.0"));
Assert.assertEquals(0, SpecificationVersion.compareSpecifications("1", "1"));
}

@Test
Expand Down

0 comments on commit 0b30e21

Please sign in to comment.