1 /* ownCloud Android client application
2 * Copyright (C) 2012 Bartek Przybylski
3 * Copyright (C) 2012-2013 ownCloud Inc.
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 package com
.owncloud
.android
.utils
;
22 public class OwnCloudVersion
implements Comparable
<OwnCloudVersion
> {
23 public static final OwnCloudVersion owncloud_v1
= new OwnCloudVersion(
25 public static final OwnCloudVersion owncloud_v2
= new OwnCloudVersion(
27 public static final OwnCloudVersion owncloud_v3
= new OwnCloudVersion(
29 public static final OwnCloudVersion owncloud_v4
= new OwnCloudVersion(
31 public static final OwnCloudVersion owncloud_v4_5
= new OwnCloudVersion(
34 // format is in version
36 // for version AA.BB.CC
37 // ie version 2.0.3 will be stored as 0x030003
39 private boolean mIsValid
;
41 public OwnCloudVersion(int version
) {
46 public OwnCloudVersion(String version
) {
49 parseVersionString(version
);
52 public String
toString() {
53 return ((mVersion
>> 16) % 256) + "." + ((mVersion
>> 8) % 256) + "."
57 public boolean isVersionValid() {
62 public int compareTo(OwnCloudVersion another
) {
63 return another
.mVersion
== mVersion ?
0
64 : another
.mVersion
< mVersion ?
1 : -1;
67 private void parseVersionString(String version
) {
69 String
[] nums
= version
.split("\\.");
70 if (nums
.length
> 0) {
71 mVersion
+= Integer
.parseInt(nums
[0]);
73 mVersion
= mVersion
<< 8;
74 if (nums
.length
> 1) {
75 mVersion
+= Integer
.parseInt(nums
[1]);
77 mVersion
= mVersion
<< 8;
78 if (nums
.length
> 2) {
79 mVersion
+= Integer
.parseInt(nums
[2]);
82 } catch (Exception e
) {