|
| 1 | +package org.fugerit.java.doc.base.config; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | + |
| 5 | +public final class DocVersion implements Serializable, Comparable<DocVersion> { |
| 6 | + |
| 7 | + /** |
| 8 | + * |
| 9 | + */ |
| 10 | + private static final long serialVersionUID = -8717045616792106442L; |
| 11 | + |
| 12 | + public static final DocVersion VERSION_1_0 = DocVersion.newVersion( "1-0" ); |
| 13 | + public static final DocVersion VERSION_1_1 = DocVersion.newVersion( "1-1" ); |
| 14 | + public static final DocVersion VERSION_1_2 = DocVersion.newVersion( "1-2" ); |
| 15 | + public static final DocVersion VERSION_1_3 = DocVersion.newVersion( "1-3" ); |
| 16 | + public static final DocVersion VERSION_1_4 = DocVersion.newVersion( "1-4" ); |
| 17 | + public static final DocVersion VERSION_1_5 = DocVersion.newVersion( "1-5" ); |
| 18 | + public static final DocVersion VERSION_1_6 = DocVersion.newVersion( "1-6" ); |
| 19 | + public static final DocVersion VERSION_1_7 = DocVersion.newVersion( "1-7" ); |
| 20 | + public static final DocVersion VERSION_1_8 = DocVersion.newVersion( "1-8" ); |
| 21 | + public static final DocVersion VERSION_1_9 = DocVersion.newVersion( "1-9" ); |
| 22 | + public static final DocVersion VERSION_1_10 = DocVersion.newVersion( "1-10" ); |
| 23 | + |
| 24 | + public static final DocVersion CURRENT_VERSION = VERSION_1_10; |
| 25 | + |
| 26 | + public static final String VERSION_SEPARATOR ="-"; |
| 27 | + |
| 28 | + private int major; |
| 29 | + |
| 30 | + private int minor; |
| 31 | + |
| 32 | + private DocVersion( String version ) { |
| 33 | + String[] split = version.split( VERSION_SEPARATOR ); |
| 34 | + this.major = Integer.parseInt( split[0] ); |
| 35 | + this.minor = Integer.parseInt( split[1] ); |
| 36 | + } |
| 37 | + |
| 38 | + public int getMajor() { |
| 39 | + return major; |
| 40 | + } |
| 41 | + |
| 42 | + public int getMinor() { |
| 43 | + return minor; |
| 44 | + } |
| 45 | + |
| 46 | + public String stringVersion() { |
| 47 | + return this.getMajor()+VERSION_SEPARATOR+this.getMinor(); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public String toString() { |
| 52 | + return this.stringVersion(); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public int compareTo(DocVersion o) { |
| 57 | + return compare( this , o ); |
| 58 | + } |
| 59 | + |
| 60 | + public static int compare( String v1, String v2 ) { |
| 61 | + return compare( newVersion( v1 ) , newVersion( v2 ) ); |
| 62 | + } |
| 63 | + |
| 64 | + public static int compare( DocVersion v1, DocVersion v2 ) { |
| 65 | + int res = v1.getMajor() - v2.getMajor(); |
| 66 | + if ( res == 0 ) { |
| 67 | + res = v1.getMinor() - v2.getMinor(); |
| 68 | + } |
| 69 | + return res; |
| 70 | + } |
| 71 | + |
| 72 | + public static DocVersion newVersion( String version ) { |
| 73 | + return new DocVersion(version); |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments