1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package eu
.alefzero
.owncloud
.utils
;
21 public class OwnCloudVersion
implements Comparable
<OwnCloudVersion
> {
22 public static final OwnCloudVersion owncloud_v1
= new OwnCloudVersion(0x010000);
23 public static final OwnCloudVersion owncloud_v2
= new OwnCloudVersion(0x020000);
24 public static final OwnCloudVersion owncloud_v3
= new OwnCloudVersion(0x030000);
25 public static final OwnCloudVersion owncloud_v4
= new OwnCloudVersion(0x040000);
27 // format is in version
29 // for version AA.BB.CC
30 // ie version 3.0.3 will be stored as 0x030003
32 private boolean mIsValid
;
34 public OwnCloudVersion(int version
) {
39 public OwnCloudVersion(String version
) {
42 parseVersionString(version
);
45 public String
toString() {
46 return ((mVersion
>> 16)%256) + "." +
47 ((mVersion
>> 8)%256) + "." +
51 public boolean isVersionValid() {
56 public int compareTo(OwnCloudVersion another
) {
57 return another
.mVersion
== mVersion ?
0 :
58 another
.mVersion
< mVersion ?
1 : -1;
61 private void parseVersionString(String version
) {
63 String
[] nums
= version
.split("\\.");
64 if (nums
.length
> 0) {
65 mVersion
+= Integer
.parseInt(nums
[0]);
67 mVersion
= mVersion
<< 8;
68 if (nums
.length
> 1) {
69 mVersion
+= Integer
.parseInt(nums
[1]);
71 mVersion
= mVersion
<< 8;
72 if (nums
.length
> 2) {
73 mVersion
+= Integer
.parseInt(nums
[2]);
76 } catch (Exception e
) {