10
10
11
11
import com .norcod .rnovpn .BuildConfig ;
12
12
13
- import junit .framework .Assert ;
14
-
15
13
import java .math .BigInteger ;
16
14
import java .net .Inet6Address ;
17
15
import java .util .Collection ;
22
20
23
21
public class NetworkSpace {
24
22
23
+ static void assertTrue (boolean f )
24
+ {
25
+ if (!f )
26
+ throw new IllegalStateException ();
27
+ }
28
+
25
29
static class ipAddress implements Comparable <ipAddress > {
26
30
private BigInteger netAddress ;
27
31
public int networkMask ;
@@ -141,22 +145,22 @@ public ipAddress[] split() {
141
145
ipAddress firstHalf = new ipAddress (getFirstAddress (), networkMask + 1 , included , isV4 );
142
146
ipAddress secondHalf = new ipAddress (firstHalf .getLastAddress ().add (BigInteger .ONE ), networkMask + 1 , included , isV4 );
143
147
if (BuildConfig .DEBUG )
144
- Assert . assertTrue (secondHalf .getLastAddress ().equals (getLastAddress ()));
148
+ assertTrue (secondHalf .getLastAddress ().equals (getLastAddress ()));
145
149
return new ipAddress []{firstHalf , secondHalf };
146
150
}
147
151
148
152
String getIPv4Address () {
149
153
if (BuildConfig .DEBUG ) {
150
- Assert . assertTrue (isV4 );
151
- Assert . assertTrue (netAddress .longValue () <= 0xffffffffl );
152
- Assert . assertTrue (netAddress .longValue () >= 0 );
154
+ assertTrue (isV4 );
155
+ assertTrue (netAddress .longValue () <= 0xffffffffl );
156
+ assertTrue (netAddress .longValue () >= 0 );
153
157
}
154
158
long ip = netAddress .longValue ();
155
159
return String .format (Locale .US , "%d.%d.%d.%d" , (ip >> 24 ) % 256 , (ip >> 16 ) % 256 , (ip >> 8 ) % 256 , ip % 256 );
156
160
}
157
161
158
162
String getIPv6Address () {
159
- if (BuildConfig .DEBUG ) Assert . assertTrue (!isV4 );
163
+ if (BuildConfig .DEBUG ) assertTrue (!isV4 );
160
164
BigInteger r = netAddress ;
161
165
162
166
String ipv6str = null ;
@@ -247,7 +251,7 @@ TreeSet<ipAddress> generateIPList() {
247
251
// Check if it and the next of it are compatible
248
252
ipAddress nextNet = networks .poll ();
249
253
250
- if (BuildConfig .DEBUG ) Assert . assertNotNull (currentNet );
254
+ if (BuildConfig .DEBUG ) assertTrue (currentNet != null );
251
255
if (nextNet == null || currentNet .getLastAddress ().compareTo (nextNet .getFirstAddress ()) == -1 ) {
252
256
// Everything good, no overlapping nothing to do
253
257
ipsDone .add (currentNet );
@@ -273,7 +277,7 @@ TreeSet<ipAddress> generateIPList() {
273
277
274
278
if (newNets [0 ].getLastAddress ().equals (currentNet .getLastAddress ())) {
275
279
if (BuildConfig .DEBUG )
276
- Assert . assertEquals (newNets [0 ].networkMask , currentNet .networkMask );
280
+ assertTrue (newNets [0 ].networkMask == currentNet .networkMask );
277
281
// Don't add the lower half that would conflict with currentNet
278
282
} else {
279
283
if (!networks .contains (newNets [0 ]))
@@ -283,9 +287,9 @@ TreeSet<ipAddress> generateIPList() {
283
287
}
284
288
} else {
285
289
if (BuildConfig .DEBUG ) {
286
- Assert . assertTrue (currentNet .networkMask < nextNet .networkMask );
287
- Assert . assertTrue (nextNet .getFirstAddress ().compareTo (currentNet .getFirstAddress ()) == 1 );
288
- Assert . assertTrue (currentNet .getLastAddress ().compareTo (nextNet .getLastAddress ()) != -1 );
290
+ assertTrue (currentNet .networkMask < nextNet .networkMask );
291
+ assertTrue (nextNet .getFirstAddress ().compareTo (currentNet .getFirstAddress ()) == 1 );
292
+ assertTrue (currentNet .getLastAddress ().compareTo (nextNet .getLastAddress ()) != -1 );
289
293
}
290
294
// This network is bigger than the next and last ip of current >= next
291
295
@@ -300,8 +304,8 @@ TreeSet<ipAddress> generateIPList() {
300
304
301
305
if (newNets [1 ].networkMask == nextNet .networkMask ) {
302
306
if (BuildConfig .DEBUG ) {
303
- Assert . assertTrue (newNets [1 ].getFirstAddress ().equals (nextNet .getFirstAddress ()));
304
- Assert . assertTrue (newNets [1 ].getLastAddress ().equals (currentNet .getLastAddress ()));
307
+ assertTrue (newNets [1 ].getFirstAddress ().equals (nextNet .getFirstAddress ()));
308
+ assertTrue (newNets [1 ].getLastAddress ().equals (currentNet .getLastAddress ()));
305
309
// split second equal the next network, do not add it
306
310
}
307
311
networks .add (nextNet );
0 commit comments