1010
1111import com .norcod .rnovpn .BuildConfig ;
1212
13- import junit .framework .Assert ;
14-
1513import java .math .BigInteger ;
1614import java .net .Inet6Address ;
1715import java .util .Collection ;
2220
2321public class NetworkSpace {
2422
23+ static void assertTrue (boolean f )
24+ {
25+ if (!f )
26+ throw new IllegalStateException ();
27+ }
28+
2529 static class ipAddress implements Comparable <ipAddress > {
2630 private BigInteger netAddress ;
2731 public int networkMask ;
@@ -141,22 +145,22 @@ public ipAddress[] split() {
141145 ipAddress firstHalf = new ipAddress (getFirstAddress (), networkMask + 1 , included , isV4 );
142146 ipAddress secondHalf = new ipAddress (firstHalf .getLastAddress ().add (BigInteger .ONE ), networkMask + 1 , included , isV4 );
143147 if (BuildConfig .DEBUG )
144- Assert . assertTrue (secondHalf .getLastAddress ().equals (getLastAddress ()));
148+ assertTrue (secondHalf .getLastAddress ().equals (getLastAddress ()));
145149 return new ipAddress []{firstHalf , secondHalf };
146150 }
147151
148152 String getIPv4Address () {
149153 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 );
153157 }
154158 long ip = netAddress .longValue ();
155159 return String .format (Locale .US , "%d.%d.%d.%d" , (ip >> 24 ) % 256 , (ip >> 16 ) % 256 , (ip >> 8 ) % 256 , ip % 256 );
156160 }
157161
158162 String getIPv6Address () {
159- if (BuildConfig .DEBUG ) Assert . assertTrue (!isV4 );
163+ if (BuildConfig .DEBUG ) assertTrue (!isV4 );
160164 BigInteger r = netAddress ;
161165
162166 String ipv6str = null ;
@@ -247,7 +251,7 @@ TreeSet<ipAddress> generateIPList() {
247251 // Check if it and the next of it are compatible
248252 ipAddress nextNet = networks .poll ();
249253
250- if (BuildConfig .DEBUG ) Assert . assertNotNull (currentNet );
254+ if (BuildConfig .DEBUG ) assertTrue (currentNet != null );
251255 if (nextNet == null || currentNet .getLastAddress ().compareTo (nextNet .getFirstAddress ()) == -1 ) {
252256 // Everything good, no overlapping nothing to do
253257 ipsDone .add (currentNet );
@@ -273,7 +277,7 @@ TreeSet<ipAddress> generateIPList() {
273277
274278 if (newNets [0 ].getLastAddress ().equals (currentNet .getLastAddress ())) {
275279 if (BuildConfig .DEBUG )
276- Assert . assertEquals (newNets [0 ].networkMask , currentNet .networkMask );
280+ assertTrue (newNets [0 ].networkMask == currentNet .networkMask );
277281 // Don't add the lower half that would conflict with currentNet
278282 } else {
279283 if (!networks .contains (newNets [0 ]))
@@ -283,9 +287,9 @@ TreeSet<ipAddress> generateIPList() {
283287 }
284288 } else {
285289 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 );
289293 }
290294 // This network is bigger than the next and last ip of current >= next
291295
@@ -300,8 +304,8 @@ TreeSet<ipAddress> generateIPList() {
300304
301305 if (newNets [1 ].networkMask == nextNet .networkMask ) {
302306 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 ()));
305309 // split second equal the next network, do not add it
306310 }
307311 networks .add (nextNet );
0 commit comments