|
| 1 | +package org.jvnet.jaxb.maven; |
| 2 | + |
| 3 | +public class XJCVersion { |
| 4 | + public static final XJCVersion UNDEFINED = new XJCVersion(null); |
| 5 | + private String raw = "UNDEFINED"; |
| 6 | + private int major; |
| 7 | + private int minor; |
| 8 | + private int bugfix; |
| 9 | + |
| 10 | + public XJCVersion(String version) { |
| 11 | + if (version != null) { |
| 12 | + this.raw = version; |
| 13 | + int indexOfSnapshot = version.indexOf("-SNAPSHOT"); |
| 14 | + if (indexOfSnapshot >= 0) { |
| 15 | + version = version.substring(0, indexOfSnapshot); |
| 16 | + } |
| 17 | + String[] split = version.split("\\."); |
| 18 | + if (split.length >= 3) { |
| 19 | + major = Integer.valueOf(split[0]); |
| 20 | + minor = Integer.valueOf(split[1]); |
| 21 | + bugfix = Integer.valueOf(split[2]); |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + |
| 26 | + public String getRaw() { |
| 27 | + return raw; |
| 28 | + } |
| 29 | + |
| 30 | + public int getMajor() { |
| 31 | + return major; |
| 32 | + } |
| 33 | + |
| 34 | + public int getMinor() { |
| 35 | + return minor; |
| 36 | + } |
| 37 | + |
| 38 | + public int getBugfix() { |
| 39 | + return bugfix; |
| 40 | + } |
| 41 | + |
| 42 | + public boolean isKnown() { |
| 43 | + return !(this.major == 0 && this.minor == 0 && this.bugfix == 0); |
| 44 | + } |
| 45 | + |
| 46 | + public boolean gte(int major, int minor, int bugfix) { |
| 47 | + return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix >= bugfix); |
| 48 | + } |
| 49 | + |
| 50 | + public boolean gt(int major, int minor, int bugfix) { |
| 51 | + return this.major > major || (this.major == major && this.minor > minor) || (this.major == major && this.minor == minor && this.bugfix > bugfix); |
| 52 | + } |
| 53 | + |
| 54 | + public boolean lte(int major, int minor, int bugfix) { |
| 55 | + return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix <= bugfix); |
| 56 | + } |
| 57 | + |
| 58 | + public boolean lt(int major, int minor, int bugfix) { |
| 59 | + return this.major < major || (this.major == major && this.minor < minor) || (this.major == major && this.minor == minor && this.bugfix < bugfix); |
| 60 | + } |
| 61 | +} |
0 commit comments