android: Change format of address ranges and print sets
This commit is contained in:
@@ -241,7 +241,7 @@ public class IPRange implements Comparable<IPRange>
|
|||||||
{
|
{
|
||||||
return InetAddress.getByAddress(mFrom).getHostAddress() + "/" + mPrefix;
|
return InetAddress.getByAddress(mFrom).getHostAddress() + "/" + mPrefix;
|
||||||
}
|
}
|
||||||
return InetAddress.getByAddress(mFrom).getHostAddress() + ".." +
|
return InetAddress.getByAddress(mFrom).getHostAddress() + "-" +
|
||||||
InetAddress.getByAddress(mTo).getHostAddress();
|
InetAddress.getByAddress(mTo).getHostAddress();
|
||||||
}
|
}
|
||||||
catch (UnknownHostException ignored)
|
catch (UnknownHostException ignored)
|
||||||
|
|||||||
@@ -205,4 +205,19 @@ public class IPRangeSet implements Iterable<IPRange>
|
|||||||
{
|
{
|
||||||
return mRanges.size();
|
return mRanges.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{ /* we could use TextUtils, but that causes the unit tests to fail */
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (IPRange range : mRanges)
|
||||||
|
{
|
||||||
|
if (sb.length() > 0)
|
||||||
|
{
|
||||||
|
sb.append(" ");
|
||||||
|
}
|
||||||
|
sb.append(range.toString());
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+7
@@ -302,4 +302,11 @@ public class IPRangeSetTest
|
|||||||
assertEquals("next", new IPRange("192.168.1.0/24"), iterator.next());
|
assertEquals("next", new IPRange("192.168.1.0/24"), iterator.next());
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testToString() throws UnknownHostException
|
||||||
|
{
|
||||||
|
IPRangeSet set = IPRangeSet.fromString("192.168.3.10/24 192.168.1.0/24 192.168.1.1-192.168.1.10");
|
||||||
|
assertEquals("string", "192.168.1.0/24 192.168.3.0/24", set.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -200,7 +200,7 @@ public class IPRangeTest
|
|||||||
{
|
{
|
||||||
testToString("192.168.1.1", "192.168.1.1", "192.168.1.1/32");
|
testToString("192.168.1.1", "192.168.1.1", "192.168.1.1/32");
|
||||||
testToString("192.168.1.0", "192.168.1.255", "192.168.1.0/24");
|
testToString("192.168.1.0", "192.168.1.255", "192.168.1.0/24");
|
||||||
testToString("192.168.1.1", "192.168.1.255", "192.168.1.1..192.168.1.255");
|
testToString("192.168.1.1", "192.168.1.255", "192.168.1.1-192.168.1.255");
|
||||||
testToString("0.0.0.0", "255.255.255.255", "0.0.0.0/0");
|
testToString("0.0.0.0", "255.255.255.255", "0.0.0.0/0");
|
||||||
testToString("fec1::1", "fec1::1", "fec1:0:0:0:0:0:0:1/128");
|
testToString("fec1::1", "fec1::1", "fec1:0:0:0:0:0:0:1/128");
|
||||||
testToString("fec1::", "fec1::ffff", "fec1:0:0:0:0:0:0:0/112");
|
testToString("fec1::", "fec1::ffff", "fec1:0:0:0:0:0:0:0/112");
|
||||||
|
|||||||
Reference in New Issue
Block a user