android: Change format of address ranges and print sets

This commit is contained in:
Tobias Brunner
2017-07-03 10:27:55 +02:00
parent 291ef58c69
commit 646260f464
4 changed files with 24 additions and 2 deletions
@@ -241,7 +241,7 @@ public class IPRange implements Comparable<IPRange>
{
return InetAddress.getByAddress(mFrom).getHostAddress() + "/" + mPrefix;
}
return InetAddress.getByAddress(mFrom).getHostAddress() + ".." +
return InetAddress.getByAddress(mFrom).getHostAddress() + "-" +
InetAddress.getByAddress(mTo).getHostAddress();
}
catch (UnknownHostException ignored)
@@ -205,4 +205,19 @@ public class IPRangeSet implements Iterable<IPRange>
{
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();
}
}
@@ -302,4 +302,11 @@ public class IPRangeSetTest
assertEquals("next", new IPRange("192.168.1.0/24"), iterator.next());
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());
}
}
@@ -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.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("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");