1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.lutecetools.service.version;
35
36
37
38
39 public class Version implements Comparable
40 {
41 private int _nMajor;
42 private int _nMinor;
43 private int _nPatch;
44 private String _strQualifier;
45
46
47
48
49 public int getMajor( )
50 {
51 return _nMajor;
52 }
53
54
55
56
57
58 public void setMajor( int nMajor )
59 {
60 _nMajor = nMajor;
61 }
62
63
64
65
66 public int getMinor( )
67 {
68 return _nMinor;
69 }
70
71
72
73
74
75 public void setMinor( int nMinor )
76 {
77 _nMinor = nMinor;
78 }
79
80
81
82
83 public int getPatch( )
84 {
85 return _nPatch;
86 }
87
88
89
90
91
92 public void setPatch( int nPatch )
93 {
94 _nPatch = nPatch;
95 }
96
97
98
99
100 public String getQualifier( )
101 {
102 return _strQualifier;
103 }
104
105
106
107
108
109 public void setQualifier( String strQualifier )
110 {
111 _strQualifier = strQualifier;
112 }
113
114 @Override
115 public int compareTo( Object object )
116 {
117 Version/../../../../../../fr/paris/lutece/plugins/lutecetools/service/version/Version.html#Version">Version version = (Version) object;
118 int nDiff = _nMajor - version.getMajor( );
119 if ( nDiff != 0 )
120 {
121 return nDiff;
122 }
123 nDiff = _nMinor - version.getMinor( );
124 if ( nDiff != 0 )
125 {
126 return nDiff;
127 }
128 nDiff = _nPatch - version.getPatch( );
129 return nDiff;
130 }
131
132 public String getVersion( )
133 {
134 StringBuilder sbVersion = new StringBuilder( );
135 sbVersion.append( _nMajor ).append( '.' ).append( _nMinor ).append( '.' ).append( _nPatch );
136 if ( _strQualifier != null )
137 {
138 sbVersion.append( '-' ).append( _strQualifier );
139 }
140 return sbVersion.toString( );
141 }
142
143 public static Version parse( String strSource ) throws VersionParsingException
144 {
145 Versionns/lutecetools/service/version/Version.html#Version">Version version = new Version( );
146
147 try
148 {
149 String strCurrent = strSource.trim( );
150
151
152 int nPos = strCurrent.indexOf( '-' );
153 if ( nPos != -1 )
154 {
155 version.setQualifier( strCurrent.substring( nPos + 1 ) );
156 strCurrent = strCurrent.substring( 0, nPos );
157 }
158
159
160 nPos = strCurrent.indexOf( '.' );
161
162 String strMajor = strCurrent.substring( 0, nPos );
163 version.setMajor( Integer.parseInt( strMajor ) );
164
165
166 strCurrent = strCurrent.substring( nPos + 1 );
167 nPos = strCurrent.indexOf( '.' );
168
169 if ( nPos != -1 )
170 {
171 String strMinor = strCurrent.substring( 0, nPos );
172 version.setMinor( Integer.parseInt( strMinor ) );
173
174 strCurrent = strCurrent.substring( nPos + 1 );
175 version.setPatch( Integer.parseInt( strCurrent ) );
176 }
177 else
178 {
179 version.setMinor( Integer.parseInt( strCurrent ) );
180 }
181 }
182 catch( Exception e )
183 {
184 throw new VersionParsingException( "Error parsing version : '" + strSource + "' : " + e.getMessage( ), e );
185 }
186 return version;
187 }
188
189 }