diff options
author | Julien Eluard <[email protected]> | 2011-09-14 18:53:30 -0700 |
---|---|---|
committer | Julien Eluard <[email protected]> | 2011-09-14 18:53:30 -0700 |
commit | 27d5bee878f68624b7317c8ba755ccdafac1ee5f (patch) | |
tree | 2946ea4054a83a3370bea267666b1a01b3535483 /api/src/main | |
parent | 1ce9a15183a3072f408a43225436ba973c74e71c (diff) |
Added support for 2 digits version number.
Diffstat (limited to 'api/src/main')
-rwxr-xr-x | api/src/main/java/org/semver/Version.java | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/api/src/main/java/org/semver/Version.java b/api/src/main/java/org/semver/Version.java index 417d8b3..1a1b501 100755 --- a/api/src/main/java/org/semver/Version.java +++ b/api/src/main/java/org/semver/Version.java @@ -40,8 +40,9 @@ public final class Version implements Comparable<Version> { MAJOR, MINOR, PATCH, SPECIAL; } - private static final String FORMAT = "(\\d)\\.(\\d)\\.(\\d)(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; + private static final String FORMAT = "(\\d)\\.(\\d)(?:\\.)?(\\d)?(?:\\.|-)?([A-Za-z][0-9A-Za-z-]*)?"; private static final Pattern PATTERN = Pattern.compile(Version.FORMAT); + private static final String SNAPSHOT_VERSION_SUFFIX = "-SNAPSHOT"; private final int major; @@ -85,8 +86,13 @@ public final class Version implements Comparable<Version> { final int major = Integer.valueOf(matcher.group(1)); final int minor = Integer.valueOf(matcher.group(2)); - final int patch = Integer.valueOf(matcher.group(3)); - + final int patch; + final String patchMatch = matcher.group(3); + if (patchMatch != null) { + patch = Integer.valueOf(patchMatch); + } else { + patch = 0; + } return new Version(major, minor, patch, matcher.group(4)); } @@ -120,7 +126,7 @@ public final class Version implements Comparable<Version> { } public boolean isSnapshot() { - return this.special.endsWith(Version.SNAPSHOT_VERSION_SUFFIX); + return this.special != null && this.special.endsWith(Version.SNAPSHOT_VERSION_SUFFIX); } @Override |