18
18
*/
19
19
package org .neo4j .driver .internal .util ;
20
20
21
+ import java .util .Objects ;
21
22
import java .util .regex .Matcher ;
22
23
import java .util .regex .Pattern ;
23
24
28
29
29
30
public class ServerVersion
30
31
{
31
- public static final ServerVersion v3_5_0 = new ServerVersion ( 3 , 5 , 0 );
32
- public static final ServerVersion v3_4_0 = new ServerVersion ( 3 , 4 , 0 );
33
- public static final ServerVersion v3_2_0 = new ServerVersion ( 3 , 2 , 0 );
34
- public static final ServerVersion v3_1_0 = new ServerVersion ( 3 , 1 , 0 );
35
- public static final ServerVersion v3_0_0 = new ServerVersion ( 3 , 0 , 0 );
36
- public static final ServerVersion vInDev = new ServerVersion ( Integer .MAX_VALUE , Integer .MAX_VALUE , Integer .MAX_VALUE );
32
+ public static final ServerVersion v3_5_0 = new ServerVersion ( "Neo4j" , 3 , 5 , 0 );
33
+ public static final ServerVersion v3_4_0 = new ServerVersion ( "Neo4j" , 3 , 4 , 0 );
34
+ public static final ServerVersion v3_2_0 = new ServerVersion ( "Neo4j" , 3 , 2 , 0 );
35
+ public static final ServerVersion v3_1_0 = new ServerVersion ( "Neo4j" , 3 , 1 , 0 );
36
+ public static final ServerVersion v3_0_0 = new ServerVersion ( "Neo4j" , 3 , 0 , 0 );
37
+ public static final ServerVersion vInDev = new ServerVersion ( "Neo4j" , Integer .MAX_VALUE , Integer .MAX_VALUE , Integer .MAX_VALUE );
37
38
38
39
private static final String NEO4J_IN_DEV_VERSION_STRING = "Neo4j/dev" ;
39
40
private static final Pattern PATTERN =
40
- Pattern .compile ( "(Neo4j/)? (\\ d+)\\ .(\\ d+)(?:\\ .)?(\\ d*)(\\ .|-|\\ +)?([0-9A-Za-z-.]*)?" );
41
+ Pattern .compile ( "([^/]*)/ (\\ d+)\\ .(\\ d+)(?:\\ .)?(\\ d*)(\\ .|-|\\ +)?([0-9A-Za-z-.]*)?" );
41
42
43
+ private final String product ;
42
44
private final int major ;
43
45
private final int minor ;
44
46
private final int patch ;
45
47
private final String stringValue ;
46
48
47
- private ServerVersion ( int major , int minor , int patch )
49
+ private ServerVersion ( String product , int major , int minor , int patch )
48
50
{
51
+ this .product = product ;
49
52
this .major = major ;
50
53
this .minor = minor ;
51
54
this .patch = patch ;
52
- this .stringValue = stringValue ( major , minor , patch );
55
+ this .stringValue = stringValue ( product , major , minor , patch );
56
+ }
57
+
58
+ public String product ()
59
+ {
60
+ return product ;
53
61
}
54
62
55
63
public static ServerVersion version ( Driver driver )
@@ -72,6 +80,7 @@ public static ServerVersion version( String server )
72
80
Matcher matcher = PATTERN .matcher ( server );
73
81
if ( matcher .matches () )
74
82
{
83
+ String product = matcher .group ( 1 );
75
84
int major = Integer .valueOf ( matcher .group ( 2 ) );
76
85
int minor = Integer .valueOf ( matcher .group ( 3 ) );
77
86
String patchString = matcher .group ( 4 );
@@ -80,7 +89,7 @@ public static ServerVersion version( String server )
80
89
{
81
90
patch = Integer .valueOf ( patchString );
82
91
}
83
- return new ServerVersion ( major , minor , patch );
92
+ return new ServerVersion ( product , major , minor , patch );
84
93
}
85
94
else if ( server .equalsIgnoreCase ( NEO4J_IN_DEV_VERSION_STRING ) )
86
95
{
@@ -103,6 +112,8 @@ public boolean equals( Object o )
103
112
104
113
ServerVersion that = (ServerVersion ) o ;
105
114
115
+ if ( !product .equals ( that .product ) )
116
+ { return false ; }
106
117
if ( major != that .major )
107
118
{ return false ; }
108
119
if ( minor != that .minor )
@@ -113,10 +124,7 @@ public boolean equals( Object o )
113
124
@ Override
114
125
public int hashCode ()
115
126
{
116
- int result = major ;
117
- result = 31 * result + minor ;
118
- result = 31 * result + patch ;
119
- return result ;
127
+ return Objects .hash (product , major , minor , patch );
120
128
}
121
129
122
130
public boolean greaterThan (ServerVersion other )
@@ -141,6 +149,10 @@ public boolean lessThanOrEqual(ServerVersion other)
141
149
142
150
private int compareTo ( ServerVersion o )
143
151
{
152
+ if ( !product .equals ( o .product ) )
153
+ {
154
+ throw new IllegalArgumentException ("Comparing different products" );
155
+ }
144
156
int c = compare ( major , o .major );
145
157
if (c == 0 )
146
158
{
@@ -160,12 +172,12 @@ public String toString()
160
172
return stringValue ;
161
173
}
162
174
163
- private static String stringValue ( int major , int minor , int patch )
175
+ private static String stringValue ( String product , int major , int minor , int patch )
164
176
{
165
177
if ( major == Integer .MAX_VALUE && minor == Integer .MAX_VALUE && patch == Integer .MAX_VALUE )
166
178
{
167
179
return NEO4J_IN_DEV_VERSION_STRING ;
168
180
}
169
- return String .format ( "Neo4j /%s.%s.%s" , major , minor , patch );
181
+ return String .format ( "%s /%s.%s.%s" , product , major , minor , patch );
170
182
}
171
183
}
0 commit comments