-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNakshaVersion.java
153 lines (136 loc) · 4.64 KB
/
NakshaVersion.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* Copyright (C) 2017-2024 HERE Europe B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/
package com.here.naksha.lib.core;
import static com.here.naksha.lib.core.NakshaVersion.v2_0_3;
import org.jetbrains.annotations.ApiStatus.AvailableSince;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Just an abstraction for Naksha versioning.
*
*/
@SuppressWarnings("unused")
@AvailableSince(v2_0_3)
public class NakshaVersion implements Comparable<NakshaVersion> {
/**
* Naksha version constant. The last version compatible with XYZ-Hub.
*/
public static final String v0_6 = "0.6.0";
public static final String v2_0_0 = "2.0.0";
public static final String v2_0_3 = "2.0.3";
public static final String v2_0_4 = "2.0.4";
public static final String v2_0_5 = "2.0.5";
public static final String v2_0_6 = "2.0.6";
public static final String v2_0_7 = "2.0.7";
public static final String v2_0_8 = "2.0.8";
public static final String v2_0_9 = "2.0.9";
public static final String v2_0_10 = "2.0.10";
public static final String v2_0_11 = "2.0.11";
public static final String v2_0_12 = "2.0.12";
public static final String v2_0_13 = "2.0.13";
public static final String v2_0_14 = "2.0.14";
public static final String v2_0_15 = "2.0.15";
public static final String v2_0_16 = "2.0.16";
public static final String v2_0_17 = "2.0.17";
public static final String v2_0_18 = "2.0.18";
public static final String v2_0_19 = "2.0.19";
public static final String v2_0_20 = "2.0.20";
public static final String v2_1_0 = "2.1.0";
public static final String v2_1_1 = "2.1.1";
public static final String v2_2_0 = "2.2.0";
public static final String v2_2_1 = "2.2.1";
/**
* The latest version of the naksha-extension stored in the resources.
*/
@AvailableSince(v2_0_5)
public static final NakshaVersion latest = of(v2_2_1);
private final int major;
private final int minor;
private final int revision;
/**
* @param major the major version (0-65535).
* @param minor the minor version (0-65535).
* @param revision the revision (0-65535).
*/
public NakshaVersion(int major, int minor, int revision) {
this.major = major;
this.minor = minor;
this.revision = revision;
}
/**
* Parses the given version string and returns the Naksha version.
*
* @param version the version like "2.0.3".
* @return the Naksha version.
* @throws NumberFormatException if the given string is no valid version.
*/
@AvailableSince(v2_0_3)
public static @NotNull NakshaVersion of(@NotNull String version) throws NumberFormatException {
final int majorEnd = version.indexOf('.');
final int minorEnd = version.indexOf('.', majorEnd + 1);
return new NakshaVersion(
Integer.parseInt(version.substring(0, majorEnd)),
Integer.parseInt(version.substring(majorEnd + 1, minorEnd)),
Integer.parseInt(version.substring(minorEnd + 1)));
}
@AvailableSince(v2_0_3)
public NakshaVersion(long value) {
this((int) ((value >>> 32) & 0xffff), (int) ((value >>> 16) & 0xffff), (int) (value & 0xffff));
}
@AvailableSince(v2_0_3)
public int getMajor() {
return major;
}
@AvailableSince(v2_0_3)
public int getMinor() {
return minor;
}
@AvailableSince(v2_0_3)
public int getRevision() {
return revision;
}
@AvailableSince(v2_0_3)
public long toLong() {
return ((major & 0xffffL) << 32) | ((minor & 0xffffL) << 16) | (revision & 0xffffL);
}
@Override
public int compareTo(@NotNull NakshaVersion o) {
final long result = toLong() - o.toLong();
return result < 0 ? -1 : result == 0 ? 0 : 1;
}
@Override
public int hashCode() {
return (int) (toLong() >>> 16);
}
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (other instanceof NakshaVersion) {
NakshaVersion o = (NakshaVersion) other;
return this.toLong() == o.toLong();
}
return false;
}
@Override
public @NotNull String toString() {
return "" + major + '.' + minor + '.' + revision;
}
}